- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning,
I have this macro, which automatically creates a constraint between the axis Z of the assembly and the axis Z of the selected part.
Sub Vincola_AsseZ()
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oComp As ComponentOccurrence
' Get the XY plane from each occurrence. This goes to the
' component definition of the part to get this information.
' This is the same as accessing the part document directly.
' The work plane obtained is in the context of the part,
' not the assembly.
Dim oCompPlane1 As WorkPlane
Dim oCompAxisZ As WorkAxis
' set the axis Z of the active assembly
Dim AsmAxisZ As WorkAxis
Set AsmAxisZ = oAsmCompDef.WorkAxes.Item(3)
selezione:
'reference to the selected dimension
Set oComp = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Seleziona il componente")
'exit sub if is nothing (Esc)
If oComp Is Nothing Then Exit Sub
Set oCompAxisZ = oComp.Definition.WorkAxes.Item(3)
' Because we need the work plane in the context of the assembly
' we need to create proxies for the work planes. The proxies
' represent the work planes in the context of the assembly.
Dim oAsmAxisZ As WorkAxisProxy
Call oComp.CreateGeometryProxy(oCompAxisZ, oAsmAxisZ)
' Create the constraint using the work plane proxies.
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmAxisZ, AsmAxisZ, 0) ' .AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)
'loop selection
GoTo selezione
End Sub
I would like to automatically add a second constraint: angle constrain between the axis Y of the assembly and the YZ plane of the same selected part.
I've tried by myself, but without success...
...does anyone can help me?
Many thanks
Solved! Go to Solution.