AutoCAD Architecture Customization

AutoCAD Architecture Customization

Reply
*Expert Elite*
1,274 Posts
108 Kudos
Registered: ‎03-13-2008
Post 1 of 2

Programatically add geometry to a duct fitting

214 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)
                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();
            }


        }

 


Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013
────────────────────────────────────
⁞|⁞ Please use Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos as appropriate. Thank you!
*Expert Elite*
1,274 Posts
108 Kudos
Registered: ‎03-13-2008
Post 2 of 2

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
────────────────────────────────────
⁞|⁞ Please use Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos as appropriate. Thank you!
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!