Inventor Customization

Inventor Customization

Reply
New Member
aldik87
Posts: 2
Registered: ‎03-16-2011
Message 1 of 6 (369 Views)
Accepted Solution

VBA - program which can steering model

369 Views, 5 Replies
03-16-2011 02:12 PM

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.


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

 

New Member
aldik87
Posts: 2
Registered: ‎03-16-2011
Message 2 of 6 (328 Views)

Re: VBA - program which can steering model

03-21-2011 09:36 AM 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.

Employee
yuhanzhang
Posts: 480
Registered: ‎01-06-2009
Message 3 of 6 (307 Views)

Re: VBA - program which can steering model

03-22-2011 07:29 PM in reply to: aldik87

The API supports to drive constraint since Inventor 2012.



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

New Member
elmecon
Posts: 1
Registered: ‎07-12-2012
Message 4 of 6 (224 Views)

Re: VBA - program which can steering model

11-20-2012 08:56 AM in reply to: yuhanzhang

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

 

Thanks in advance.

 

Mike.

ADN Support Specialist
Vladimir.Ananyev
Posts: 531
Registered: ‎08-14-2012
Message 5 of 6 (189 Views)

Re: VBA - program which can steering model

11-30-2012 04:10 AM 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

ADN Support Specialist
ekinsb
Posts: 351
Registered: ‎07-21-2006
Message 6 of 6 (163 Views)

Re: VBA - program which can steering model

12-11-2012 05:19 PM 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
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.