public override bool IsApplicable(RXObject overruledSubject) { // Shade current group only RebarPos pos = overruledSubject as RebarPos; if (pos == null) return false; return (!pos.IncludeInBOQ || pos.Detached); }
public override bool IsApplicable(RXObject overruledSubject) { RebarPos pos = overruledSubject as RebarPos; if (pos == null) return false; Database db = pos.Database; if (db == null) return false; return (mIds.ContainsKey(db.FingerprintGuid)); }
public void Test() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor acEd = acDoc.Editor; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { var blkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; var mdlSpc = acTrans.GetObject(blkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; var myWallRule = new MyWallDrawRule(); myWallRule.SetExtensionDictionaryEntryFilter("MyWallType"); Overrule.AddOverrule(RXObject.GetClass(typeof(Line)), myWallRule, false); Overrule.Overruling = true; var line = new Line(Point3d.Origin, Point3d.Origin + Vector3d.XAxis.RotateBy(Math.PI / 6, Vector3d.ZAxis) * 10); mdlSpc.AppendEntity(line); acTrans.AddNewlyCreatedDBObject(line, true); if (!line.ExtensionDictionary.IsValid) { line.CreateExtensionDictionary(); var dict = acTrans.GetObject(line.ExtensionDictionary, OpenMode.ForWrite) as DBDictionary; dict.SetAt("MyWallType", new DataTable()); } acTrans.Commit(); } }
public static ObjectIdCollection TypeCheckApproach5() { ObjectIdCollection ids = new ObjectIdCollection(); Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord; var cl = RXObject.GetClass(typeof(Circle)); foreach (ObjectId id in btr) { if (id.ObjectClass == cl) { ids.Add(id); } } tr.Commit(); } return(ids); }
static General() { try { IsBimUser = bimUsers.Any(u => u.EqualsIgnoreCase(Environment.UserName)) || IsBimUserByUserData(); ClassAttDef = RXObject.GetClass(typeof(AttributeDefinition)); ClassBlRef = RXObject.GetClass(typeof(BlockReference)); ClassDBDic = RXObject.GetClass(typeof(DBDictionary)); ClassDbTextRX = RXObject.GetClass(typeof(DBText)); ClassDimension = RXObject.GetClass(typeof(Dimension)); ClassHatch = RXObject.GetClass(typeof(Hatch)); ClassMLeaderRX = RXObject.GetClass(typeof(MLeader)); ClassMTextRX = RXObject.GetClass(typeof(MText)); ClassPolyline = RXObject.GetClass(typeof(Polyline)); ClassRecord = RXObject.GetClass(typeof(Xrecord)); ClassRegion = RXObject.GetClass(typeof(Region)); ClassVport = RXObject.GetClass(typeof(Viewport)); } catch { // } }
public static List <PosCopy> ReadAll(PosGrouping grouping, bool skipEmpty) { List <ObjectId> items = new List <ObjectId>(); Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead); using (BlockTableRecordEnumerator it = btr.GetEnumerator()) { while (it.MoveNext()) { if (it.Current.ObjectClass == RXObject.GetClass(typeof(RebarPos))) { items.Add(it.Current); } } } } return(ReadAllInSelection(items, skipEmpty, grouping)); }
public override bool IsApplicable(RXObject overruledSubject) { try { if (LineTypesOfDoubleLines == null || LineTypesOfDoubleLines.Count == 0) { return false; } Autodesk.AutoCAD.DatabaseServices.Polyline pln = overruledSubject as Autodesk.AutoCAD.DatabaseServices.Polyline; foreach (var lineType in LineTypesOfDoubleLines) { if (pln.Linetype == lineType.LineTypeName) { return true; } } } catch (System.Exception ex) { AcadApp.AcaEd.WriteMessage("\nERROR: MarkingDarawOverrule.IsApplicable " + ex + "\n"); } return false; }
public static void Attach() { if (ContextMenuForVP == null) { ContextMenuForVP = new ContextMenuExtension(); var miEnt = new MenuItem(Language.GetItem(LangItem, "h51")); miEnt.Click += StartFunction; ContextMenuForVP.MenuItems.Add(miEnt); var rxcEnt = RXObject.GetClass(typeof(Viewport)); Application.AddObjectContextMenuExtension(rxcEnt, ContextMenuForVP); } if (ContextMenuForCurve == null) { ContextMenuForCurve = new ContextMenuExtension(); var miEnt = new MenuItem(Language.GetItem(LangItem, "h51")); miEnt.Click += StartFunction; ContextMenuForCurve.MenuItems.Add(miEnt); var rxcEnt = RXObject.GetClass(typeof(Curve)); Application.AddObjectContextMenuExtension(rxcEnt, ContextMenuForCurve); } }
public static PropertySetDefinition CreateWallPropertySetDefinition() { Database db = GetDatabase(); PropertySetDefinition def = new PropertySetDefinition(); // we want the property set to apply to walls StringCollection appliesTo = new StringCollection(); string wallClassName = RXObject.GetClass(typeof(Wall)).Name; appliesTo.Add(wallClassName); def.SetToStandard(db); def.SubSetDatabaseDefaults(db); def.AlternateName = "SampleWallPropertySet"; def.IsLocked = false; def.IsVisible = true; def.IsWriteable = true; StringCollection properties = new StringCollection(); properties.Add("Width"); properties.Add("Length"); properties.Add("Height"); foreach (string propName in properties) { PropertyDefinition propDef = new PropertyDefinition(); propDef.SetToStandard(db); propDef.SubSetDatabaseDefaults(db); propDef.Automatic = true; propDef.Name = propName; propDef.Description = propName; propDef.IsVisible = true; propDef.IsReadOnly = true; propDef.SetAutomaticData(wallClassName, propName); def.Definitions.Add(propDef); } return(def); }
//public List<Line> InsectLine(ref Transaction tr, ref BlockTableRecord spaceRecord, ref Line line) //{ // //} //Carry all. public void InspectBlockReference(ref BlockTable bt, ref Transaction tr, ref BlockTableRecord spaceRecord, ref BlockReference bref, ref List <BlockReference> blocks, ref List <Line> lines, ref HashSet <String> NothingBlocks) { BlockTableRecord gePostBt = (BlockTableRecord)tr.GetObject(bt[gePost], OpenMode.ForRead); BlockTableRecord geDBLSTUBPost = (BlockTableRecord)tr.GetObject(bt[geDBLSTUD], OpenMode.ForRead); BlockTableRecord geTRISTUDPost = (BlockTableRecord)tr.GetObject(bt[geTRISTUD], OpenMode.ForRead); List <Point2d> boundary = new List <Point2d>(); bool isInverted = false; bool hasBoundary = false; if (bref != null) { if (!bref.ExtensionDictionary.IsNull) { DBDictionary extDict = (DBDictionary)tr.GetObject(bref.ExtensionDictionary, OpenMode.ForRead); if (extDict != null && extDict.Contains(filterDictName)) { DBDictionary fildict = (DBDictionary)tr.GetObject(extDict.GetAt(filterDictName), OpenMode.ForRead); if (fildict != null) { if (fildict.Contains(spatialName)) { var fil = (SpatialFilter)tr.GetObject(fildict.GetAt(spatialName), OpenMode.ForRead); if (fil != null) { Extents3d ext = fil.GetQueryBounds(); isInverted = fil.Inverted; var pts = fil.Definition.GetPoints(); //Matrix3d inverseMatrix = brefMatrix.Inverse(); foreach (var pt in pts) { Point3d point3 = new Point3d(pt.X, pt.Y, 0); point3 = point3.TransformBy(fil.OriginalInverseBlockTransform); boundary.Add(new Point2d(point3.X, point3.Y)); //ed.WriteMessage("\nBoundary point at {0}", pt); } } } if (boundary.Count >= 2) { hasBoundary = true; } } } } BlockTableRecord newBtr = (BlockTableRecord)tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead); foreach (ObjectId id in newBtr) { if (id.ObjectClass.DxfName == "INSERT") { BlockReference newBref1 = (BlockReference)tr.GetObject(id, OpenMode.ForRead); Matrix3d matrix3d = newBref1.BlockTransform; string brefName = newBref1.IsDynamicBlock ? ((BlockTableRecord)newBref1.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)).Name : newBref1.Name; if (brefName.Split('|').Last() == gePost && !NothingBlocks.Contains(brefName)) { BlockReference bref2 = copyDynamicBlock(spaceRecord, ref newBref1, ref gePostBt, tr); if (!hasBoundary || canAdd(isInverted, boundary, bref2.Position)) { blocks.Add(bref2); } else { bref2.Erase(); } } else if (brefName.Split('|').Last() == geDBLSTUD && !NothingBlocks.Contains(brefName)) { BlockReference bref2 = copyDynamicBlock(spaceRecord, ref newBref1, ref geDBLSTUBPost, tr); if (!hasBoundary || canAdd(isInverted, boundary, bref2.Position)) { blocks.Add(bref2); } else { bref2.Erase(); } } else if (brefName.Split('|').Last() == geTRISTUD && !NothingBlocks.Contains(brefName)) { BlockReference bref2 = copyDynamicBlock(spaceRecord, ref newBref1, ref geTRISTUDPost, tr); if (!hasBoundary || canAdd(isInverted, boundary, bref2.Position)) { blocks.Add(bref2); } else { bref2.Erase(); } } else { List <BlockReference> newObjects = new List <BlockReference>(); List <Line> newLines = new List <Line>(); InspectBlockReference(ref bt, ref tr, ref spaceRecord, ref newBref1, ref newObjects, ref newLines, ref NothingBlocks); if (newObjects.Count == 0 && newLines.Count == 0) { NothingBlocks.Add(brefName); } if (hasBoundary) { foreach (BlockReference nbref in newObjects) { if (canAdd(isInverted, boundary, nbref.Position)) { blocks.Add(nbref); } else { nbref.Erase(); } } } else { blocks.AddRange(newObjects); } } } else if (id.ObjectClass == RXObject.GetClass(typeof(Line))) { Line line = (Line)tr.GetObject(id, OpenMode.ForRead); if (line.Layer.Split('|').Last() == swallLayer) { Line newLine = copyLine(spaceRecord, ref line, tr); if (canAdd(isInverted, boundary, newLine.StartPoint) || canAdd(isInverted, boundary, newLine.EndPoint)) { lines.Add(newLine); } } } } for (int i = 0; i < blocks.Count; i++) { blocks[i].TransformBy(bref.BlockTransform); } for (int i = 0; i < lines.Count; i++) { lines[i].TransformBy(bref.BlockTransform); } } }
public static void SelectPolylinesToChange() { ObjectId[] selection = null; #region Database var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; #endregion try { PromptSelectionResult selectionRes = ed.SelectImplied(); // If there's no pickfirst set available... if (selectionRes.Status == PromptStatus.Error) { // ... ask the user to select entities PromptSelectionOptions selectionOpts = new PromptSelectionOptions(); selectionOpts.MessageForAdding = "\nSelect polylines: "; selectionRes = ed.GetSelection(selectionOpts); } else { // If there was a pickfirst set, clear it ed.SetImpliedSelection(new ObjectId[0]); } // If the user has not cancelled... if (selectionRes.Status == PromptStatus.OK) { try { selection = selectionRes.Value.GetObjectIds().Where (id => { return( (id.ObjectClass == RXObject.GetClass(typeof(Polyline))) || (id.ObjectClass == RXObject.GetClass(typeof(Polyline2d))) || (id.ObjectClass == RXObject.GetClass(typeof(Polyline3d)))); }).ToArray(); foreach (var obj in selection) { if (obj.IsErased) { continue; } InteratePolyLinesToChange(obj); } } catch (Exception ex) { MessengerManager.MessengerManager.AddLog(ex.Message); } } } catch { } }
public void RunCode(List <Point3d> pts, Transaction tr, ref Database db, Editor ed, ref List <BlockReference> InBoundaryAddBrefs, ref List <Line> InBoundaryLines, ref HashSet <String> NothingBlocks) { //Setup layer and blockTableRecord createLayer(); copyLocktableRecord(); List <BlockReference> objects = new List <BlockReference>(); List <Line> sWallLines = new List <Line>(); TypedValue[] filterList = new TypedValue[1]; filterList[0] = new TypedValue(0, "INSERT,LINE"); SelectionFilter filter = new SelectionFilter(filterList); HashSet <ObjectId> choosenIds = new HashSet <ObjectId>(); PromptSelectionResult selRes = ed.SelectCrossingWindow(pts[0], pts[2], filter); if (selRes.Status == PromptStatus.OK) { foreach (ObjectId id in selRes.Value.GetObjectIds()) { choosenIds.Add(id); } } PromptSelectionResult selResReversed = ed.SelectCrossingWindow(pts[2], pts[0], filter); if (selResReversed.Status == PromptStatus.OK) { foreach (ObjectId id in selResReversed.Value.GetObjectIds()) { choosenIds.Add(id); } } if (choosenIds.Count == 0) { return; } BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord spaceRecord = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead); BlockTableRecord gePostBt = (BlockTableRecord)tr.GetObject(bt[gePost], OpenMode.ForRead); BlockTableRecord geDBLSTUDPost = (BlockTableRecord)tr.GetObject(bt[geDBLSTUD], OpenMode.ForRead); BlockTableRecord geTRISTUDPost = (BlockTableRecord)tr.GetObject(bt[geTRISTUD], OpenMode.ForRead); foreach (ObjectId objectId in choosenIds) { DBObject dbObject = tr.GetObject(objectId, OpenMode.ForRead); if (objectId.ObjectClass == RXObject.GetClass(typeof(Line))) { Line line = dbObject as Line; if (line.Layer.Split('|').Last() == swallLayer) { sWallLines.Add(copyLine(spaceRecord, ref line, tr)); } } else if (dbObject is BlockReference) { BlockReference bref = dbObject as BlockReference; BlockTableRecord brefRecord = (BlockTableRecord)tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead); string brefName = bref.IsDynamicBlock ? ((BlockTableRecord)bref.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)).Name : bref.Name; if (brefName == gePost) { objects.Add(copyDynamicBlock(spaceRecord, ref bref, ref gePostBt, tr)); } else if (brefName == geDBLSTUD) { objects.Add(copyDynamicBlock(spaceRecord, ref bref, ref geDBLSTUDPost, tr)); } else if (brefName == geTRISTUD) { objects.Add(copyDynamicBlock(spaceRecord, ref bref, ref geTRISTUDPost, tr)); } else { List <BlockReference> rawNewBlocks = new List <BlockReference>(); List <Line> newLines = new List <Line>(); InspectBlockReference(ref bt, ref tr, ref spaceRecord, ref bref, ref rawNewBlocks, ref newLines, ref NothingBlocks); objects.AddRange(rawNewBlocks); sWallLines.AddRange(newLines); } } } List <Point3d> boundary = createRectangleForXclip(pts); foreach (BlockReference bref in objects) { if (canAdd(false, boundary, bref.Position)) { InBoundaryAddBrefs.Add(bref); } else { bref.Erase(); } } foreach (Line line in sWallLines) { if (canAdd(false, boundary, line.StartPoint) || canAdd(false, boundary, line.EndPoint)) { InBoundaryLines.Add(line); } else { line.Erase(); } } return; }
public void RunCode(List <Point3d> pts, Transaction tr, ref Database db, Editor ed, ref List <BlockReference> InBoundaryAddBrefs, ref List <Line> InBoundaryLines, ref List <Polyline> InBoundaryPlines, ref HashSet <String> NothingBlocks) { //Setup layer and blockTableRecord foreach (string layer in acceptableLayer) { createLayer(layer, 1); } copyLocktableRecord(); List <BlockReference> sWallBlocks = new List <BlockReference>(); List <Line> sWallLines = new List <Line>(); List <Polyline> sWallPlines = new List <Polyline>(); HashSet <ObjectId> choosenIds = EditorSelectCrossingWindow(ed, pts); if (choosenIds.Count == 0) { return; } BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord spaceRecord = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead); //GetAllBlockName allBlockTableRecord.Clear(); allBlockTableRecord = getBlockTableRecord(bt, tr); foreach (ObjectId objectId in choosenIds) { DBObject dbObject = tr.GetObject(objectId, OpenMode.ForRead); if (objectId.ObjectClass == RXObject.GetClass(typeof(Line))) { Line line = dbObject as Line; if (acceptableLayer.Contains(line.Layer.Split('|').Last())) { sWallLines.Add(CopyLine(spaceRecord, ref line, tr)); } } else if (dbObject is Polyline) { Polyline pline = dbObject as Polyline; if (acceptableLayer.Contains(pline.Layer.Split('|').Last())) { sWallPlines.Add(CopyPolyline(spaceRecord, ref pline, tr)); } } else if (dbObject is BlockReference) { BlockReference bref = dbObject as BlockReference; BlockTableRecord brefRecord = (BlockTableRecord)tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead); string brefName = bref.IsDynamicBlock ? ((BlockTableRecord)bref.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)).Name : bref.Name; if (allBlockTableRecord.Keys.Contains(brefName) && acceptableLayer.Contains(bref.Layer.Split('|').Last())) { sWallBlocks.Add(CopyDynamicBlock(spaceRecord, ref bref, allBlockTableRecord[brefName], tr)); } else { List <BlockReference> rawNewBlocks = new List <BlockReference>(); List <Line> newLines = new List <Line>(); List <Polyline> newPLines = new List <Polyline>(); InspectBlockReference(ref tr, ref spaceRecord, ref bref, ref rawNewBlocks, ref newLines, ref newPLines, ref NothingBlocks); sWallBlocks.AddRange(rawNewBlocks); sWallLines.AddRange(newLines); sWallPlines.AddRange(newPLines); } } } List <Point3d> boundary = createRectangleForXclip(pts); foreach (BlockReference bref in sWallBlocks) { if (canAdd(false, boundary, bref.Position)) { InBoundaryAddBrefs.Add(bref); } else { dynaProps.Remove(bref.ObjectId); bref.Erase(); } } foreach (Line line in sWallLines) { if (canAdd(false, boundary, line.StartPoint) || canAdd(false, boundary, line.EndPoint)) { InBoundaryLines.Add(line); } else { line.Erase(); } } foreach (Polyline pline in sWallPlines) { if (canAddPolyline(false, boundary, pline)) { InBoundaryPlines.Add(pline); } else { pline.Erase(); } } return; }
//The lines, plines, and blocks MUST BE EMPTY when this function is called. public void InspectBlockReference(ref Transaction tr, ref BlockTableRecord spaceRecord, ref BlockReference bref, ref List <BlockReference> blocks, ref List <Line> lines, ref List <Polyline> plines, ref HashSet <string> NothingBlocks) { List <Point2d> boundary = new List <Point2d>(); bool isInverted = false; bool hasBoundary = false; if (bref != null) { CheckBoundaryAndInverted(ref bref, tr, ref boundary, ref hasBoundary, ref isInverted); BlockTableRecord newBtr = (BlockTableRecord)tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead); foreach (ObjectId id in newBtr) { if (id.ObjectClass.DxfName == "INSERT") { BlockReference newBref1 = (BlockReference)tr.GetObject(id, OpenMode.ForRead); Matrix3d matrix3d = newBref1.BlockTransform; string brefName = newBref1.IsDynamicBlock ? ((BlockTableRecord)newBref1.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)).Name : newBref1.Name; //Remove prefix -- File, Path, etc... brefName = brefName.Split('|').Last(); if (allBlockTableRecord.Keys.Contains(brefName) && !NothingBlocks.Contains(brefName) && acceptableLayer.Contains(newBref1.Layer.Split('|').Last())) { if (canAdd(isInverted, boundary, newBref1.Position)) { BlockReference bref2 = CopyDynamicBlock(spaceRecord, ref newBref1, allBlockTableRecord[brefName], tr); blocks.Add(bref2); } } else { List <BlockReference> newObjects = new List <BlockReference>(); List <Line> newLines = new List <Line>(); List <Polyline> newPlines = new List <Polyline>(); InspectBlockReference(ref tr, ref spaceRecord, ref newBref1, ref newObjects, ref newLines, ref newPlines, ref NothingBlocks); if (newObjects.Count == 0 && newLines.Count == 0 && newPlines.Count == 0) { NothingBlocks.Add(brefName); } foreach (BlockReference nbref in newObjects) { if (canAdd(isInverted, boundary, nbref.Position)) { blocks.Add(nbref); } else { dynaProps.Remove(nbref.ObjectId); nbref.Erase(); } } foreach (Line line in newLines) { if (canAdd(isInverted, boundary, line.StartPoint) || canAdd(isInverted, boundary, line.EndPoint)) { lines.Add(line); } else { line.Erase(); } } foreach (Polyline pline in newPlines) { if (canAddPolyline(isInverted, boundary, pline)) { plines.Add(pline); } else { pline.Erase(); } } } } else if (id.ObjectClass == RXObject.GetClass(typeof(Line))) { Line line = (Line)tr.GetObject(id, OpenMode.ForRead); if (acceptableLayer.Contains(line.Layer.Split('|').Last())) { if (canAdd(isInverted, boundary, line.StartPoint) || canAdd(isInverted, boundary, line.EndPoint)) { Line newLine = CopyLine(spaceRecord, ref line, tr); lines.Add(newLine); } } } else if (id.ObjectClass == RXObject.GetClass(typeof(Polyline))) { Polyline pline = (Polyline)tr.GetObject(id, OpenMode.ForRead); if (acceptableLayer.Contains(pline.Layer.Split('|').Last())) { if (canAddPolyline(isInverted, boundary, pline)) { Polyline newPline = CopyPolyline(spaceRecord, ref pline, tr); plines.Add(newPline); } } } } for (int i = 0; i < blocks.Count; i++) { blocks[i].TransformBy(bref.BlockTransform); } for (int i = 0; i < lines.Count; i++) { lines[i].TransformBy(bref.BlockTransform); } for (int i = 0; i < plines.Count; i++) { plines[i].TransformBy(bref.BlockTransform); } } }
/// <inheritdoc /> public override bool IsApplicable(RXObject overruledSubject) { return(ExtendedDataUtils.IsApplicable(overruledSubject, SectionDescriptor.Instance.Name)); }
//重定义失效 public static void OverruleEnd() { Overrule.RemoveOverrule(RXObject.GetClass(typeof(Line)), LArrowDrawOverrule3.TheOverrule); Overrule.RemoveOverrule(RXObject.GetClass(typeof(Line)), LArrowGripOverrule3.TheOverrule); }
/// <summary> /// Проверка валидности примитива. Проверка происходит по наличию XData с определенным AppName /// </summary> /// <param name="overruledSubject">Instance of <see cref="RXObject"/></param> public override bool IsApplicable(RXObject overruledSubject) { return(ExtendedDataUtils.IsApplicable(overruledSubject, SecantNodalLeader.GetDescriptor().Name)); }
public virtual void CopyFrom(RXObject source) { createInstance(); BaseRXObject.CopyFrom(source); tr.Dispose(); }
/// <inheritdoc /> public void Initialize() { Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), GroundLineGripPointOverrule.Instance(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), GroundLineOsnapOverrule.Instance(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), GroundLineObjectOverrule.Instance(), true); }
public static ObjectIdCollection GetPaperObjects(this ObjectId viewportId) { var objCol = new ObjectIdCollection(); if (viewportId.IsNull) { return(objCol); } if (viewportId.IsErased || viewportId.Database == null) { return(objCol); } using (var acTrans = viewportId.Database.TransactionManager.StartTransaction()) { var vPort = acTrans.GetObject(viewportId, OpenMode.ForRead) as Viewport; if (vPort != null) { if (vPort.Number == 1) { return(objCol); } var unitVector = CalcTol.UnitVector; foreach (var objId in (BlockTableRecord)acTrans.GetObject(vPort.BlockId, OpenMode.ForRead)) { if (objId.IsNull || objId.IsErased || objId == viewportId || objId.ObjectClass == RXObject.GetClass(typeof(Viewport)) || objId.ObjectClass == RXObject.GetClass(typeof(AttributeDefinition)) || objId.ObjectClass == RXObject.GetClass(typeof(AttributeReference)) || objId.ObjectClass == RXObject.GetClass(typeof(ProxyEntity))) { continue; } var entity = acTrans.GetObject(objId, OpenMode.ForRead) as Entity; if (entity == null) { continue; } Extents2d ext2d; try { ext2d = entity.GeometricExtents.Convert2d(); } catch { return(objCol); } if (ext2d != new Extents2d() && (ext2d.IsInside(ext2d, unitVector) || ext2d.Intersects(ext2d, unitVector))) { objCol.Add(objId); } } } else { return(objCol); } acTrans.Commit(); } return(objCol); }
public static void Main() { DocumentCollection mgr_doc = global::Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager; //Access and lock the current document and database Document doc = global::Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; HostApplicationServices.WorkingDatabase = db; AutoCADCommand.Audit(); AutoCADCommand.Purge(); // if the drawing has any AEC or Proxy objects, immediately // send out to AECTOACAD, audit, purge and then start work //doc.SendStringToExecute( // "AECTOACAD", // true, // true, // true); //Setup directories string curloc = Path.GetDirectoryName(db.Filename); //Creates a new directory for all files to be saved to //called "_Setup Files" and "Xrefs" string NewFol = "_Setup Files"; string NewSetups = "SETUP"; string setuploc = System.IO.Path.Combine(curloc, NewFol, NewSetups); string xrefloc = System.IO.Path.Combine(curloc, NewFol); //creates the setup directories if they don't already exist if (!Directory.Exists(xrefloc)) { Directory.CreateDirectory(xrefloc); } if (!Directory.Exists(setuploc)) { Directory.CreateDirectory(setuploc); } //Gather all the xrefs from the document, if there are any List <BlockTableRecord> xlist = Xref_List(doc); //Get a list of layouts/layoutids List <Layout> listoflayouts = Project_ListOfLayouts(doc); List <ObjectId> listoflayids = Project_ListOfLayoutIds(doc); // The objectIDs for the BlockTableRecords of the Model and PaperSpace layouts ObjectId mspace = listoflayids[0]; List <ObjectId> pspaces = listoflayids.GetRange(1, (listoflayids.Count() - 1)); DictOfViewPorts vp_dict = new DictOfViewPorts(); #region External Reference Exportation using (DocumentLock doclock = doc.LockDocument()) { //Start the process of saving out each of the unique //xrefs into another folder called "Xrefs" if (xlist.Count() > 0) { foreach (BlockTableRecord x in xlist) { using (Transaction tr = db.TransactionManager.StartTransaction()) { //if the file already exists somewhere else in the directory //just copy it from there to the base location instead Xref_ExporterCopy(x); } } } #endregion #region Viewport Information //get the info on all viewports in all layouts foreach (Layout layout in listoflayouts) { List <AutoCADViewport> list_vpinfo = Xref_ViewPortInfo(layout.ObjectId); vp_dict.Add(layout, list_vpinfo); } } #endregion #region Actual Setup File Creation #region Misc. Saving //doc is no longer locked //save the consultant drawing into the xref folder with its references try { doc.Database.SaveAs( (Path.Combine(xrefloc, (Path.GetFileName(db.Filename)))), true, DwgVersion.AC1800, db.SecurityParameters); } catch (global::Autodesk.AutoCAD.Runtime.Exception aex) { if (aex.ErrorStatus == ErrorStatus.FileAccessErr) { // error handling code } } catch { // error handling code } #endregion #region Xref Insertion & Layout Creation foreach (Layout l in listoflayouts) { if (!l.ModelType) { //create a new dwg based on the BR+A template //switch the active drawing to the newly made drawing string BRA = "G:\\Shared\\CADD\\ACAD2011\\Template\\BR+A.dwt"; Document newdoc = doc.CreateNew(BRA, setuploc, l.LayoutName); global::Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = newdoc; HostApplicationServices.WorkingDatabase = newdoc.Database; try { global::Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("CLAYER", "x-xref"); newdoc.LayerManagement("Lock", "x-xref", false); } catch { // error handling code } //Insert the consultant drawing at 0,0,0 newdoc.Xref_Attach( (doc.Name), Path.GetFileNameWithoutExtension(doc.Name), "Model"); newdoc.Editor.Regen(); //insert the default titleblock based on the size of the previous document's layout string tblksize; int numoflays = 0; string tblk_dir = Path.GetDirectoryName("G:\\Shared\\CADD\\BLOCKLIB\\BR&A\\NYC\\BR+A-NY.dwg"); string TBLK = Path.Combine(xrefloc, "TBLK.dwg"); using (DocumentLock d_lock = newdoc.LockDocument()) { using (Transaction tr1 = newdoc.Database.TransactionManager.StartTransaction()) { numoflays++; tblksize = l.PaperSize(); // If the layout doesn't already exist in the drawing, create it LayoutManager newlaymgr = LayoutManager.Current; List <Layout> new_listoflayouts = Project_ListOfLayouts(newdoc); Layout curlay = new Layout(); PlotPaperUnit ppunits = PlotPaperUnit.Inches; if (!new_listoflayouts.Any(ln => ln.LayoutName.Equals(l.LayoutName))) { curlay = newdoc.Create_NewLayout(l.LayoutName); } else { curlay = new_listoflayouts[new_listoflayouts.FindIndex(ln => ln.LayoutName.Equals(l.LayoutName))]; } #endregion #region Title Block Switch Statements // case statements pick out specific titleblocks try { switch (tblksize) { case "11,17": //change the actual page size curlay.SetPageSize(11.00, 17.00, ppunits); // save the titleblock from the G Drive into the project folder // as TBLK.dwg and the titleblock info as well as TBLKinfo.dwg if (!File.Exists(TBLK)) { File.Copy((Path.Combine(tblk_dir, "11X17.dwg")), (Path.Combine(xrefloc, "TBLK.dwg")), false); File.Copy((Path.Combine(tblk_dir, "11X17INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo.dwg")), false); //insert the titleblock newdoc.Xref_Attach(TBLK, "TBLK", l.LayoutName); } else { string other_tblk = Path.Combine(xrefloc, "TBLK_11X17.dwg"); File.Copy((Path.Combine(tblk_dir, "11X17.dwg")), (Path.Combine(xrefloc, "TBLK_11X17.dwg")), false); File.Copy((Path.Combine(tblk_dir, "11X17INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo_11X17.dwg")), false); //insert the titleblock newdoc.Xref_Attach(other_tblk, "TBLK_11X17", l.LayoutName); } break; case "24,36": //change the actual page size curlay.SetPageSize(24.00, 36.00, ppunits); // save the titleblock from the G Drive into the project folder // as TBLK.dwg and the titleblock info as well as TBLKinfo.dwg if (!File.Exists(TBLK)) { File.Copy((Path.Combine(tblk_dir, "24X36.dwg")), (Path.Combine(xrefloc, "TBLK.dwg")), false); File.Copy((Path.Combine(tblk_dir, "24X36INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo.dwg")), false); //insert the titleblock newdoc.Xref_Attach(TBLK, "TBLK", l.LayoutName); } else { string other_tblk = Path.Combine(xrefloc, "TBLK_24X36.dwg"); File.Copy((Path.Combine(tblk_dir, "24X36.dwg")), (Path.Combine(xrefloc, "TBLK_24X36.dwg")), false); File.Copy((Path.Combine(tblk_dir, "24X36INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo_24X36.dwg")), false); //insert the titleblock newdoc.Xref_Attach(other_tblk, "TBLK_24X36", l.LayoutName); } break; case "30,42": //change the actual page size curlay.SetPageSize(30.00, 42.00, ppunits); // save the titleblock from the G Drive into the project folder // as TBLK.dwg and the titleblock info as well as TBLKinfo.dwg if (!File.Exists(TBLK)) { File.Copy((Path.Combine(tblk_dir, "30X42.dwg")), (Path.Combine(xrefloc, "TBLK.dwg")), false); File.Copy((Path.Combine(tblk_dir, "30X42INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo.dwg")), false); //insert the titleblock newdoc.Xref_Attach(TBLK, "TBLK", l.LayoutName); } else { string other_tblk = Path.Combine(xrefloc, "TBLK_30X42.dwg"); File.Copy((Path.Combine(tblk_dir, "30X42.dwg")), (Path.Combine(xrefloc, "TBLK_30X42.dwg")), false); File.Copy((Path.Combine(tblk_dir, "30X42INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo_30X42.dwg")), false); //insert the titleblock newdoc.Xref_Attach(other_tblk, "TBLK_30X42", l.LayoutName); } break; case "30,48": //change the actual page size curlay.SetPageSize(30.00, 48.00, ppunits); // save the titleblock from the G Drive into the project folder // as TBLK.dwg and the titleblock info as well as TBLKinfo.dwg if (!File.Exists(TBLK)) { File.Copy((Path.Combine(tblk_dir, "30X48.dwg")), (Path.Combine(xrefloc, "TBLK.dwg")), false); File.Copy((Path.Combine(tblk_dir, "30X48INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo.dwg")), false); //insert the titleblock newdoc.Xref_Attach(TBLK, "TBLK", l.LayoutName); } else { string other_tblk = Path.Combine(xrefloc, "TBLK_30X48.dwg"); File.Copy((Path.Combine(tblk_dir, "30X48.dwg")), (Path.Combine(xrefloc, "TBLK_30X48.dwg")), false); File.Copy((Path.Combine(tblk_dir, "30X48INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo_30X48.dwg")), false); //insert the titleblock newdoc.Xref_Attach(other_tblk, "TBLK_30X48", l.LayoutName); } break; default: case "36,48": //change the actual page size curlay.SetPageSize(36.00, 48.00, ppunits); // save the titleblock from the G Drive into the project folder // as TBLK.dwg and the titleblock info as well as TBLKinfo.dwg if (!File.Exists(TBLK)) { File.Copy((Path.Combine(tblk_dir, "36X48.dwg")), (Path.Combine(xrefloc, "TBLK.dwg")), false); File.Copy((Path.Combine(tblk_dir, "36X48INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo.dwg")), false); //insert the titleblock newdoc.Xref_Attach(TBLK, "TBLK", l.LayoutName); } else { string other_tblk = Path.Combine(xrefloc, "TBLK_36X48.dwg"); File.Copy((Path.Combine(tblk_dir, "36X48.dwg")), (Path.Combine(xrefloc, "TBLK_36X48.dwg")), false); File.Copy((Path.Combine(tblk_dir, "36X48INF.dwg")), (Path.Combine(xrefloc, "TBLKinfo_36X48.dwg")), false); //insert the titleblock newdoc.Xref_Attach(other_tblk, "TBLK_36X48", l.LayoutName); } break; } } catch (IOException) { //change the actual page size curlay.SetPageSize(36.00, 48.00, ppunits); //insert the titleblock newdoc.Xref_Attach(TBLK, "TBLK", l.LayoutName); } //newdoc.Editor.Regen(); tr1.Commit(); } #endregion #region Layout Creation //switches to appropiate layout and calls it "Work" using (Transaction tr2 = mgr_doc.MdiActiveDocument.Database.TransactionManager.StartTransaction()) { LayoutManager newlaymgr = LayoutManager.Current; Layout curlay = new Layout(); List <Layout> new_listoflayouts = Project_ListOfLayouts(newdoc); if (new_listoflayouts.Any(ln => ln.LayoutName.Equals(l.LayoutName))) { for (int i = 0; i < new_listoflayouts.Count; i++) { if (new_listoflayouts[i].LayoutName.Equals(l.LayoutName)) { curlay = new_listoflayouts[i]; break; } } } else { newdoc.Create_NewLayout(l.LayoutName); for (int i = 0; i < new_listoflayouts.Count; i++) { if (new_listoflayouts[i].LayoutName.Equals(l.LayoutName)) { curlay = new_listoflayouts[i]; break; } } } if (curlay.LayoutName.ToUpper() != "LAYOUT1") { newlaymgr.DeleteLayout("Layout1"); } newlaymgr.RenameLayout(curlay.LayoutName, "Work"); // for each set of viewport info in the List of VP info foreach (AutoCADViewport vpinfo in vp_dict[l]) { // create a new vp with the corresponding info curlay.Viewport_Create(vpinfo, newdoc); //newdoc.Editor.Regen(); } tr2.Commit(); } newdoc.Editor.Regen(); //delete the extra viewport that gets created sometimes... using (Transaction tr3 = newdoc.TransactionManager.StartTransaction()) { LayoutManager newlaymgr1 = LayoutManager.Current; Layout layout = tr3.GetObject(newlaymgr1.GetLayoutId(newlaymgr1.CurrentLayout), OpenMode.ForWrite) as Layout; BlockTableRecord lay_btr = tr3.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord; ObjectIdCollection vp_ids = layout.GetViewports(); RXClass VPClass = RXObject.GetClass(typeof(Viewport)); foreach (ObjectId item in lay_btr) { if (item.ObjectClass == VPClass) { Viewport vp = tr3.GetObject(item, OpenMode.ForWrite) as Viewport; var laywidth = layout.GetWidth(); var layheight = layout.GetHeight(); if (vp.Number != 1 && (vp.Height > layheight || vp.Width > laywidth)) { vp.Erase(); } newdoc.Editor.Regen(); } } tr3.Commit(); } } #endregion #region Closing Area try { AutoCADCommand.Audit(); AutoCADCommand.Purge(); //save all the changes newdoc.Database.SaveAs( (newdoc.Name), true, DwgVersion.AC1800, db.SecurityParameters); } catch { break; } try { mgr_doc.MdiActiveDocument.CloseAndDiscard(); } catch { } } } try { //mgr_doc.MdiActiveDocument = mgr_doc.GetDocument(db); //mgr_doc.GetDocument(db).CloseAndDiscard(); //mgr_doc.Open("G:\\BRATEMP\\PDS\\BLANK.DWG",false); } catch (System.Runtime.InteropServices.COMException acadcom) { Console.WriteLine("Exception was {0} type and the inner exception was {1}", acadcom.ErrorCode, acadcom.InnerException); Console.ReadLine(); } }
public static int LabelAllPipes() { var pipeLabeler = new Labeler( new LabelSpecs { Tag = "PIPENUMBER", BlockName = "PipeLabel", Layer = "PipeLabels", LayerColorIndex = ColorIndices.Blue, TextHeight = 4.0, XOffset = 0.0, YOffset = 0.0, HorizontalMode = TextHorizontalMode.TextCenter }); int pipeNumber = 1; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(" LabelAllPipes starting..."); var ids = new List <ObjectId>(); using (var trans = ModelSpace.StartTransaction()) { foreach (ObjectId id in ModelSpace.From(trans)) { ids.Add(id); } } using (var trans = ModelSpace.StartTransaction()) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(" Finding labels..."); foreach (ObjectId objectId in ids) { if (IsLabel(trans, objectId)) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" label found, erase block..."); var block = trans.GetObject(objectId, OpenMode.ForWrite) as BlockReference; var blkrefClass = RXObject.GetClass(typeof(BlockReference)); if (block != null && objectId.ObjectClass == blkrefClass) { block.Erase(true); } Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" label found, erase DBTtext..."); var text = trans.GetObject(objectId, OpenMode.ForWrite) as DBText; if (text != null) { text.Erase(true); } } } Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(" Finding pipes..."); foreach (ObjectId objectId in ids) { var vertices = new List <Point3d>(); if (IsPipe(trans, objectId)) { var polyline = trans.GetObject(objectId, OpenMode.ForRead) as Polyline; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" Adding {polyline.NumberOfVertices} vertices..."); for (int i = 0; i < polyline.NumberOfVertices; i++) { vertices.Add(polyline.GetPoint3dAt(i)); } pipeNumber++; } Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" Creating label: p{pipeNumber}..."); for (int i = 1; i < vertices.Count; i++) { pipeLabeler.CreateLabel( text: $"P{pipeNumber}", position: Midpoint(vertices[i], vertices[i - 1])); } } trans.Commit(); return(pipeNumber); } }
public DBObject WblockClone(RXObject ownerPointer, IdMapping idMap, bool isPrimary) { createInstance(); DBObject WblockC = BaseDBObject.WblockClone(ownerPointer,idMap,isPrimary); tr.Dispose(); return WblockC; }
/// <inheritdoc /> public void Initialize() { Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), WaterProofingGripPointOverrule.Instance(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), WaterProofingOsnapOverrule.Instance(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), WaterProofingObjectOverrule.Instance(), true); }
/// <inheritdoc/> public void Terminate() { Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), LevelMarkGripPointOverrule.Instance()); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), LevelMarkOsnapOverrule.Instance()); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), LevelMarkObjectOverrule.Instance()); }
/// <inheritdoc /> public void Terminate() { Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), WaterProofingGripPointOverrule.Instance()); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), WaterProofingOsnapOverrule.Instance()); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), WaterProofingObjectOverrule.Instance()); }
public static void CloseSelectedPolylines() { ObjectId[] selection = null; #region Database var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; #endregion try { var selectionRes = ed.SelectImplied(); // If there's no pickfirst set available... if (selectionRes.Status == PromptStatus.Error) { // ... ask the user to select entities var selectionOpts = new PromptSelectionOptions(); selectionOpts.MessageForAdding = "\nSelect polylines: "; selectionRes = ed.GetSelection(selectionOpts); } else { // If there was a pickfirst set, clear it ed.SetImpliedSelection(new ObjectId[0]); } // If the user has not cancelled... if (selectionRes.Status == PromptStatus.OK) { /*Remove Duplicate Polylines*/ try { selection = selectionRes.Value.GetObjectIds().Where (id => { return((id.ObjectClass == RXObject.GetClass(typeof(Polyline))) || (id.ObjectClass == RXObject.GetClass(typeof(Polyline2d))) || (id.ObjectClass == RXObject.GetClass(typeof(Polyline3d)))); }).ToArray(); foreach (var obj in selection) { if (obj.IsErased) { continue; } if (!DeleteDuplicatePolylines(obj, selection)) { ed.WriteMessage("\nDeleted Polyline Object: " + obj.Handle); } } } catch (Exception) { MessengerManager.MessengerManager.AddLog( "\nError deleting polylines." ); } /*Remove Polylines not on 3 letter layers*/ try { foreach (var obj in selection) { if (obj.IsErased) { continue; } if (!DeleteDuplicatePolylines(obj)) { InteratePolyLines(obj); } ChangeLayerColorFor3LetterName(obj); } } catch (Exception) { MessengerManager.MessengerManager.AddLog( "\nError deleting polylines on 3 letters." ); } } } catch { } }
//重定义生效 //注意这里的实体类型和Overrule子类中必须严格对应 public static void OverruleStart() { Overrule.AddOverrule(RXObject.GetClass(typeof(Line)), LArrowDrawOverrule3.TheOverrule, false); Overrule.AddOverrule(RXObject.GetClass(typeof(Line)), LArrowGripOverrule3.TheOverrule, false); }
/// <inheritdoc /> public void Terminate() { Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), GroundLineGripPointOverrule.Instance()); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), GroundLineOsnapOverrule.Instance()); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), GroundLineObjectOverrule.Instance()); }
public override void Run(string filename, Database db) { List <ObjectId> tables = new List <ObjectId>(); if (purgeBlocks) { tables.Add(db.BlockTableId); } if (purgeDimensionStyles) { tables.Add(db.DimStyleTableId); } if (purgeLayers) { tables.Add(db.LayerTableId); } if (purgeLinetypes) { tables.Add(db.LinetypeTableId); } if (purgeTextStyles || purgeShapes) { tables.Add(db.TextStyleTableId); } if (purgeUCSSettings) { tables.Add(db.UcsTableId); } if (purgeViewports) { tables.Add(db.ViewportTableId); } if (purgeViews) { tables.Add(db.ViewTableId); } List <ObjectId> dictionaries = new List <ObjectId>(); if (purgeGroups) { dictionaries.Add(db.GroupDictionaryId); } if (purgeMaterials) { dictionaries.Add(db.MaterialDictionaryId); } if (purgeMlineStyles) { dictionaries.Add(db.MLStyleDictionaryId); } if (purgeMultileaderStyles) { dictionaries.Add(db.MLeaderStyleDictionaryId); } if (purgePlotStyles) { dictionaries.Add(db.PlotStyleNameDictionaryId); } if (purgeTableStyles) { dictionaries.Add(db.TableStyleDictionaryId); } if (purgeVisualStyles) { dictionaries.Add(db.VisualStyleDictionaryId); } if (purgeDetailViewStyles) { dictionaries.Add(db.DetailViewStyleDictionaryId); } if (purgeSectionViewStyles) { dictionaries.Add(db.SectionViewStyleDictionaryId); } using (Transaction tr = db.TransactionManager.StartTransaction()) { try { ObjectIdCollection idList = new ObjectIdCollection(); string s = ""; // Symbol tables foreach (ObjectId tableID in tables) { foreach (ObjectId id in CollectTableIds(tr, db, tableID)) { if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(TextStyleTableRecord)).UnmanagedObject) { // Seperate font styles and shapes TextStyleTableRecord style = (TextStyleTableRecord)tr.GetObject(id, OpenMode.ForRead); if (purgeTextStyles && !style.IsShapeFile) { idList.Add(id); } else if (purgeShapes && style.IsShapeFile) { idList.Add(id); } } else { idList.Add(id); } } } System.IO.File.WriteAllText("D:\\log.txt", s); // Dictionary entries foreach (ObjectId dictionaryID in dictionaries) { foreach (ObjectId id in CollectDictionaryIds(tr, db, dictionaryID)) { idList.Add(id); } } // Reg apps if (purgeRegApps) { RegAppTable regAppTable = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead); foreach (ObjectId id in regAppTable) { if (id.IsValid) { idList.Add(id); } } } // Empty text objects or zero length geometry if (purgeEmptyTexts | purgeZeroLengthGeometry) { ObjectIdCollection blockIDs = new ObjectIdCollection(); blockIDs.Add(SymbolUtilityServices.GetBlockModelSpaceId(db)); DBDictionary layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead); foreach (DBDictionaryEntry entry in layoutDict) { if (entry.Key.ToUpperInvariant() != "MODEL") { Layout layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead); blockIDs.Add(layout.BlockTableRecordId); } } int textCount = 0; int zeroLengthCount = 0; foreach (ObjectId blockID in blockIDs) { var btr = (BlockTableRecord)tr.GetObject(blockID, OpenMode.ForRead); foreach (ObjectId id in btr) { // Empty text objects if (purgeEmptyTexts && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject) { DBText text = (DBText)tr.GetObject(id, OpenMode.ForRead); if (string.IsNullOrEmpty(text.TextString)) { text.UpgradeOpen(); text.Erase(true); textCount++; } } else if (purgeEmptyTexts && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(MText)).UnmanagedObject) { MText text = (MText)tr.GetObject(id, OpenMode.ForRead); if (string.IsNullOrEmpty(text.Text)) { text.UpgradeOpen(); text.Erase(true); textCount++; } } // Zero length geometry else if (purgeZeroLengthGeometry && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Curve)))) { Curve curve = (Curve)tr.GetObject(id, OpenMode.ForRead); if (curve.GetLength() < zeroLengthGeometryTolerance) { curve.UpgradeOpen(); curve.Erase(true); zeroLengthCount++; } } } } } // Filter purgables db.Purge(idList); // Step through the returned ObjectIdCollection // and erase each unreferenced symbol int purgeCount = 0; foreach (ObjectId id in idList) { DBObject obj = tr.GetObject(id, OpenMode.ForWrite); obj.Erase(true); purgeCount++; } } catch (System.Exception ex) { OnError(ex); } tr.Commit(); } }
/// <inheritdoc /> public override bool IsApplicable(RXObject overruledSubject) { return(ExtendedDataUtils.IsApplicable(overruledSubject, Axis.GetDescriptor().Name, true)); }
/// <inheritdoc/> public override bool IsApplicable(RXObject overruledSubject) { return(ExtendedDataUtils.IsApplicable(overruledSubject, GroundLineDescriptor.Instance.Name, true)); }
/// <summary> /// 卸载右键菜单 /// </summary> private void RemoveContextMenu() { try { if (m_ContextMenu != null) { Autodesk.AutoCAD.ApplicationServices.Application.RemoveObjectContextMenuExtension(RXObject.GetClass(typeof (Entity)),m_ContextMenu); m_ContextMenu.Dispose(); m_ContextMenu = null; } } catch(CADException ex) { PublicMethod.Instance.ShowMessage(ex.Message); } }
/// <inheritdoc/> public void Initialize() { Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), LevelMarkGripPointOverrule.Instance(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), LevelMarkOsnapOverrule.Instance(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), LevelMarkObjectOverrule.Instance(), true); }