Create Imates on Workpoints

Create Imates on Workpoints

chris_bargent
Contributor Contributor
664 Views
2 Replies
Message 1 of 3

Create Imates on Workpoints

chris_bargent
Contributor
Contributor

Hi,

 

I'm working in Inventor 2012 and new to VBA and I'm gonna kick myself if there's a really easy answer to this. I've got 120+ WorkPoints on corresponding WorkAxes on an irregular pattern both horizontally and vertically. I'd like to Select all the WorkPoints and add a mate Imate then all the work axis and add an insert imate to ease placement of a part at each location within an assembly (this scenario crops up quite often).

 

I've been trying to use AddMateiMateDefinition but it doesn't seem to let me pass a WorkPoint to it, is it possible?

 

Many thanks

0 Likes
Accepted solutions (1)
665 Views
2 Replies
Replies (2)
Message 2 of 3

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

Create workpoint "MyPoint" and workaxis "MyAxis" and run this VBA sample.

It works for me.

Private Sub CreateiMateDefinitionSample()
    ' Set a reference to the active part document
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
    'some work axis
    Dim oAxis As WorkAxis
    Set oAxis = oCompDef.WorkAxes.Item("MyAxis")
    'some work point
    Dim oWP As WorkPoint
    Set oWP = oCompDef.WorkPoints.Item("MyPoint")

    ' Create a mate iMateDefinition on a work point
    Dim oMateiMateDefinition1 As MateiMateDefinition
    Set oMateiMateDefinition1 = oCompDef _
      .iMateDefinitions.AddMateiMateDefinition( _
          oWP, 0, , , "MatePoint")

    ' Create a mate iMateDefinition on a work axis
    Dim oMateiMateDefinition2 As MateiMateDefinition
    Set oMateiMateDefinition2 = oCompDef _
      .iMateDefinitions.AddMateiMateDefinition( _
          oAxis, 0, , , "MateAxis")
End Sub

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

chris_bargent
Contributor
Contributor

 

Excellent, many thanks. Works like a charm.

 

I can’t pretend to understand what was wrong with my code as although structured slightly differently it was doing the same thing (in my mind).

0 Likes