Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA - program which can steering model

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
aldik87
734 Views, 6 Replies

VBA - program which can steering model

Hello

 

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.

6 REPLIES 6
Message 2 of 7
aldik87
in reply to: aldik87

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.

Message 3 of 7
YuhanZhang
in reply to: aldik87

The API supports to drive constraint since Inventor 2012.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 4 of 7
elmecon
in reply to: YuhanZhang

Any ideas how to drive an assembly constraint from a vba macro?

 

Thanks in advance.

 

Mike.

Message 5 of 7
Vladimir.Ananyev
in reply to: elmecon

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

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 7
ekinsb
in reply to: elmecon


@elmecon 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

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7
Brett.G
in reply to: ekinsb

Thanks for that code example.  I do have a question regarding driving constraints in a larger assembly.  I'm trying to drive a set of two constraints in a larger assembly and can drive them just fine in a similar fashion to the example you provided.  However, the update method seems to take much longer than when I drive a the same constraint using the Drive functionality. 

 

Is there any way to speed up the Update method, or limit it to only update the two constraints I'm changing?  Thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report