//из основного кода
//импорт шаблона
ImportLayout("c:\\test.dwt","Чертеж_ЗУ_А3_КПТ_В");
//mpcol - коллеция ObjectId нескольких полилиний
for (int i=0;i<mpcol.Count;i++)
{
ObjectId vp = displayatvp("Чертеж_ЗУ_А3_КПТ_В",mpcol[i],i,1.5);
}
//..
//попытка отобразить каждую полилинию в каждом видовом окне
static public ObjectId displayatvp(string listname, ObjectId target, int curindex, double vpheight)
{
Document doc =Platform.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId vpid=ObjectId.Null;
using (DocumentLock acLckDoc = doc.LockDocument())
{
Transaction tr =db.TransactionManager.StartTransaction();
using (tr)
{
Entity ent=tr.GetObject(target,OpenMode.ForRead) as Entity;
Extents3d ext=ent.GeometricExtents;
LayerTable ltb = (LayerTable)tr.GetObject(db.LayerTableId,OpenMode.ForRead);
LayoutManager acLayoutMgr = LayoutManager.Current;
DBDictionary layoutDic = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite, false) as DBDictionary;
Layout layout = tr.GetObject(entry.Value, OpenMode.ForRead) as Layout;
foreach (DBDictionaryEntry entry in layoutDic)
{
if (!layout.ModelType)
{
if (layout.LayoutName==listname)
{
acLayoutMgr.CurrentLayout = layout.LayoutName;
ObjectIdCollection idsVports = layout.GetViewports();//даёт 1
BlockTableRecord btrLayout = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
//вот так я вижу видовые экраны
/* ObjectIdCollection idsVports=new ObjectIdCollection();
foreach (ObjectId id in btrLayout)
{
DBObject obj=tr.GetObject(id,OpenMode.ForRead);
if (obj is Viewport)
{
idsVports.Add(id);
}
}
idsVports.RemoveAt(0);*/
int vpindex=curindex+1; //для избежания первого видового экрана листа
Viewport vp = (Viewport)tr.GetObject(idsVports[vpindex], OpenMode.ForRead);
double mScrRatio = (vp.Width / vp.Height);
Matrix3d matWCS2DCS;
matWCS2DCS = Matrix3d.PlaneToWorld(vp.ViewDirection);
matWCS2DCS = Matrix3d.Displacement(vp.ViewTarget - Point3d.Origin) * matWCS2DCS;
matWCS2DCS = Matrix3d.Rotation(-vp.TwistAngle, vp.ViewDirection, vp.ViewTarget) * matWCS2DCS;
matWCS2DCS = matWCS2DCS.Inverse();
ext.TransformBy(matWCS2DCS);
double mWidth;
mWidth = (ext.MaxPoint.X - ext.MinPoint.X);
double mHeight;
mHeight = (ext.MaxPoint.Y - ext.MinPoint.Y);
Point2d mCentPt = new Point2d(
((ext.MaxPoint.X + ext.MinPoint.X) * 0.5),
((ext.MaxPoint.Y + ext.MinPoint.Y) * 0.5));
vp.UpgradeOpen();
if (mWidth > (mHeight * mScrRatio)) mHeight = mWidth / mScrRatio;
vp.ViewHeight = mHeight * vpheight;
vp.ViewCenter = mCentPt;
vp.Visible = true;
vp.On = true;
doc.Editor.SwitchToModelSpace();
Application.SetSystemVariable("CVPORT", vp.Number);
//doc.Editor.SwitchToPaperSpace();
vpid=vp.ObjectId;
}
}}}
tr.Commit();
return vpid;
}}
//импорт листа
public static void ImportLayout(string sourceFileName,string layoutName)
{
Document destDoc = Application.DocumentManager.MdiActiveDocument;
Database destDb = destDoc.Database;
var destEd = destDoc.Editor;
Database sourceDb = new Database(false, true);
sourceDb.ReadDwgFile(sourceFileName, FileOpenMode.OpenForReadAndAllShare, true, "");
using (DocumentLock acLckDoc = destDoc.LockDocument())
{
using (var destTr = destDb.TransactionManager.StartTransaction())
{
DBDictionary layouts =
destTr.GetObject(destDb.LayoutDictionaryId,
OpenMode.ForRead) as DBDictionary;
HostApplicationServices.WorkingDatabase = destDb;
var destLayoutManager = LayoutManager.Current;
var destLayoutId = destLayoutManager.CreateLayout(layoutName);
var destLayout = (Layout)destTr.GetObject(destLayoutId, OpenMode.ForWrite);
HostApplicationServices.WorkingDatabase = sourceDb;
using (var sourceTr = sourceDb.TransactionManager.StartTransaction())
{
var layoutDictionary = (DBDictionary)sourceTr.GetObject(sourceDb.LayoutDictionaryId, OpenMode.ForRead);
if (!layoutDictionary.Contains(layoutName))
{
destEd.WriteMessage("В шаблоне отсутствует лист "+layoutName+".");
return;
}
var sourceLayoutManager = LayoutManager.Current;
var sourceLayoutId = sourceLayoutManager.GetLayoutId(layoutName);
var sourceLayout = (Layout)sourceTr.GetObject(sourceLayoutId, OpenMode.ForRead);
destLayout.CopyFrom(sourceLayout);
var layoutTableRecord =
(BlockTableRecord)sourceTr.GetObject(sourceLayout.BlockTableRecordId, OpenMode.ForRead);
var objIdCol = new ObjectIdCollection();
foreach (var layoutObjectId in layoutTableRecord)
{
objIdCol.Add(layoutObjectId);
}
var idMap = new IdMapping();
destDb.WblockCloneObjects(objIdCol, destLayout.BlockTableRecordId, idMap, DuplicateRecordCloning.Ignore, false);
sourceTr.Commit();
}
HostApplicationServices.WorkingDatabase = destDb;
destTr.Commit();
}
}
}