I was created model of industrial robot with assembly and I need to create program in VBA, which can be used to steering robot arms in model for example used keyboard. Program have to include assembly too. I don't know what I should start do this... Please help me or show me some example with this. Thanks.
Solved! Go to Solution.
Ok maby other way... It possible to drive constraint in VBA??? If yes, my question is how can I do this??? I create 3 special move constraint, which let me sterring robots, and this can be good idea to drive constraint by program.
Activate an assembly with mate constraint "Plane" and run this VBA macro.
Please search Inventor API Help for DriveConstraintSettings object methods and properties.
Sub Test_DriveCOnstraint() Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition Set oDef = oDoc.ComponentDefinition Dim oCon As MateConstraint Set oCon = oDef.Constraints.Item("Plane") If oCon.DriveConstraintSettings.IsInitialized Then Dim oDS As DriveConstraintSettings Set oDS = oCon.DriveConstraintSettings With oDS .StartValue = "0 mm" .EndValue = "50 mm" .PauseDelay = 0.01 .GoToStart .PlayForward .PlayReverse End With Beep Else MsgBox "Doesn't initialized" End If End Sub
Any ideas how to drive an assembly constraint from a vba macro?
Thanks in advance.
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