Author Topic: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.  (Read 3025 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
I need to try and get the Routing Preference for a conduit and a conduit fitting with C# and I am not having much luck.   I am able to obtain the routing preference for a duct and duct fitting using the following methods.


Code - C#: [Select]
  1. private string GetDuctRoutingPreferenceName(Member member)
  2. {
  3.  
  4.     if(member == null)
  5.     {
  6.         throw new ArgumentNullException("member", "Parameter cannot be null.");
  7.     }
  8.    
  9.     if(member.ObjectId.ObjectClass.Name != "AecbDbDuct")
  10.     {
  11.         throw new ArgumentException("Object is not a duct.", "member");
  12.     }
  13.    
  14.     var routingPreference = "*None*";
  15.        
  16.     using (Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  17.     {
  18.         var duct = new Duct();
  19.         duct = (Duct)member;
  20.         var objectId = duct.RoutingPreferenceId;
  21.                
  22.         if (objectId != ObjectId.Null)
  23.         {
  24.             var obj = transaction.GetObject(objectId, OpenMode.ForRead) as DuctPartCatalogPreferenceStyle;
  25.             routingPreference = obj.Name;
  26.             transaction.Commit();
  27.         }
  28.        
  29.         return routingPreference;
  30.     }
  31. }
  32.  
  33.  
  34.  
  35.  
  36. private string GetDuctFittingRoutingPreferenceName(Member member)
  37. {
  38.  
  39.     if(member == null)
  40.     {
  41.         throw new ArgumentNullException("member", "Parameter cannot be null.");
  42.     }
  43.    
  44.     if(member.ObjectId.ObjectClass.Name != "AecbDbDuctFitting")
  45.     {
  46.         throw new ArgumentException("Object is not a duct fitting.", "member");
  47.     }
  48.    
  49.     var routingPreference = "*None*";
  50.        
  51.     using (Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  52.     {
  53.         var ductFitting = new DuctFitting();
  54.         ductFitting = (DuctFitting)member;
  55.         var objectId = ductFitting.RoutingPreferenceId;
  56.                
  57.         if (objectId != ObjectId.Null)
  58.         {
  59.             var obj = transaction.GetObject(objectId, OpenMode.ForRead) as DuctPartCatalogPreferenceStyle;
  60.             routingPreference = obj.Name;
  61.             transaction.Commit();
  62.         }
  63.        
  64.         return routingPreference;
  65.     }
  66. }


Unfortunately duct does not have the same methods available.  For some reason Autodesk did routing preferences for duct and pipe differently and it looks like they don't have an api for get the routing preference of a conduit or cable tray.  Has anyone else been successful in doing this?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #1 on: July 18, 2014, 07:01:57 PM »
Seems like you're pretty alone with this MEP stuff but it sounds really neat.  We were discussing software the other day and they're hesitant to move electrical to a software package because they do so many brownfield projects here.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #2 on: July 19, 2014, 08:58:16 AM »
Not alot of people out there developing for AutoCAD MEP.  I know that JeffH has done some development for MEP in the past and MexicanCustard currently works with MEP but besides that there are not many out there.  The company I work for actively develops software for MEP but I am not one of the professional programmers.  I am just the little guy in the corner that does this as a hobby.


The routing preference is not in the extension dictionary nor in the XData of the part.  I do see using MgbDbg Snoop that there is a reference on the Conduit to the PartCatalogPreferenceDefinition.  I just don't understand how to link the two together once i have the conduit object.  Basically there is a hard pointer from the Conduit object to the routing preference but nothing in the API to link them.


Is there anything that can be done using pure .net?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

JONTHEPOPE

  • Guest
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #3 on: July 19, 2014, 03:41:15 PM »
Hi Keith ,

I worked with MEP a few years ago but it has been discontinued in my office to my dismay.
I don't know how to access the routing preference for conduit/cable tray with .net but I wish I did.
You could try the template API if there is one or I believe the functionality for electrical starts with the panel schedule. Sorry I can't be of more help.

Could you pleas explain why your first string has two arguments
Code: [Select]
(Member member)I have not seen this done before.
Do the two Strings work together inside a click event?
Is Member just a named variable?
So I can have One class with two Methods?


WILL HATCH

  • Bull Frog
  • Posts: 450
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #4 on: July 20, 2014, 12:28:30 AM »
The first declares the type and the second declares the variable name. 
C starts a variable declaration with type and variable name, rather than the variable name As type in VB

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #5 on: July 20, 2014, 08:04:40 AM »
What also might be confusing is that c# is a case-sensitive language.  Member, member, mEmber, meMber, etc are all distinct and different variable names.  Most of them are not good choices however.  Usually when I write methods like the ones above I will almost always use a variable name that mimics the Type name except for the case of the first letter.  For me it makes it more readable.  Others might disagree but since I am the only one that programs and maintains my code i prefer to do it this way.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #6 on: July 20, 2014, 05:05:00 PM »
What also might be confusing is that c# is a case-sensitive language.  Member, member, mEmber, meMber, etc are all distinct and different variable names.  Most of them are not good choices however.  Usually when I write methods like the ones above I will almost always use a variable name that mimics the Type name except for the case of the first letter.  For me it makes it more readable.  Others might disagree but since I am the only one that programs and maintains my code i prefer to do it this way.


Agreed! within simple routines like that type names are great variable names.  I usually only depart if I wish to say something about the object that doesn't require the effort of adding the comments to show up in the intellisense tooltip when coding.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: AutoCAD MEP: Get Conduit and Conduit Fitting Routing Preference.
« Reply #7 on: July 21, 2014, 04:46:12 PM »
That's when named arguments come in handy for reading code.

This
Code - C#: [Select]
  1. CalculateBMI(123, 64);
  2.  
vs
Code - C#: [Select]
  1. CalculateBMI(weight: 123, height: 64);
  2.  

http://msdn.microsoft.com/en-us/library/dd264739.aspx