AutoCAD Civil 3D Customization

AutoCAD Civil 3D Customization

Reply
Distinguished Contributor
joshuamodglin
Posts: 147
Registered: ‎08-15-2007
Message 1 of 4 (228 Views)
Accepted Solution

Finding out which Part Family the pipe is from

228 Views, 3 Replies
10-02-2012 02:41 PM

I am updating a system which lists the sizes available for a specific part. What the client is looking for is to only show the sizes that have been defined in the parts list for the family that the part currently is associated with. This is where I am having difficulty. I cannot seem to locate what family the pipe is from.

 

Does anyone know of a .Net (I really would like to avoid COM if at all possible) to know which family the pipe belongs to?

 

Thanks,

Josh Modglin
Advanced Technologies Solutions Logo

The PartFamily property is not exposed in .NET, as I'm sure you've found. But, you can get the PartFamily via late-binding so no COM references are needed.

 [CommandMethod("GetPartFamilyTest")]
public void getpartfamily()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions entOpts = new PromptEntityOptions("Select part: ");
entOpts.SetRejectMessage("..Not a network part, try again.");
entOpts.AddAllowedClass(typeof(PipeDb.Part), false);
PromptEntityResult res = ed.GetEntity(entOpts);
if (res.Status != PromptStatus.OK)
return;
using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
PipeDb.Part part = (PipeDb.Part)tr.GetObject(res.ObjectId, OpenMode.ForRead);
object acadpart = part.AcadObject;
object prtfam = acadpart.GetType().InvokeMember("PartFamily", System.Reflection.BindingFlags.GetProperty, null, acadpart, new object[0]);
ObjectId prtfamId = DBObject.FromAcadObject(prtfam);
PipeDb.Styles.PartFamily partFam = (PipeDb.Styles.PartFamily)tr.GetObject(prtfamId, OpenMode.ForRead);
tr.Commit();
}
}

 

*Expert Elite*
Jeff_M
Posts: 4,431
Registered: ‎07-22-2003
Message 2 of 4 (218 Views)

Re: Finding out which Part Family the pipe is from

10-03-2012 12:32 PM in reply to: joshuamodglin

The PartFamily property is not exposed in .NET, as I'm sure you've found. But, you can get the PartFamily via late-binding so no COM references are needed.

        [CommandMethod("GetPartFamilyTest")]
        public void getpartfamily()
        {
                        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions entOpts = new PromptEntityOptions("Select part: ");
            entOpts.SetRejectMessage("..Not a network part, try again.");
            entOpts.AddAllowedClass(typeof(PipeDb.Part), false);
            PromptEntityResult res = ed.GetEntity(entOpts);
            if (res.Status != PromptStatus.OK)
                return;
            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                PipeDb.Part part = (PipeDb.Part)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                object acadpart = part.AcadObject;
                object prtfam = acadpart.GetType().InvokeMember("PartFamily", System.Reflection.BindingFlags.GetProperty, null, acadpart, new object[0]);
                ObjectId prtfamId = DBObject.FromAcadObject(prtfam);
                PipeDb.Styles.PartFamily partFam = (PipeDb.Styles.PartFamily)tr.GetObject(prtfamId, OpenMode.ForRead);
                tr.Commit();
            }
        }

 

Jeff_M, also a frequent Swamper
Distinguished Contributor
joshuamodglin
Posts: 147
Registered: ‎08-15-2007
Message 3 of 4 (214 Views)

Re: Finding out which Part Family the pipe is from

10-03-2012 03:11 PM in reply to: Jeff_M

A concise, simple, and ingenious way to do it. I am running in between projects at the moment and won't probably be able to test the code before Friday but it looks pretty straightforward and will mark it as solution on Friday, once tested.

 

Impressive work Jeff! Thanks for sharing.

 

Josh Modglin
Advanced Technologies Solutions Logo
Distinguished Contributor
joshuamodglin
Posts: 147
Registered: ‎08-15-2007
Message 4 of 4 (205 Views)

Re: Finding out which Part Family the pipe is from

10-05-2012 01:01 PM in reply to: Jeff_M

Tested, proven, works. 

 

Thanks again Jeff.

Josh Modglin
Advanced Technologies Solutions Logo
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.