Sample code for Creating assembly from the available parts

Sample code for Creating assembly from the available parts

2019mmp003
Contributor Contributor
330 Views
1 Reply
Message 1 of 2

Sample code for Creating assembly from the available parts

2019mmp003
Contributor
Contributor

Hello everyone. Hope you are doing good. I have created parts(hollow cylinders) and saved them in a folder, I want to make an assembly using those parts, Such that they must be placed one inside other concentrically. I want to place those parts into the assembly doc using place features and then add concentric constraint such that there top and bottom faces should also be at same level. If anyone could help me with the sample code it would be great. Thanks.

0 Likes
331 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

you can use this as a sample. run it in an assembly. it will add 2 parts. then you need to select to edges for the constraint. Then the constraint ismade.

Dim doc As AssemblyDocument = ThisDoc.Document
Dim otg As TransientGeometry = ThisApplication.TransientGeometry

Dim matrix As Matrix = otg.CreateMatrix()
Dim occ1 = doc.ComponentDefinition.Occurrences.Add("D:\forum\tube.ipt", matrix)
occ1.Grounded = True

matrix.SetTranslation(otg.CreateVector(150, 0, 0))
Dim occ2 = doc.ComponentDefinition.Occurrences.Add("D:\forum\tube2.ipt", matrix)

Dim edge1 As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select first edge")
Dim edge2 As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select second edge")

doc.ComponentDefinition.Constraints.AddInsertConstraint(edge1, edge2, False, 0.0)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes