Creating subassembly using .NET

Creating subassembly using .NET

Anonymous
Not applicable
3,562 Views
7 Replies
Message 1 of 8

Creating subassembly using .NET

Anonymous
Not applicable

Is it possible to create subassembly from C3D Stock Subassemblies.dll programmatically using .NET?
I need call procedure (BasicLane for example), set all input parameters and create subassembly in drawing.

0 Likes
Accepted solutions (2)
3,563 Views
7 Replies
Replies (7)
Message 2 of 8

Jeff_M
Consultant
Consultant

Yes. The source code for the Stock Subassemblies is in the C:\Program Files\Autodesk\Autodesk AutoCAD Civil 3D 2014\Sample\Civil 3D API\C3DStockSubAssemblies folder.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 8

Anonymous
Not applicable
Yes, I know it but I need call procedure of this DLL from another DLL.
0 Likes
Message 4 of 8

michael_robertson
Collaborator
Collaborator

Alex,

Not sure exactly what you are asking:

> Create a new subassembly

> Use a stock subassembly within a custom subassembly

> Programmatically create an assembly using stock subassembly

 

What version of C3D are you using? (the answer may vary depending on version)

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes
Message 5 of 8

Anonymous
Not applicable
I need programmatically create new assembly using stock subassembly.
C3D2014
VB.NET 2010 - just in case 🙂
0 Likes
Message 6 of 8

michael_robertson
Collaborator
Collaborator
Accepted solution

I haven't done this myself but I know it is possible from software we had written for us.

 

Here's the methods:

Import stock subassemly:

http://docs.autodesk.com/CIV3D/2014/ENU/API_Reference_Guide/html/648aeb2b-8729-3cc2-beb6-0a2ce6f24b8...

 

Add subassembly to assembly:

http://docs.autodesk.com/CIV3D/2014/ENU/API_Reference_Guide/html/73cadec3-9dee-8246-fdf8-652428c9ef2...

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes
Message 7 of 8

Anonymous
Not applicable
Accepted solution

It's awesome - it really working! Smiley Very Happy
Here working test routine:

 

        Dim a_CivilDoc As CivilDocument
        a_CivilDoc = CivilApplication.ActiveDocument
 
        Dim saname As String = "C:\Documents and Settings\All Users\Application Data\Autodesk\C3D 2010\rus\C3DStockSubassemblies.dll"
        Dim classname As String = "Subassembly.BasicLane"
        Dim location As New Autodesk.AutoCAD.Geometry.Point3d(000)
        Dim location2 As New Autodesk.AutoCAD.Geometry.Point3d(10, -0.20)
 
        Dim q_SubassemblyId As ObjectId
        q_SubassemblyId = a_CivilDoc.SubassemblyCollection.ImportStockSubassembly(saname, classname, location)
 
        Dim q_SubassemblyId2 As ObjectId
        q_SubassemblyId2 = a_CivilDoc.SubassemblyCollection.ImportStockSubassembly(saname, classname, location2)
 
        Dim q_Subassembly As Subassembly
        Dim q_Subassembly2 As Subassembly
        Dim q_Assembly As Assembly
 
        Using a_Transaction As Transaction = _
            HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
 
            q_Subassembly = a_Transaction.GetObject(q_SubassemblyId, OpenMode.ForWrite)
            q_Subassembly2 = a_Transaction.GetObject(q_SubassemblyId2, OpenMode.ForWrite)
 
            Dim q_Parameters As ParamDoubleCollection
            q_Parameters = q_Subassembly.ParamsDouble
 
            For i = 0 To q_Parameters.Count - 1
                If q_Parameters(i).DisplayName = "509" Then
                    q_Parameters(i).Value = 5
                End If
            Next
 
            q_Assembly = a_Transaction.GetObject(a_CivilDoc.AssemblyCollection(0), OpenMode.ForWrite)
            q_Assembly.AddSubassembly(q_Subassembly.Id)
            q_Assembly.InsertSubassemblyAfter(q_Subassembly2.Id, q_Subassembly.Points(3))
 
            a_Transaction.Commit()
 
        End Using

 And result:

Assambly

 

Thanks a lot!

0 Likes
Message 8 of 8

michael_robertson
Collaborator
Collaborator

Thanks for sharing your code, this is something we will probably doing pretty soon.

 

Mike

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes