AutoCAD Architecture Customization

*Expert Elite*
Posts: 943
Registered: ‎03-13-2008
Message 1 of 2 (175 Views)

Programatically add geometry to a duct fitting

175 Views, 1 Replies
01-30-2013 05:48 PM

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)

            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);



Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013
*Expert Elite*
Posts: 943
Registered: ‎03-13-2008
Message 2 of 2 (174 Views)

Re: Programatically add geometry to a duct fitting

01-30-2013 05:49 PM 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.

Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community