Author Topic: How to directly access a Civil 3D Assembly object?  (Read 330 times)

0 Members and 1 Guest are viewing this topic.

jh_dempsey

  • Mosquito
  • Posts: 6
How to directly access a Civil 3D Assembly object?
« on: March 21, 2018, 07:26:17 AM »
Hi All

Im producing a custom add on which requires me to access the data/variables stored within an Civil 3D assembly.
The code works on 3D Solids which have been produced from "Extract Corridor from Solids" tool.

I know the name of the assembly I wish to access as its provided in the property set the extract tool applies to the 3D solids.

I have already written the code to get the name of the assembly from the property set. Now I have this, how do I get hold of the Assembly object itself? (I guess I need a GetAssemblyFromName function!)

Thanks

Jeff_M

  • King Gator
  • Posts: 3916
  • C3D user & customizer
Re: How to directly access a Civil 3D Assembly object?
« Reply #1 on: March 21, 2018, 11:48:11 AM »
You will need to iterate through the corridor baselines then baseline regions. Each region has the AssemblyId property, get that object and compare the name.
Pseudo-code:
Code - C#: [Select]
  1. foreach(var baseline in corridor.Baselines)
  2.  {
  3.     foreach(var region in baseline.BaselineRegions)
  4.       {
  5.           var assbly = (Assembly)tr.GetObject(region.AssemblyId, OpenMode.ForRead);
  6.           if(assbly.Name == nametolookfor)
  7.              {
  8.                 //do what you need, if you need the actual values for the assembly in the corridor, use the AppliedAssemblies property for the region
  9.  

jh_dempsey

  • Mosquito
  • Posts: 6
Re: How to directly access a Civil 3D Assembly object?
« Reply #2 on: March 21, 2018, 11:59:56 AM »
I thought I might have to do this. But the same question now applies to the corridor.

To run your code, I need to run tr.getObject to select a corridor.
As I cant use any user input (ie selecting on screen or typing into the command line) how do I select the correct corridor?
I have the name of the corridor I require stored in a string.

Jeff_M

  • King Gator
  • Posts: 3916
  • C3D user & customizer
Re: How to directly access a Civil 3D Assembly object?
« Reply #3 on: March 21, 2018, 12:44:40 PM »
Code - C#: [Select]
  1.            var civDoc = CivilApplication.ActiveDocument;
  2.            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  3.            {
  4.                var corr = (Corridor)tr.GetObject(civDoc.CorridorCollection[nameofcorridor], OpenMode.ForRead);
  5.                foreach(Baseline bl in corr.Baselines)
  6.  
  7.  

jh_dempsey

  • Mosquito
  • Posts: 6
Re: How to directly access a Civil 3D Assembly object?
« Reply #4 on: March 22, 2018, 03:37:57 PM »
That worked :-) It was the civilDocument part I think I was missing.
I think I tried to access the CorridorCollection (and AssemblyCollection) from the standard AutoCAD Document object and obviously got nowhere.

Now knowing this, I do find it strange that i could then directly access an assembly object using civDoc.AssemblyCollection[nameOfAssembly] but once i had it, that object appears to have no way to see and access the subassemblies attached to it? As Jeff_M says above, the only way i seemed to be able to get to the parameters of a subassembly was going through the corridor hierarchy and extracting an AppliedSubassmbly object. Is this true, or have i missed something else in the documentation?

Jeff_M

  • King Gator
  • Posts: 3916
  • C3D user & customizer
Re: How to directly access a Civil 3D Assembly object?
« Reply #5 on: March 22, 2018, 04:29:16 PM »
Quote
or have i missed something else in the documentation?

Yes... :wink:

If all you need to know are the subassemblies of an assembly, and not how they are actually calculated in a corridor, the Assembly object has the Groups property. Subassemblies are Grouped together, such as right side and left side. Each AssemblyGroup has the GetSubassemblyIds() method

Jeff_M

  • King Gator
  • Posts: 3916
  • C3D user & customizer
Re: How to directly access a Civil 3D Assembly object?
« Reply #6 on: March 22, 2018, 04:32:18 PM »
Do you have the C3D .NET API documentation bookmarked? If not, you should :-)
http://docs.autodesk.com/CIV3D/2018/ENU/API_Reference_Guide/

You can substitute 2016, 2017, and, soon, 2019 for the 2018 for version specific docs.