Example #1
0
        private static void RegisterObjectIdUpdaterEvent(IObjectContainer db, ObjectEventHandler activationTracker)
        {
            IEventRegistry eventRegistry = EventRegistryFactory.ForObjectContainer(db);
            
            eventRegistry.Activated += activationTracker;
            activationCount = 0;

            eventRegistry.Instantiated += delegate(object sender, ObjectEventArgs args)
                                          {
                                              SupportObjectId obj = args.Object as SupportObjectId;
                                              if (obj != null)
                                              {
                                                  obj.ObjectId = db.Ext().GetID(obj);
                                              }
                                          };
        }
Example #2
0
        private static void RegisterObjectIdUpdaterEvent(IObjectContainer db, ObjectEventHandler activationTracker)
        {
            IEventRegistry eventRegistry = EventRegistryFactory.ForObjectContainer(db);

            eventRegistry.Activated += activationTracker;
            activationCount          = 0;

            eventRegistry.Instantiated += delegate(object sender, ObjectEventArgs args)
            {
                SupportObjectId obj = args.Object as SupportObjectId;
                if (obj != null)
                {
                    obj.ObjectId = db.Ext().GetID(obj);
                }
            };
        }
Example #3
0
        public void ObjectEvents()
        {
            int customerCreated = 0;

            ObjectEventHandler <Customer> eventDelegate = delegate(Customer obj, EventArgs e) { customerCreated = obj.CustomerID; };

            Customer.AnyObjectCreated += eventDelegate;

            Customer customer = Customer.New();

            customer.Name = "Blabla";
            customer.Save();

            Assert.AreEqual(customer.CustomerID, customerCreated);

            Customer.AnyObjectCreated -= eventDelegate;
        }
Example #4
0
 private void SetHandler(IObjectCanvas Canvas, PropertyGrid propertyGrid, ObjectToolPanel ToolPanel)
 {
     if (Canvas != null)
     {
         SetCanvas(Canvas);
     }
     if (propertyGrid != null)
     {
         SetPropertyGrid(propertyGrid);
     }
     if (ToolPanel != null)
     {
         SetToolPanel(ToolPanel);
         AfterCreateStart    += new ObjectEventHandler(ObjectManager_AfterCreateStart);
         AfterSelect         += new ObjectEventHandler(ObjectManager_AfterSelect);
         AfterCreateFinished += new ObjectEventHandler(ToolPanel.Manager_AfterCreateFinished);
         AfterCreateFinished += new ObjectEventHandler(ObjectManager_AfterCreateFinished);
     }
 }
        /// <summary>
        /// create map image
        /// not working currently
        /// </summary>
        /// <param name="data"></param>
        private void createMapImage(GeoLocationData data)
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            var db = doc.Database;
            var ed = doc.Editor;

            //now get an image

            var first = new Point2d(261290.0000, 270952.5000);
            //second corner
            var second = new Point2d(568732.0000, 76776.5000);

            ObjectId           giId    = ObjectId.Null;
            ObjectEventHandler handler =
                (s, e) =>
            {
                if (e.DBObject is GeomapImage)
                {
                    giId = e.DBObject.ObjectId;
                    ed.WriteMessage("\n map image objectid: " + giId);
                }
            };

            // Simply call the GEOMAPIMAGE command with the two points
            db.ObjectAppended += handler;
            ed.Command("GEOMAPIMAGE", "V");
            db.ObjectAppended -= handler;

            if (giId == ObjectId.Null)
            {
                return;
            }

            // Open the entity and change some values
            try
            {
                using (var tr = doc.TransactionManager.StartTransaction())
                {
                    // Get each object and check if it's a GeomapImage
                    var gi =
                        tr.GetObject(giId, OpenMode.ForWrite) as GeomapImage;
                    if (gi != null)
                    {
                        // Let's adjust the brightmess/contrast/fade of the
                        // GeomapImage

                        gi.Brightness = 50;
                        gi.Contrast   = 15;
                        gi.Fade       = 0;

                        // And make sure it's at the right resolution and
                        // shows both aerial and road information

                        gi.Resolution = GeomapResolution.Optimal;
                        gi.MapType    = GeomapType.Road;

                        gi.UpdateMapImage(true);

                        //keep map only
                        //data.EraseFromDb();
                    }

                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception)
            {
                ed.WriteMessage(
                    "\nUnable to update geomap image entity." +
                    "\nPlease check your internet connectivity and call " +
                    "GEOMAPIMAGEUPDATE."
                    );
            }
        }
        //https://www.keanw.com/2014/09/exploding-nested-autocad-blocks-using-net.html

        private void ExplodeBlock(Transaction tr, Database db, ObjectId id, bool erase = true)

        {

            // Open out block reference - only needs to be readable for the explode operation, as it's non-destructive
            var br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);

            // We'll collect the BlockReferences created in a collection
            var toExplode = new ObjectIdCollection();

            // Define our handler to capture the nested block references
            ObjectEventHandler handler = (s, e) =>
            {
                if (e.DBObject is BlockReference)

                {

                    toExplode.Add(e.DBObject.ObjectId);

                }

            };


            // Add our handler around the explode call, removing it directly afterwards

            db.ObjectAppended += handler;

            br.ExplodeToOwnerSpace();

            db.ObjectAppended -= handler;



            // Go through the results and recurse, exploding the

            // contents



            foreach (ObjectId bid in toExplode)

            {

                ExplodeBlock(tr, db, bid, erase);

            }



            // We might also just let it drop out of scope



            toExplode.Clear();



            // To replicate the explode command, we're delete the

            // original entity



            if (erase)

            {

                br.UpgradeOpen();

                br.Erase();

                br.DowngradeOpen();

            }

        }