Inventor Customization

Reply
Valued Mentor
Posts: 431
Registered: ‎11-24-2003
Message 1 of 4 (185 Views)

Getting a graphically selected occurrence of a rectangular pattern feature?

185 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
Posts: 419
Registered: ‎08-14-2012
Message 2 of 4 (154 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
Posts: 431
Registered: ‎11-24-2003
Message 3 of 4 (145 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
Posts: 419
Registered: ‎08-14-2012
Message 4 of 4 (136 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube