@Anonymous wrote:
Any ideas how to drive an assembly constraint from a vba macro?
Thanks in advance.
Mike.
I think rather than using the "Drive Constraint" functionality you likely want to control them yourself because you'll need more control and may want to change more than one constraint at a time. You can do this by change the values of the parameters that the constraint depends on. This is essentiallly what the "Drive Constraint" command is doing too. Here's a simple example that will drive the two parameters "Angle" and "Distance".
Public Sub DriveParameters()
' Get the active assembly document.
Dim asmDoc As AssemblyDocument
Set asmDoc = ThisApplication.ActiveDocument
' Get the parameters object.
Dim params As Parameters
Set params = asmDoc.ComponentDefinition.Parameters
' Get the Distance and Angle parameters. This will fail
' if they don't exist.
Dim distParam As Parameter
Dim angleParam As Parameter
Set distParam = params.Item("Distance")
Set angleParam = params.Item("Angle")
' Calculate the distance and angle for each iteration.
Dim pi As Double
pi = Atn(1) * 4
Dim iterations As Integer
iterations = 50
Dim angleValue As Double
angleValue = (pi / 2) / 50
Dim distanceValue
distanceValue = 0.1
' Iterate over a certain number of iterations.
Dim i As Integer
For i = 1 To iterations
' Set the parameter values.
angleParam.Value = angleParam.Value + angleValue
distParam.Value = distParam.Value + distanceValue
' Update the document and the view to see each step.
asmDoc.Update
ThisApplication.ActiveView.Update
Next
End Sub