Message 1 of 3
Create Custom Viewports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi every body.
I'm trying to create some sheets trough a path on a dawing by creating a new Layout for each sheet, and a viewport on it, pointing to a specified point on drawing and have a custom scale. I've been searching so far, and got this:
private void Button_runplanning_Click(object sender, EventArgs e) { using (DocumentLock lck = doc.LockDocument()) { CAD_Additions obj = new CAD_Additions(); double sheetLength = 500; double sheetWidth = 200; //Point2dCollection pc2 = new Point2dCollection(); #region Get centerline object Polyline CL = new Polyline(); try { using (Transaction tr = curdb.TransactionManager.StartTransaction()) { long val1 = Convert.ToInt64(CenterLineDataTable.Rows[0]["handle"]); ObjectId clid = curdb.GetObjectId(false, new Handle(val1), 0); CL = (Polyline)tr.GetObject(clid, OpenMode.ForRead); tr.Commit(); } } catch (System.Exception exp) { RadMessageBox.Show("An error occured. Try again please.\r\n" + exp.Message, "Error", MessageBoxButtons.OK, RadMessageIcon.Error); return; } if (CL == null) { RadMessageBox.Show("An error occured. Try again please.", "Error", MessageBoxButtons.OK, RadMessageIcon.Error); return; } #endregion using (Transaction tr = curdb.TransactionManager.StartTransaction()) { LayoutManager acLayoutmgr = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current; Point3d stPoint = new Point3d(Convert.ToDouble(CenterLineDataTable.Rows[0]["stx"]), Convert.ToDouble(CenterLineDataTable.Rows[0]["stY"]), 0); int sheetCount = 0; while (true) { if (CL.GetDistAtPoint(stPoint) + (sheetCount * sheetLength) + sheetLength / 2 > CL.Length) { break; } Point3d sheetCenter = CL.GetPointAtDist(CL.GetDistAtPoint(stPoint) + (sheetCount * sheetLength) + sheetLength / 2); string layoutName = "Layout_" + (sheetCount + 1).ToString(); ObjectId newLayoutId = acLayoutmgr.CreateLayout(layoutName); Layout lay = (Layout)tr.GetObject(newLayoutId, OpenMode.ForRead); CreateViewport(lay.ObjectId, sheetCenter, sheetLength, sheetWidth); //EditCurrentViewPort(lay.ObjectId, sheetCenter, sheetLength, sheetWidth); sheetCount++; } tr.Commit(); } } }
public ObjectId CreateViewport(ObjectId layoutId, Point3d center, double length, double width) { using (DocumentLock lck = doc.LockDocument()) { ObjectId oid; try { using (Transaction tr = curdb.TransactionManager.StartTransaction()) { Layout LayoutDest = (Layout)tr.GetObject(layoutId, OpenMode.ForRead); //Layout LayoutDest = (Layout)tr.GetObject(curdb.CurrentSpaceId, OpenMode.ForRead); BlockTableRecord btrDest = (BlockTableRecord)tr.GetObject(LayoutDest.BlockTableRecordId, OpenMode.ForWrite); Autodesk.AutoCAD.DatabaseServices.Viewport vpNew = new Autodesk.AutoCAD.DatabaseServices.Viewport(); vpNew.SetDatabaseDefaults(); vpNew.Width = length; vpNew.Height = width; vpNew.CenterPoint = center; vpNew.ViewTarget = center; vpNew.ViewCenter = new Point2d(center.X, center.Y); vpNew.ViewHeight = width; vpNew.Visible = true; vpNew.StandardScale = StandardScaleType.CustomScale; vpNew.CustomScale = 1; oid = btrDest.AppendEntity(vpNew); tr.AddNewlyCreatedDBObject(vpNew, true); vpNew.ViewDirection = Vector3d.ZAxis; vpNew.On = true; tr.Commit(); return oid; } } catch (System.Exception ex) { ed.WriteMessage(ex.Message); } } return layoutId; }
Tthis works without any error, some layouts are created ("Layout_x"), but all of them, have a same viewport pointing to the drawing extents.
Can anyone help me on this?