Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello friends,
With this code, I create layout. But there is a problem ...
Viewport Size Not at P2 points with P1 ..! How can I fix this?
I want; The formation of a single layout-viewport by point P1 and P2. . P1 and P2 in size.
[CommandMethod("LCT")]
public void LayoutCreate()
{
var (_, db, ed) = GetActiveDocumentComponents();
var p1 = ed.GetPoint("\nP1 noktası: ").Value;
var p2 = ed.GetPoint("\nP2 noktası: ").Value;
ed.Command("_.ZOOM", "_W", p1, p2);
var name = ed.GetString("\nLayout ismi: ").StringResult;
using (var tr = db.TransactionManager.StartTransaction())
{
var lm = LayoutManager.Current;
lm.CreateLayout(name);
lm.CurrentLayout = name;
var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
var layout = (Layout)tr.GetObject((ObjectId)layoutDict[name], OpenMode.ForWrite);
var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
var toErase = new List<ObjectId>();
foreach (ObjectId id in btr)
{
if (tr.GetObject(id, OpenMode.ForRead) is Autodesk.AutoCAD.DatabaseServices.Viewport)
toErase.Add(id);
}
foreach (var id in toErase)
{
var vpOld = (Autodesk.AutoCAD.DatabaseServices.Viewport)tr.GetObject(id, OpenMode.ForWrite);
vpOld.Erase();
}
var vp = new Autodesk.AutoCAD.DatabaseServices.Viewport();
vp.SetDatabaseDefaults();
btr.AppendEntity(vp);
tr.AddNewlyCreatedDBObject(vp, true);
vp.On = true;
vp.ViewCenter = new Point2d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
vp.ViewHeight = Math.Abs(p2.Y - p1.Y);
vp.Width = Math.Abs(p2.X - p1.X);
vp.Height = Math.Abs(p2.Y - p1.Y);
vp.CenterPoint = new Point3d(vp.Width / 2, vp.Height / 2, 0);
tr.Commit();
}
}
Solved! Go to Solution.