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: 

Proxy of a workplane inside a pattern inside a part inside an assembly

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
oransen
856 Views, 5 Replies

Proxy of a workplane inside a pattern inside a part inside an assembly

There are many examples of creating rectangular patterns, but not many, if any, of interrogating existing patterns.

 

I have attached the files and a screenshot of a rectangular part inside an assembly. The part contains a rectangular pattern of holes and workplanes.

 

My question is how do I get hold of each proxy of the workplane in the pattern?

 

In other words I don't know what to put in the for loop at the end of this code fragment:

 

        If _invApp.Documents.Count = 0 Then
            MsgBox("Need to open an the assembly document")
            Return
        End If

        If _invApp.ActiveDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
            MsgBox("Need to have an Assembly document active")
            Return
        End If

        Dim asmDoc As AssemblyDocument
        asmDoc = _invApp.ActiveDocument

        Dim asmDef As AssemblyComponentDefinition
        asmDef = asmDoc.ComponentDefinition

        Dim occurrences As ComponentOccurrences
        occurrences = asmDef.Occurrences

        Dim partOcc As ComponentOccurrence
        ' partOcc = occurrences.ItemByName("Block-with-hole-pattern")
        partOcc = occurrences.Item(1)

        Dim pippo As PartComponentDefinition
        pippo = partOcc.Definition

        Dim features As PartFeatures
        features = pippo.Features

        Dim RecFeatures As RectangularPatternFeatures
        RecFeatures = features.RectangularPatternFeatures

        Dim RecPattern As RectangularPatternFeature
        RecPattern = RecFeatures.Item(1)

        Dim Xparam As Parameter
        Xparam = RecPattern.XCount
        Debug.Print("This pattern has " & Xparam.Value & " x elements")

        Dim i As Integer, j As Integer
        For i = 1 To Xparam.Value
            Debug.Print(i & "   ")

            ' How to get hold of the proxy for the workplane in the pattern source?

        Next i

 

The fragment assumes you've opened the assembly attached.

5 REPLIES 5
Message 2 of 6
philippe.leefsma
in reply to: oransen

Hi

 

it's pretty straightforward to get a better idea about how things are structured under the APi by writting some simple VBA code as follow and analyzing the live objects using the VBA debugger.

 

Public Sub pattern()

    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim pattern As RectangularPatternFeature
    Set pattern = doc.ComponentDefinition.Features.RectangularPatternFeatures(1)
    

End Sub

 

 

From the video I recorded below, you can deduce that the patterned workplanes are accessible from "PatternElements.Item(idx).ResultFeatures" collection.

 

The video is watchable here

 

NB: The first pattern element is empty because it is the patterned feature itself.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 6
oransen
in reply to: oransen

My question was about getting the proxies of workplanes in patterns inside parts inside assemblies.

 

I'll do as you suggest, but some documentation would be helpful.

 

Message 4 of 6
Vladimir.Ananyev
in reply to: oransen

Inventor API Help contains the overview article on proxies:

Proxies.png

 

In the following vba sample  WorkPlaneProxy objects are created using ComponentOccurrence.CreateGeometryProxy(...)  method.

 

Sub ExplorePatternInComponent()

  Dim oAsmDoc As AssemblyDocument
  Set oAsmDoc = ThisApplication.ActiveDocument
  Dim oAsmDef As AssemblyComponentDefinition
  Set oAsmDef = oAsmDoc.ComponentDefinition
  Dim oOccs As ComponentOccurrences
  Set oOccs = oAsmDef.Occurrences
  Dim oOcc As ComponentOccurrence
  Set oOcc = oOccs.ItemByName("Block-with-hole-pattern:1")
  
  Dim oDef As PartComponentDefinition
  Set oDef = oOcc.Definition
  
  Dim oFeatures As PartFeatures
  Set oFeatures = oDef.features
  
  Dim RecFeatures As RectangularPatternFeatures
  Set RecFeatures = oFeatures.RectangularPatternFeatures
  
  Dim RecPattern As RectangularPatternFeature
  Set RecPattern = RecFeatures.Item(1)
  
  Dim Nx As Integer, Ny As Integer
  
  Dim Xparam As Parameter
  Set Xparam = RecPattern.XCount
  If Not Xparam Is Nothing Then
    Nx = Xparam.value
  Else
    Nx = 1
  End If
  
  Dim Yparam As Parameter
  Set Yparam = RecPattern.YCount
  If Not Yparam Is Nothing Then
    Ny = Yparam.value
  Else
    Ny = 1
  End If

  Debug.Print ("This pattern has " & Nx & " x " & Ny & " elements")

  Dim oPatternElements As FeaturePatternElements
  Set oPatternElements = RecPattern.PatternElements
  Dim oElt As FeaturePatternElement

  Dim sset As SelectSet
  Set sset = oAsmDoc.SelectSet
  
  Dim i As Integer
  
  For i = 2 To Nx
    Set oElt = oPatternElements.Item(i)
'    Debug.Print oElt.ResultFeatures.Item(1).Name

    'get work plane object (assume it is the first object 
    'in the collection ResultFeatures)
    Dim oWP As WorkPlane
    Set oWP = oElt.ResultFeatures.Item(1)
    'Debug.Print oWP.Name

    'get proxy object
    Dim oWpProxy As WorkPlaneProxy
    Set oWpProxy = Nothing
    Call oOcc.CreateGeometryProxy(oWP, oWpProxy)

    'now you can do something useful with oWpProxy
    Call sset.Select(oWpProxy)
  Next     
  Beep    
End Sub

 cheers


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 6
oransen
in reply to: Vladimir.Ananyev

Magic, thanks! The VB worked, and it took me some time to convert to C++, but I got there in the end.

 

I'd understood creating proxies, but did not understand ResultFeatures...

 

Message 6 of 6
Vladimir.Ananyev
in reply to: oransen

ResultFeatures is the collection of entities that were included in the pattern operation.  In your model that could be workplane + workaxis in every pattern element.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report