AutoCAD Architecture Customization
Welcome to Autodesk’s AutoCAD Architecture Customization Forums. Share your knowledge, ask questions, and explore popular AutoCAD Architecture Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Programatically add geometry to a duct fitting

1 REPLY 1
Reply
Message 1 of 2
Keith.Brown
413 Views, 1 Reply

Programatically add geometry to a duct fitting

I am trying to add geometry programatically to a duct fitting.  This is because the content builder is incapable of correctly building some types of fittings.  I found some old code from an Autodesk University class that shows how to add geometry to a AEC object.  I have modified it a little to be able to work with a duct fitting but it does not work.  The code compiles fine and runs fine without any errors.  The geometry is just not added.

 

Does anyone have any ideas?

 

        [CommandMethod("ACAClassCode", "ExModelerModifyBody", CommandFlags.Modal)]
        public void ModifyBody()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            // get a mass element to modify.
            PromptEntityOptions prEntOpts = new PromptEntityOptions("\nSelect duct fitting to modify");
            prEntOpts.SetRejectMessage("\nSelected entity must be of type duct fitting");
            //prEntOpts.AddAllowedClass(typeof(Autodesk.Aec.DatabaseServices.MassElement), false);
            prEntOpts.AddAllowedClass(typeof(DuctFitting), false);

            PromptEntityResult prEntRes = ed.GetEntity(prEntOpts);

            if (prEntRes.Status != PromptStatus.OK)
                return;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;


            using (Transaction trans = tm.StartTransaction())
            {
                // Open the duct fitting
                //Autodesk.Aec.DatabaseServices.MassElement me = (Autodesk.Aec.DatabaseServices.MassElement)trans.GetObject(prEntRes.ObjectId, OpenMode.ForWrite);
                DuctFitting me = (DuctFitting)trans.GetObject(prEntRes.ObjectId, OpenMode.ForWrite);

                // Get the body from the duct fitting.
                Autodesk.Aec.Modeler.Body bBase = me.Body;

                // setup a location to hold the new body.
                Autodesk.Aec.Modeler.Body bNew = null;

                // create two new bodies
                Autodesk.Aec.Modeler.Body b1 = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 5)), 2, 1.5, 10);
                Autodesk.Aec.Modeler.Body b2 = Autodesk.Aec.Modeler.Body.Sphere(new Point3d(0, 0, 5), 0.5, 10);

                // perform a bolean union via the plus operator... In this case we are unioining the two new bodys we created above.
                bNew = b1 + b2;

                // Now take the oginal body and subtract our new body.
                // bNew = bBase - bNew;
                bNew = bBase + bNew;
                

                // finally, since we are working on a copy, we need to assign the final body back to the mass element.
                //me.SetBody(bNew, true);
                me.Body.Combine(bNew);
                trans.Commit();
            }


        }

 

1 REPLY 1
Message 2 of 2
Keith.Brown
in reply to: Keith.Brown

I thought I would mention that I know that .net is capable of adding geometry programatically to a fitting.  I have seen the end result personally so that I know it works.  I know that 3D solids were used but I am just unable to figure it out.  Any help would be appreciated.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost