public List <AcadDB.Region> GetSubRegions() { List <AcadDB.Region> regions = new List <AcadDB.Region>(); AcadGeo.Vector3d tmp_vec = up_vector.CrossProduct(normal_vector); AcadDB.DBObjectCollection objs = new AcadDB.DBObjectCollection(); AcadGeo.Vector3d hf = up_vector * height * 0.5; AcadGeo.Vector3d wf = tmp_vec * (width * 0.5 - thickness); AcadGeo.Vector3d tf = up_vector * thickness; objs.Add(new AcadDB.Line(base_point + hf + wf, base_point + hf - wf)); objs.Add(new AcadDB.Line(base_point + hf - wf, base_point - hf - wf + tf)); objs.Add(new AcadDB.Line(base_point - hf - wf + tf, base_point - hf + wf + tf)); objs.Add(new AcadDB.Line(base_point - hf + wf + tf, base_point + hf + wf)); { AcadDB.DBObjectCollection regs = AcadDB.Region.CreateFromCurves(objs); foreach (var reg in regs) { if (reg is AcadDB.Region) { regions.Add(reg as AcadDB.Region); } } } return(regions); }
public static ACADDB.Region AddRegion(ACADDB.ObjectId acadObjectId) { ACADDB.Region returnvalue = null; // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; ACADDB.Database acCurDb = acDoc.Database; // Start a transaction using (ACADDB.Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read ACADDB.BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, ACADDB.OpenMode.ForRead) as ACADDB.BlockTable; // Open the Block table record Model space for write ACADDB.BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[ACADDB.BlockTableRecord.ModelSpace], ACADDB.OpenMode.ForWrite) as ACADDB.BlockTableRecord; ACADDB.Polyline polyline = acTrans.GetObject(acadObjectId, ACADDB.OpenMode.ForRead) as ACADDB.Polyline; if (polyline != null) { ACADDB.DBObjectCollection acDBObjColl = new ACADDB.DBObjectCollection(); acDBObjColl.Add((ACADDB.DBObject)polyline.AcadObject); // Calculate the regions based on each closed loop ACADDB.DBObjectCollection myRegionColl = new ACADDB.DBObjectCollection(); myRegionColl = ACADDB.Region.CreateFromCurves(acDBObjColl); ACADDB.Region acRegion = myRegionColl[0] as ACADDB.Region; returnvalue = acRegion; // Add the new object to the block table record and the transaction acBlkTblRec.AppendEntity(acRegion); acTrans.AddNewlyCreatedDBObject(acRegion, true); // Dispose } // Save the new object to the database acTrans.Commit(); } return(returnvalue); }