Exemplo n.º 1
0
 public static string Get(ObjectId id, string key)
 {
     try {
         if (id.IsErased == false & id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead)) {
                             foreach (ObjectId attributeId in br.AttributeCollection)
                             {
                                 using (AttributeReference attributeRef = (AttributeReference)tr.GetObject(attributeId, OpenMode.ForRead)) {
                                     if (attributeRef.Tag == key)
                                     {
                                         return(attributeRef.TextString);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
     return(default(string));
 }
Exemplo n.º 2
0
 public static void Position(ObjectId id, string key, Point3d position)
 {
     try {
         if (id.IsErased == false & id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForWrite)) {
                             foreach (ObjectId attributeId in br.AttributeCollection)
                             {
                                 using (AttributeReference attributeRef = (AttributeReference)tr.GetObject(attributeId, OpenMode.ForWrite)) {
                                     if (attributeRef.Tag == key)
                                     {
                                         attributeRef.Position = position;
                                     }
                                 }
                             }
                         }
                         tr.Commit();
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
Exemplo n.º 3
0
 public static void Delete(ObjectId id, string key)
 {
     try {
         if (id.IsErased == false && id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (DBDictionary dict = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, false)) {
                             if (dict.Contains(key))
                             {
                                 ObjectId deleteId = dict.GetAt(key);
                                 Xrecord  xRec     = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForWrite, false);
                                 xRec.Erase();
                                 dict.Remove(deleteId);
                             }
                         }
                         tr.Commit();
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
Exemplo n.º 4
0
 public static Point3d GetBlockAttributeLocation(ObjectId id, string key)
 {
     try {
         if (id.IsErased == false & id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead)) {
                             foreach (ObjectId attributeId in br.AttributeCollection)
                             {
                                 using (AttributeReference attributeRef = (AttributeReference)tr.GetObject(attributeId, OpenMode.ForRead)) {
                                     if (attributeRef.Tag == key)
                                     {
                                         return(attributeRef.Position);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
     return(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0));
 }
Exemplo n.º 5
0
 //this could be altered to use the typedvalue and retrieve the type from reversing the dxfcode lookup, but we would still need a generic return for the calling function
 public static T Get <T>(string key)
 {
     try {
         if (World.Docu != null)
         {
             if (World.Docu.IsActive == true && World.Docu.IsDisposed == false)
             {
                 using (World.Docu.LockDocument()) {
                     using (Database db = World.Docu.Database) {
                         using (Transaction tr = db.TransactionManager.StartTransaction()) {
                             using (DBDictionary dict = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, false)) {
                                 if (dict.Contains(key))
                                 {
                                     Xrecord      xRec   = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForRead);
                                     ResultBuffer resBuf = xRec.Data;
                                     if (resBuf == null)
                                     {
                                         return(default(T));
                                     }
                                     TypedValue[] typ = resBuf.AsArray();
                                     return((T)Convert.ChangeType(typ[0].Value, typeof(T)));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
     return(default(T));
 }
Exemplo n.º 6
0
 /// <summary>most properties are typed as double, this currently only supports setting double</summary>
 public static void Set(ObjectId id, string key, double value)
 {
     try {
         if (id.IsErased == false && id.IsEffectivelyErased == false && id.IsNull == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForWrite)) {
                             foreach (DynamicBlockReferenceProperty blockProperty in br.DynamicBlockReferencePropertyCollection)
                             {
                                 if (blockProperty.PropertyName == key & World.IsNumeric(blockProperty.Value))
                                 {
                                     blockProperty.Value = value;
                                 }
                             }
                         }
                         tr.Commit();
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
Exemplo n.º 7
0
 public static double Get(ObjectId id, string key)
 {
     try {
         if (id.IsErased == false && id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 if (id != new ObjectId())
                 {
                     using (Database db = World.Docu.Database) {
                         using (Transaction tr = db.TransactionManager.StartTransaction()) {
                             using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead)) {
                                 foreach (DynamicBlockReferenceProperty blockProperty in br.DynamicBlockReferencePropertyCollection)
                                 {
                                     if (blockProperty.PropertyName == key & World.IsNumeric(blockProperty.Value))
                                     {
                                         return(Convert.ToDouble(blockProperty.Value));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
     return(default(double));
 }
Exemplo n.º 8
0
 public void Execute(object parameter)
 {
     if (parameter is RibbonButton)
     {
         RibbonButton button = parameter as RibbonButton;
         string       cmdStr = "._" + button.Id + " ";
         try {
             World.Docu.SendStringToExecute(cmdStr, true, false, false);
         }
         catch (System.Exception ex) {
             Err.Log(ex);
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>this inserts a block into another block, the block designated by oid is the receiver and receives a new copy of the block designated by blockname</summary>
        public static Handle Insert(ObjectId oid, string blockPath, string blockName, Point3d position = new Point3d())
        {
            Handle hd = new Handle();

            try {
                if (oid.IsErased == false & oid.IsEffectivelyErased == false)
                {
                    using (World.Docu.LockDocument()) {
                        using (Database db = World.Docu.Database) {
                            using (Transaction tr = db.TransactionManager.StartTransaction()) {
                                using (BlockReference br = (BlockReference)tr.GetObject(oid, OpenMode.ForWrite)) {
                                    if (AcadIO.Insert.DB.AddBlock(blockPath + "\\" + blockName) == false)
                                    {
                                        return(hd);
                                    }

                                    using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead)) {
                                        using (BlockReference bi = new BlockReference(Autodesk.AutoCAD.Geometry.Point3d.Origin, bt[blockPath])) {
                                            using (BlockTableRecord blockSpace = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForWrite)) {
                                                blockSpace.AppendEntity(bi);
                                                tr.AddNewlyCreatedDBObject(bi, true);
                                                bi.LayerId  = br.LayerId;
                                                bi.Position = position;
                                                hd          = bi.Handle;
                                            }
                                        }
                                    }
                                }
                                tr.Commit();
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex) {
                Err.Log(ex);
            }
            finally {
            }
            return(hd);
        }
Exemplo n.º 10
0
 public static void Set(ObjectId id, string key, object value)
 {
     try {
         if (id.IsErased == false & id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForWrite)) {
                             if (br.ExtensionDictionary == ObjectId.Null)
                             {
                                 br.CreateExtensionDictionary();
                             }
                             using (DBDictionary dict = (DBDictionary)tr.GetObject(br.ExtensionDictionary, OpenMode.ForWrite, false)) {
                                 DxfCode code = AcadIO.DxfHelper.GetFromObject(value);
                                 if (dict.Contains(key))
                                 {
                                     Xrecord      xRec   = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForWrite);
                                     ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value));
                                     xRec.Data = resBuf;
                                 }
                                 else
                                 {
                                     Xrecord      xRec   = new Xrecord();
                                     ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value));
                                     xRec.Data = resBuf;
                                     dict.SetAt(key, xRec);
                                     tr.AddNewlyCreatedDBObject(xRec, true);
                                 }
                             }
                         }
                         tr.Commit();
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
Exemplo n.º 11
0
 public static void Delete(ObjectId oid)
 {
     try {
         if (oid.IsErased == false & oid.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(oid, OpenMode.ForWrite)) {
                             br.Erase();
                         }
                         tr.Commit();
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
Exemplo n.º 12
0
 public static void Set(string key, object value)
 {
     try {
         if (World.Docu != null)
         {
             if (World.Docu.IsActive == true && World.Docu.IsDisposed == false)
             {
                 using (World.Docu.LockDocument()) {
                     using (Database db = World.Docu.Database) {
                         using (Transaction tr = db.TransactionManager.StartTransaction()) {
                             using (DBDictionary dict = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, false)) {
                                 DxfCode code = AcadIO.DxfHelper.GetFromObject(value);
                                 if (dict.Contains(key))
                                 {
                                     Xrecord      xRec   = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForWrite);
                                     ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value));
                                     xRec.Data = resBuf;
                                 }
                                 else
                                 {
                                     Xrecord      xRec   = new Xrecord();
                                     ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value));
                                     xRec.Data = resBuf;
                                     dict.SetAt(key, xRec);
                                     tr.AddNewlyCreatedDBObject(xRec, true);
                                 }
                             }
                             tr.Commit();
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
Exemplo n.º 13
0
 public static T Get <T>(ObjectId id, string key)
 {
     try {
         if (id.IsErased == false & id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead)) {
                             if (br.ExtensionDictionary == ObjectId.Null)
                             {
                                 return(default(T));
                             }
                             using (DBDictionary dict = (DBDictionary)tr.GetObject(br.ExtensionDictionary, OpenMode.ForRead, false)) {
                                 if (dict.Contains(key))
                                 {
                                     Xrecord      xRec   = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForRead);
                                     ResultBuffer resBuf = xRec.Data;
                                     if (resBuf == null)
                                     {
                                         return(default(T));
                                     }
                                     TypedValue[] typ = resBuf.AsArray();
                                     return((T)Convert.ChangeType(typ[0].Value, typeof(T)));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
     return(default(T));
 }