public static ObjectId Insert(ObjectId blkDefId, Matrix3d transform, Database db = null, string space = null) { db = (db ?? Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database); ObjectId id = ObjectId.Null; using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable blkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord mdlSpc = trans.GetObject(blkTbl[space ?? BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; BlockReference blkRef = new BlockReference(Point3d.Origin, blkDefId); blkRef.BlockTransform = transform; id = mdlSpc.AppendEntity(blkRef); trans.AddNewlyCreatedDBObject(blkRef, true); BlockTableRecord blkDef = trans.GetObject(blkDefId, OpenMode.ForRead) as BlockTableRecord; if (blkDef.HasAttributeDefinitions) { foreach (ObjectId subId in blkDef) { if (subId.ObjectClass.Equals(RXObject.GetClass(typeof(AttributeDefinition)))) { AttributeDefinition attrDef = trans.GetObject(subId, OpenMode.ForRead) as AttributeDefinition; AttributeReference attrRef = new AttributeReference(); attrRef.SetAttributeFromBlock(attrDef, transform); blkRef.AttributeCollection.AppendAttribute(attrRef); } } } trans.Commit(); } return(id); }
public static void ChangeCircleColors() { var document = AcadApp.DocumentManager.MdiActiveDocument; var database = document.Database; using (var tr = database.TransactionManager.StartOpenCloseTransaction()) { try { var circleClass = RXObject.GetClass(typeof(Circle)); var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(database); var modelSpace = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForRead); foreach (ObjectId id in modelSpace) { if (!id.ObjectClass.IsDerivedFrom(circleClass)) { continue; } var circle = (Circle)tr.GetObject(id, OpenMode.ForWrite); circle.ColorIndex = circle.Radius <1.0 ? 2 : circle.Radius> 10.0 ? 1 : 3; } tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { tr.Abort(); document.Editor.WriteMessage(ex.Message); } } }
/// <summary> /// Gets the rough outline. /// </summary> /// <param name="collection">The collection.</param> /// <returns>Acaddb.Polyline.</returns> private static Acaddb.Polyline GetRoughOutline(Acaddb.ObjectIdCollection collection) { try { var theClass = RXObject.GetClass(typeof(Acaddb.Polyline)); foreach (Acaddb.ObjectId oid in collection) { if (!oid.ObjectClass.IsDerivedFrom(theClass)) { continue; } var polyline = GetObject(oid); if (polyline == null) { continue; } if (polyline.Layer.Length < 8) { if (polyline.Layer.Equals("ORO") || polyline.Layer.Contains("ROUGH-OUTLINE")) { return(polyline); } } } } catch (Exception ex) { COMS.MessengerManager.LogException(ex); } return(null); }
public static IEnumerable <T> GetObjects <T>(this BlockTableRecord btr, OpenMode mode, bool openErased, bool forceOpenOnLockedLayers) where T : Entity { BlockTableRecord blockTableRecords = (openErased ? btr.IncludingErased : btr); TransactionManager transactionManager = btr.Database.TransactionManager; if (typeof(T) != typeof(Entity)) { RXClass @class = RXObject.GetClass(typeof(T)); foreach (ObjectId objectId in blockTableRecords) { if (!(objectId.ObjectClass == @class) && !objectId.ObjectClass.IsDerivedFrom(@class)) { continue; } yield return((T)transactionManager.GetObject(objectId, mode, openErased, forceOpenOnLockedLayers)); } @class = null; } else { foreach (ObjectId objectId1 in blockTableRecords) { yield return((T)transactionManager.GetObject(objectId1, mode, openErased, forceOpenOnLockedLayers)); } } }
public bool askForDistances(AC_Line acline) { circleCenter = acline.StartPoint; previewCircle = new AC_Circle(); previewCircle.addToDrawing(); removeSnap noSnap = new removeSnap(previewCircle.ObjectId); ObjectOverrule.AddOverrule(RXObject.GetClass(typeof(Entity)), noSnap, true); drawPreviewCircle = true; PromptDistanceOptions DistOption = new PromptDistanceOptions("Triangulation Distance"); DistOption.BasePoint = circleCenter; DistOption.UseBasePoint = true; PromptDoubleResult triang1 = tr.AC_Doc.Editor.GetDistance(DistOption); if (triang1.Status == PromptStatus.OK) { if (triang1.Value != 0) { tr.AC_Doc.Editor.WriteMessage(triang1.Value.ToString() + "\n"); circleCenter = acline.EndPoint; DistOption.BasePoint = circleCenter; radius.Add(triang1.Value); PromptDoubleResult triang2 = tr.AC_Doc.Editor.GetDistance(DistOption); if (triang2.Status == PromptStatus.OK) { tr.AC_Doc.Editor.WriteMessage(triang2.Value.ToString() + "\n"); radius.Add(triang2.Value); previewCircle.Visible = false; drawPreviewCircle = false; return(true); } else { tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor; ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap); previewCircle.Erase(true); return(false); } } else { tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor; tr.AC_Doc.Editor.WriteMessage("Cannot Calculate Triangulation \n"); ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap); previewCircle.Erase(true); return(false); } } else { tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor; ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap); previewCircle.Visible = false; drawPreviewCircle = false; return(false); } }
public static void TecTest() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction Tx = db.TransactionManager.StartTransaction()) { BlockTableRecord ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead); RXObject brClass = RXObject.GetClass(typeof(BlockReference)); Point3d lastrightpt = new Point3d(0, 0, 0); foreach (ObjectId id in ms) { if (id.ObjectClass == brClass) { BlockReference br = (BlockReference)Tx.GetObject(id, OpenMode.ForWrite); ed.WriteMessage("NAME:{0}\n", br.Name); Extents3d bounds = br.GeometricExtents; ed.WriteMessage("BOUNDS: {0}\n", bounds.ToString()); Vector3d vec = (Vector3d)(lastrightpt - bounds.MinPoint); ed.WriteMessage("VECTOR: {0}\n", vec.ToString()); Point3d rightpt = new Point3d(bounds.MaxPoint.X, bounds.MinPoint.Y, 0);; Vector3d newrp = (Vector3d)(vec + rightpt.GetAsVector() + (new Vector3d(50, 0, 0))); lastrightpt = new Point3d(newrp.X, newrp.Y, 0); ed.WriteMessage("NEWLASTRIGHT SET to {0}\n", lastrightpt); Matrix3d mat = Matrix3d.Displacement(vec); br.TransformBy(mat); } } Tx.Commit(); } }
public void newDIMinc() { start_DIMline(); index = 1; while (true) { if (!askforPoint()) { break; } update_DIMline(index); if (!create_DIMtxt(index)) { break; } ; index++; } ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), preview._osOverrule); ObjectId textsGroup = createTextGroup(DIMtexts); AddExtensionDictionary(DIMline); DimIncMod.Add_Events(DIMline, textsGroup); }
public static void RemoveAllViewports(this Layout layout) { var db = layout.Database; using (var tr = db.TransactionManager.StartTransaction()) { var layoutRecord = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite); var viewportType = RXObject.GetClass(typeof(Viewport)); foreach (var obj in layoutRecord) { if (obj.ObjectClass != viewportType) { continue; } var vp = (Viewport)tr.GetObject(obj, OpenMode.ForWrite); vp.Erase(); CurrentDocument.Editor.Regen(); } tr.Commit(); } }
public static List <ObjectId> getBlockRefs() { List <ObjectId> ids = new List <ObjectId>(); using (var tr = BaseObjs.startTransactionDb()) { var bt = (BlockTable)tr.GetObject( BaseObjs._db.BlockTableId, OpenMode.ForRead); var ms = (BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); RXClass theClass = RXObject.GetClass(typeof(BlockReference)); foreach (ObjectId id in ms) { if (id.ObjectClass.IsDerivedFrom(theClass)) { var br = (BlockReference)tr.GetObject( id, OpenMode.ForRead); if (br.Name.ToUpper() == "GRADETAG" || br.Name.ToUpper() == "FLTAG") { ids.Add(br.ObjectId); } } } } return(ids); }
static General() { List <string> bimUsers; try { bimUsers = GetBimUsers(); } catch { bimUsers = _bimUsers; } 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 void RemoveOverrule() { Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), UserDrawOverrule.TheOverrule); Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), DCadDrawEntityOverrule.TheOverrule); Overrule.RemoveOverrule(RXObject.GetClass(typeof(DBText)), DCadDrawEntityOverrule.TheOverrule); Overrule.RemoveOverrule(RXObject.GetClass(typeof(MText)), DCadDrawEntityOverrule.TheOverrule); }
public static void ForEachInAllBlockTableRecords <T>(this Database database, Action <T> action) where T : Entity { using (var tr = database.TransactionManager.StartTransaction()) { // Get the block table for the current database var blockTable = (BlockTable)tr.GetObject(database.BlockTableId, OpenMode.ForRead); foreach (ObjectId id in blockTable) { // Get the model space block table record var blockTableRecord = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead); // get theClassType RXClass theClass = RXObject.GetClass(typeof(T)); // Loop through the entities in model space foreach (ObjectId objectId in blockTableRecord) { // Look for entities of the correct type if (objectId.ObjectClass.IsDerivedFrom(theClass)) { var entity = (T)tr.GetObject( objectId, OpenMode.ForWrite); action(entity); } } } tr.Commit(); } }
static bool IsLabel(Transaction trans, ObjectId objectId) { try { if (objectId.IsNull || objectId.IsErased || !objectId.IsValid) { return(false); } var block = trans.GetObject(objectId, OpenMode.ForRead) as BlockReference; var blkrefClass = RXObject.GetClass(typeof(BlockReference)); if (block != null && objectId.ObjectClass == blkrefClass) { return(string.Equals(block.Layer, "PipeLabels", StringComparison.OrdinalIgnoreCase)); } var text = trans.GetObject(objectId, OpenMode.ForRead) as DBText; if (text != null) { return(string.Equals(text.Layer, "Pipe Labels", StringComparison.OrdinalIgnoreCase)); } return(false); } catch (System.Exception e) { throw new System.Exception("Cannot determine if an object is a label", e); } }
public static void AddOverrule() { Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), UserDrawOverrule.TheOverrule, false); Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), DCadDrawEntityOverrule.TheOverrule, false); Overrule.AddOverrule(RXObject.GetClass(typeof(DBText)), DCadDrawEntityOverrule.TheOverrule, true); Overrule.AddOverrule(RXObject.GetClass(typeof(MText)), DCadDrawEntityOverrule.TheOverrule, true); }
public bool hadColorized(MyDB2 mydb) { string dxfName = RXObject.GetClass(typeof(Region)).DxfName; ObjectId[] ids = My.Selection.GetObjectIDs(dxfName, ccLayerNamePrefix + "_" + mydb.Resolution); return(ids != null && ids.Length > 0); }
public void UnlockAllViewports() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction transaction = acCurDb.TransactionManager.StartTransaction()) { PromptSelectionResult prompt = acDoc.Editor.SelectAll(); if (prompt.Status != PromptStatus.OK) { return; } SelectionSet selectionSet = prompt.Value; foreach (SelectedObject obj in selectionSet) { if (obj.ObjectId.ObjectClass == RXObject.GetClass(typeof(Viewport))) { Viewport viewport = (Viewport)transaction.GetObject(obj.ObjectId, OpenMode.ForWrite); viewport.Locked = false; } } transaction.Commit(); } }
/// <summary> /// Initializes a new _instance of the <see cref="DbObjectEnumerator{T}"/> class. /// </summary> /// <param name="enumerator">The enumerator to wrap.</param> /// <param name="transaction">The current transaction.</param> /// <param name="openMode">The open mode.</param> public DbObjectEnumerator(IEnumerator <ObjectId> enumerator, Transaction transaction, OpenMode openMode) { _enumerator = enumerator; _transaction = transaction; _open_mode = openMode; _ent_type = RXObject.GetClass(typeof(T)); }
ForEach <T>(Action <T> action) where T : Entity { try { using (var tr = BaseObjs.startTransactionDb()) { var blockTable = (BlockTable)tr.GetObject(BaseObjs._db.BlockTableId, OpenMode.ForRead); var modelSpace = (BlockTableRecord)tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead); RXClass theClass = RXObject.GetClass(typeof(T)); foreach (ObjectId id in modelSpace) { if (id.ObjectClass.IsDerivedFrom(theClass)) { try { var ent = (T)tr.GetObject(id, OpenMode.ForRead); action(ent); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " LdrText_Misc.cs: line: 37"); } } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " LdrText_Misc.cs: line: 46"); } }
// Gets the display name of an object type. public static string GetDisplayName(RXClass classObject) { using (RXObject rawObject = classObject.Create()) { if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(AecDbObject)))) { AecDbObject dbObject = (AecDbObject)rawObject; return(dbObject.DisplayName); } else if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(AecEntity)))) { AecEntity entity = (AecEntity)rawObject; return(entity.DisplayName); } else if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(DBObject)))) { string dxfName = classObject.DxfName; if (dxfName == null) { return(classObject.Name); } else { return(dxfName); } } } throw new ArgumentException("wrong class type"); }
/// <summary> Adds Entities (text, Attribute Definitions etc)to the block definition. </summary> /// <param name="blockDefinitionObjectId"> <see cref="ObjectId"/> for the block definition object. </param> /// <param name="entities"> The entities to add to the block. </param> /// <returns> true if it succeeds, false if it fails. </returns> /// <exception cref="ArgumentNullException">The value of 'blockDefinitionObjectId' cannot be null. </exception> public static bool AddEntitiesToBlockDefinition <T>(ObjectId blockDefinitionObjectId, ICollection <T> entities) where T : Entity { if (blockDefinitionObjectId == null) { throw new ArgumentNullException("blockDefinitionObjectId"); } if (!blockDefinitionObjectId.IsValid) { return(false); } if (entities == null) { throw new ArgumentNullException("entities"); } if (entities.Count < 1) { return(false); } Xpos = 0; Ypos = 0; bool workedOk = false; Database database = blockDefinitionObjectId.Database; TransactionManager transactionManager = database.TransactionManager; using (Transaction transaction = transactionManager.StartTransaction()) { if (blockDefinitionObjectId.ObjectClass == (RXObject.GetClass(typeof(BlockTableRecord)))) { BlockTableRecord blockDefinition = (BlockTableRecord)transactionManager.GetObject(blockDefinitionObjectId, OpenMode.ForWrite, false); if (blockDefinition != null) { foreach (T entity in entities) { DBText text = entity as DBText; if (text != null) { text.Position = new Point3d(Xpos, Ypos, Zpos); incrementXY(); } else { MText mText = entity as MText; if (mText != null) { mText.Location = new Point3d(Xpos, Ypos, Zpos); incrementXY(); } } blockDefinition.AppendEntity(entity); // todo: vertical spacing ?? transactionManager.AddNewlyCreatedDBObject(entity, true); } workedOk = true; } } transaction.Commit(); } return(workedOk); }
public void Initialize() { // Register custom osnap on initialize _mode = new CustomObjectSnapMode( "Quarter", "Quarter", "Quarter of length", _glyph ); // Which kind of entity will use the osnap _mode.ApplyToEntityType( RXObject.GetClass(typeof(Polyline)), new AddObjectSnapInfo(_info.SnapInfoPolyline) ); _mode.ApplyToEntityType( RXObject.GetClass(typeof(Curve)), new AddObjectSnapInfo(_info.SnapInfoCurve) ); _mode.ApplyToEntityType( RXObject.GetClass(typeof(Entity)), new AddObjectSnapInfo(_info.SnapInfoEntity) ); // Activate the osnap CustomObjectSnapMode.Activate("_Quarter"); }
public static void Detach() { if (MpPrToTableCme != null) { var rxcEnt = RXObject.GetClass(typeof(Entity)); Application.RemoveObjectContextMenuExtension(rxcEnt, MpPrToTableCme); } }
//关闭夹点规则重定义 public static void closeGripRule() { if (UserGripOverrule.TheOverrule != null) { Overrule.RemoveOverrule(RXObject.GetClass(typeof(BlockReference)), UserGripOverrule.TheOverrule); Overrule.RemoveOverrule(RXObject.GetClass(typeof(DBText)), UserGripOverrule.TheOverrule); Overrule.RemoveOverrule(RXObject.GetClass(typeof(MText)), UserGripOverrule.TheOverrule); } }
//开启夹点规则重定义 public static void openGripRule() { if (UserGripOverrule.TheOverrule != null) { Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), UserGripOverrule.TheOverrule, false); Overrule.AddOverrule(RXObject.GetClass(typeof(DBText)), UserGripOverrule.TheOverrule, true); Overrule.AddOverrule(RXObject.GetClass(typeof(MText)), UserGripOverrule.TheOverrule, true); } }
static void OnObjectAppended(object sender, _OdDb.ObjectEventArgs e) { var objId = e.DBObject.ObjectId; if (objId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(_OdDb.Entity)))) { _appended.Add(e.DBObject.ObjectId.Handle); } }
public static void Start() { var cm = new ContextMenuExtension(); var menu = new MenuItem(Resources.ContextMenu); menu.Click += Click; cm.MenuItems.Add(menu); Application.AddObjectContextMenuExtension(RXObject.GetClass(typeof(Entity)), cm); }
private static void End() { foreach (Overrule o in m_overrules) { Overrule.RemoveOverrule(RXObject.GetClass(typeof(Circle)), o); } Overrule.Overruling = false; Application.DocumentManager.MdiActiveDocument.Editor.Regen(); }
public static void Detach() { if (ContextMenu != null) { var rxcEnt = RXObject.GetClass(typeof(BlockReference)); Application.RemoveObjectContextMenuExtension(rxcEnt, ContextMenu); ContextMenu = null; } }
public void HideIcon() { if (ProductsDrawableOverrule.ProductsDrawableOverruleInstance != null) { UserConfigFile.SetValue("mpProductInsert", "ShowIcon", false.ToString(), true); Overrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), ProductsDrawableOverrule.Instance()); ProductsDrawableOverrule.ProductsDrawableOverruleInstance = null; Application.DocumentManager.MdiActiveDocument.Editor.Regen(); } }
public static void ShowIcon() { if (MpProductsDrawableOverrule.MpProductsDrawableOverruleInstance == null) { UserConfigFile.SetValue(UserConfigFile.ConfigFileZone.Settings, "mpProductInsert", "ShowIcon", true.ToString(), true); Overrule.AddOverrule(RXObject.GetClass(typeof(Entity)), MpProductsDrawableOverrule.Instance(), true); Overrule.Overruling = true; AcApp.DocumentManager.MdiActiveDocument.Editor.Regen(); } }