Placing a part in an assembly with a macro

Placing a part in an assembly with a macro

Anonymous
Not applicable
494 Views
1 Reply
Message 1 of 2

Placing a part in an assembly with a macro

Anonymous
Not applicable

I have been working with macros basically making user forms to control the models. The program calls on a part that I use as an actuation template (its just a part with parameters that are then linked to the assembly contraints) then the macro will change the parameters and update the model.

 

What I need to do is to put in some code in the userforn initialize sub that gets the actuation template from the disk, for example: C:\Other Stuff\Actuation Template A.ipt. Then the macro places the part into the assembly. The userform then manipulates the actuation template (and the assembly model). Then when the userform is unloaded the part is deleted from the assembly.     Thanks for any advice you can offer.

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

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

Hope the following code could help a bit:

 

Sub test()


'create PartDocument
Dim oNewDoc As PartDocument
Set oNewDoc = ThisApplication.Documents.Add(kPartDocumentObject, "C:\Other Stuff\Actuation Template A.ipt", True)

Dim oM As matrix
Set oM = ThisApplication.TransientGeometry.CreateMatrix()


Dim oAssDoc As AssemblyDocument
Set oAssDoc = ThisApplication.activeDocument

Dim oOcc As ComponentOccurrence
Set oOcc = oAssDoc.ComponentDefinition.Occurrences.AddByComponentDefinition(oNewDoc.ComponentDefinition, oM) 


' to delete the part
' oOcc.Delete

End Sub

0 Likes