Inventor Customization

Inventor Customization

Reply
Valued Mentor
Gruff
Posts: 440
Registered: ‎11-24-2003
Message 1 of 4 (206 Views)

Getting a graphically selected occurrence of a rectangular pattern feature?

206 Views, 3 Replies
10-03-2012 10:43 AM

We are using Inventor 2011 and I would like to make a small app that allows my users to graphically select one or more occurrences of a rectangular pattern feature  Then allow them to suppress them if desired.

 

I have determined the code to loop through the pattern occurrences and toggle suppression for any instance.

What I do not know how to do is determine which occurrences have been graphically selected.

 

At this time I am only concerned with round hole features.  (Perforated metal)

 

Any help here?

ADN Support Specialist
Vladimir.Ananyev
Posts: 531
Registered: ‎08-14-2012
Message 2 of 4 (175 Views)

Re: Getting a graphically selected occurrence of a rectangular pattern feature?

10-11-2012 01:27 AM in reply to: Gruff

You may use SelectSet object to access all objects that are currently selected using the Select command.  If object type is kFeaturePatternElementObject then you may treat it as pattern occurrence.  Its property Index gives you element position in the pattern.

Private Sub RectPatterns()
  
  Dim oDoc As PartDocument
  Set oDoc = ThisApplication.ActiveDocument
  
  Dim oDef As PartComponentDefinition
  Set oDef = oDoc.ComponentDefinition
  
  Dim oRP As RectangularPatternFeature
  Set oRP = oDef.Features.RectangularPatternFeatures.Item(1)
  
  Dim oSSet As SelectSet
  Set oSSet = oDoc.SelectSet
  If oSSet.Count = 0 Then Exit Sub
  
  Dim Entity As Object
  Set Entity = oSSet.Item(1)
  If Entity.Type <> ObjectTypeEnum.kFeaturePatternElementObject Then
    Beep
    MsgBox "Select feature pattern element"
    Exit Sub
  End If
  
  Dim oFPE As FeaturePatternElement
  Set oFPE = Entity
  If oFPE.Index > 1 Then
    oFPE.Suppressed = Not oFPE.Suppressed
  Else
    Beep
    MsgBox "Cannot suppress the first feature pattern element"
    Exit Sub
  End If
  
  oDoc.Update
End Sub

Hope this helps.

Cheers,

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Valued Mentor
Gruff
Posts: 440
Registered: ‎11-24-2003
Message 3 of 4 (166 Views)

Re: Getting a graphically selected occurrence of a rectangular pattern feature?

10-11-2012 10:33 AM in reply to: Vladimir.Ananyev

Vlad,

 

I think you misunderstand.

 

I do not want to select the pattern Feature Insances in the Browser Tree.

I am talking about selecting the Pattern instances in the graphics display.

 

Selected elements return Edge or Face when selected there..

 

I need to know how to get the pattern instance from the selected face or edge.

 

Trying to select the desired element from the browser tree is rediculously difficult as it is a 1D array.

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

Re: Getting a graphically selected occurrence of a rectangular pattern feature?

10-12-2012 03:49 AM in reply to: Gruff

This is also possible.  In the case of hole pattern you may select cylindric faces or cirlce edge (if you do it in the part context).  Function ElementIndexByFace returns the index of selected pattern element.  1 corresponds to the source hole.

 

Function ElementIndexByFace(ByVal oSelectedFace As Face) As Integer

  Dim oDef As PartComponentDefinition
  Set oDef = oSelectedFace.Parent.Parent

  If oSelectedFace.CreatedByFeature.Type _
        = ObjectTypeEnum.kHoleFeatureObject Then
    ElementIndexByFace = 1
    
  ElseIf oSelectedFace.CreatedByFeature.Type _
        = ObjectTypeEnum.kRectangularPatternFeatureObject Then
    
    Dim oRP As RectangularPatternFeature
    Set oRP = oSelectedFace.CreatedByFeature
    Dim oFace As Face
    Dim i As Integer
    Dim oFPE As FeaturePatternElement
    For i = 2 To oRP.PatternElements.Count
      Set oFPE = oRP.PatternElements.Item(i)
      Set oFace = oFPE.Faces.Item(1)
      If oSelectedFace Is oFace Then
        ElementIndexByFace = i
        Exit Function
      End If
    Next
  Else
    ElementIndexByFace = -1
  End If
End Function 'ElementIndexByFace


Private Sub PatternElementByFace()

  Dim oDoc As PartDocument
  Set oDoc = ThisApplication.ActiveDocument
  
  Dim SSET As SelectSet
  Set SSET = oDoc.SelectSet
  
  If SSET.Count = 0 Then
    Call MsgBox("Select cylindric face in pattern element")
    Exit Sub
  End If
  
  'no error checking for brevity
  Dim oSelectedFace As Face
  Set oSelectedFace = SSET.Item(1)
  
  Dim Index As Integer
  Index = ElementIndexByFace(oSelectedFace)
  
  If Index > 0 Then
    Debug.Print "Element  #" & Index
  Else
    MsgBox "Failed to find pattern element index."
  End If

End Sub 'PatternElementByFace




Private Sub PatternElementByEdge()
  'no error checking for brevity
  
  Dim oDoc As PartDocument
  Set oDoc = ThisApplication.ActiveDocument  
  Dim SSET As SelectSet
  Set SSET = oDoc.SelectSet  
  If SSET.Count = 0 Then
    Call MsgBox("Select circle edge in pattern element")
    Exit Sub
  End If    
  Dim oSelectedEdge As Edge
  Set oSelectedEdge = SSET.Item(1)
  
  'verify GeometryType - should be circle curve
  If oSelectedEdge.GeometryType <> CurveTypeEnum.kCircleCurve Then
    Call MsgBox("Select circle edge in pattern element")
    Exit Sub
  End If

  Dim Index As Integer
  Index = 0  
  Dim oFace As Face
  For Each oFace In oSelectedEdge.Faces
    If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
      Index = ElementIndexByFace(oFace)
    End If
  Next  
  If Index > 0 Then
    Debug.Print Index
  Else
    MsgBox "Failed to find pattern element index."
  End If
End Sub 'PatternElementByEdge

In assembly context SelectSet returns corresponding proxy objects (FaceProxy, EdgeProxy, etc.). In this case you should use NativeObject property to get object in the context of definition (e.g., Part Document)..

 

 Please fill free to modify this code to satisfy your particular requirements. 

Hope this helps.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

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.