- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on an addin for AutoCAD that needs to place a Section and from that create a block with the intersected geometry.
The code I am using is based on the sample code from Autodesk. But while it appears that the section is created correctly it does not show up in the drawing.
The code I use to create a section is
internal Section CreateSection(string name, Point3dCollection pts, Vector3d verticalDir, Vector3d viewingDir) { if (string.IsNullOrEmpty(name)) return null; if (null == pts || pts.Count <= 1) return null; if (null == verticalDir || null == viewingDir) return null; Section res = null; using (Transaction trans = Db.TransactionManager.StartTransaction()) { try { ObjectId blockId = CreateBlock(name, trans); res = new Section(pts, verticalDir, viewingDir); res.Name = name; BlockTable bt = trans.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable; if (trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) is BlockTableRecord mspace) { ObjectId id = mspace.AppendEntity(res); trans.AddNewlyCreatedDBObject(res, true); if (trans.GetObject(res.Settings, OpenMode.ForWrite) is SectionSettings settings) SetDefaultSectionSettings(settings, blockId); } trans.Commit(); } catch (Exception ex) { string mssg = ex.Message; } } return res; }
Neither the output block nor the section itself appears in the drawing, even though inspecting the data after creation seems to show everything is in order with them (the section does not have an AcadBlock property set, but everything is is filled correctly)
I am unlocking the document at the start of the command (or I could not open anything for Write).
Clearly I am missing something obvious, but I cannot think of what, and the documentation does not suggest anything I should do different or additionally.
Solved! Go to Solution.