/// <summary> /// Offsets the features by -0.001 ft /// </summary> /// <param name="name">The name.</param> /// <exception cref="System.ArgumentNullException">layer name</exception> public static void OffsetFeatures(string name) { try { MessengerManager.MessengerManager.AddLog("Start Offset Features"); if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("Layer Name"); } var pidsToDelete = new Acaddb.ObjectIdCollection(); var pids = GetAllPolylines(); //var refcentroid = GetCentroidOfOuterBoundary(GetPolylinePoints(OGR.ObjectId)); var offset = -0.0001; //inital start value foreach (Acaddb.ObjectId oid in pids) { offset = -0.001; Acaddb.Polyline polyline = GetPolyline((oid)); if (polyline == null) { throw new ArgumentNullException("Polyline is Null"); } if (polyline.Layer != name.ToUpper()) { continue; } MessengerManager.MessengerManager.AddLog("Found Offset Features on Layer " + name); var newpoly = polyline.GetOffsetCurves(offset).Cast <Acaddb.Polyline>(); newpoly.FirstOrDefault().Layer = polyline.Layer; // Get the current document and database var acDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = Application.DocumentManager.MdiActiveDocument .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; // Add each offset object acBlkTblRec.AppendEntity(newpoly.FirstOrDefault()); acTrans.AddNewlyCreatedDBObject(newpoly.FirstOrDefault(), true); acTrans.Commit(); } pidsToDelete.Add(oid); } DeletePolys(pidsToDelete); } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } finally { MessengerManager.MessengerManager.AddLog("End Offset Features"); } }
public static void OffsetGreen() { try { var pids = GetAllPolylines(); //var OGR = GetGreen(pids); //if (OGR == null) // return; //var refcentroid = GetCentroidOfOuterBoundary(GetPolylinePoints(OGR.ObjectId)); //var collars = GetCollar(pids); // AdjustCollars(collars); // var roughouts = GetRoughOutline(pids); // AdjustRoughLayouts(roughouts); var offset = -0.0001; var posOffset = 0.0001; foreach (Acaddb.ObjectId oid in pids) { offset = -0.0001; Acaddb.Polyline polyline = GetPolyline((oid)); if (polyline == null) { return; } if (polyline.Layer == "OGR") { continue; } if (polyline.Layer == "OCO") { offset = posOffset; } else if (polyline.Layer == "OIR") { offset = posOffset; } var newpoly = polyline.GetOffsetCurves(offset).Cast <Acaddb.Polyline>(); newpoly.FirstOrDefault().Layer = polyline.Layer; // Get the current document and database var acDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = Application.DocumentManager.MdiActiveDocument .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; // Add each offset object acBlkTblRec.AppendEntity(newpoly.FirstOrDefault()); acTrans.AddNewlyCreatedDBObject(newpoly.FirstOrDefault(), true); acTrans.Commit(); } } DeletePolys(pids); } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } }