IDW: select all file occurences in current view

IDW: select all file occurences in current view

Anonymous
Not applicable
2,880 Views
7 Replies
Message 1 of 8

IDW: select all file occurences in current view

Anonymous
Not applicable

Hi,

I'm just wondering if it's possible to select all edges of one file in whole view. I want to move them to another layer.

 

What I need to do:

select all occurences/instances of one file in current view

select them as edges

move to another layer (blue) 😉

 

INV - all occurences.png

 

I have big assembly with many levels of subassemblies. All I need to select all hangers (some ipt files) and move them to another layer. I have dozens files to select in one view.. And dozen of views.

 

 

INV - all occurences - tree.png

 

Is it possible to to that with VBA or iLogic? What I was thinkin is to select one file and then hit the button "select other files with the same name in current drawing". Maybe something like this is already buildin but I couldn't find it.

0 Likes
Accepted solutions (1)
2,881 Views
7 Replies
Replies (7)
Message 2 of 8

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

Solution of the similar problem was discussed here:

http://forums.autodesk.com/t5/Inventor-Customization/add-Occurrences-to-the-Selection-in-drawing-mod...

3 main ideas should be mentiond.

1) you may find all occurrences for the given PartDocument
'find all occurrences for every part found
Dim oOccEnum As ComponentOccurrencesEnumerator
Set oOccEnum = oAssyDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc) 

2) Here is “magic” method that returns all drawing curves that were projected from the given component occurrence:
Dim oCurveUnum As DrawingCurvesEnumerator
Set oCurveUnum = oDrawView.DrawingCurves(oOcc) 

3) then you may move all found curves to some layer with appropriate style settings:
Sheet.ChangeLayer( Objects As ObjectCollection, Layer As Layer )

cheers


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks for showing the forum link, it was pretty much my case (couldn't find it before).

 

I don't understand one thing, why you are changing style:

oDrawView.ViewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle

 

I just commented it out (maybe I don't know that it is usefull) but then how to get back to previous state? Generally I have hiddenlines non-visible but not always.

 

 edit:

I was wondering if one upgrade could be done.

 

Search criteria in step 3: to select file from the drawing

 

I was trying:

'step 3
  'filter required docs
  Dim oRefDocs As DocumentsEnumerator
  Set oRefDocs = oAssyDoc.AllReferencedDocuments
  
  'Part Select
  Dim SelectedFile As PartDocument
   Set SelectedFile = ThisApplication.CommandManager _
        .Pick(kPartDefaultFilter, "Select a part to color.")
  
On error resume next Fname = SelectedFile.FullFileName Fname = Left(Fname, InStrRev(Fname, ".") - 1) ' ".ipt" cut Fname = Right(Fname, Len(Fname) - InStrRev(Fname, "\")) 'cut the front part If Len(Fname) = 0 Then Fname = InputBox("Give me search string", "File Name") If Len(Fname) = 0 Then Exit Sub End If Dim oDoc As Inventor.Document For Each oDoc In oRefDocs 'Criteria depends on your requirements: 'substring from filename, custom iProperty value, parameter value, etc. If InStr(oDoc.FullFileName, Fname) > 0 Then

 but I could't choose anything. If my selection fails I can input fila name from a keyboard but it's far more complicated..

what filter should I choose?

0 Likes
Message 4 of 8

Vladimir.Ananyev
Alumni
Alumni

I believe you should add step 0:  having drawing document active you should select some DrawingSegment.  Step 0 should return you PartDocument corresponding to the selected segment.  All the rest was already discussed - having the reference to the PartDocument you may find all its occurrences, then all their drawing curves, then move all curves to the desired layer.

 

Here is VBA sample to test Step 0:

 

Sub PickCurve()
 
  'Step 0:  find PartDocument from the selected curve segment
 
  ' Get a drawing curve segment selection from the user
  Dim oCS As DrawingCurveSegment
  Set oCS = ThisApplication.CommandManager.Pick( _
        SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick a drawing curve segment")
   
  If oCS Is Nothing Then
    MsgBox "Selection was cancelled"
    Beep
    End
  End If
 
  Dim oCurve As DrawingCurve
  Set oCurve = oCS.Parent
 
  Dim oEdge As Edge
  If TypeOf oCurve.ModelGeometry Is EdgeProxy Then
    ‘we have assembly document
    Set oEdge = oCurve.ModelGeometry.NativeObject
  Else
    ‘we have part document
    Set oEdge = oCurve.ModelGeometry
  End If
 
  Dim oBody As SurfaceBody
  Set oBody = oEdge.Parent
 
  Dim oDef As PartComponentDefinition
  Set oDef = oBody.Parent
 
  Dim oDoc As Inventor.PartDocument
  Set oDoc = oDef.Document
 
  'Step 1: now you may find all occurrences for the found PartDocument
 
  '...
 
  Beep
End Sub

  

Hope this could help you.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 8

Anonymous
Not applicable

Thanks. Now it's easier to pick the part.

Is it very tricky to change to part priority not curve proirity? It's more intuitive.

INV - part priority.png

 

And now, if I choose a curve, it has to be in one of the views. How can I skip view selecting?

 

 

0 Likes
Message 6 of 8

Vladimir.Ananyev
Alumni
Alumni

>>Is it very tricky to change to part priority not curve proirity? It's more intuitive.

It could be a bit tricky to implement the part priority selection in the drawing view context because there are no parts in the drawing view context – only drawing segments could be selected. 

But I believe it is possible to develop your own addin that implements customized interactive selection mode.  You may learn some ideas on interactive selection in the Inventor API Help that contains the overview “User Interaction”.  See the customization of the SelectEvents via the OnPreSelect event object.

 

>> ... if I choose a curve, it has to be in one of the views. How can I skip view selecting?

Could you please clarify your idea?  

You don’t need to select a drawing view explicitly.  But you can select a drawing curve only if you pick it inside some drawing view.   When you find the selected part you may process all the drawing curves projected from the occurrences of this part in all drawing views in the active sheet.

 

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 8

Anonymous
Not applicable

Please see the attached SUB.

When I run this Sub it ask me two times, in step 0 I must select the curve and later I must select proper view (I don't want to go trough all views).

0 Likes
Message 8 of 8

Vladimir.Ananyev
Alumni
Alumni

You don’t have to select the drawing view once you have already selected drawing curve segment.  This reference could be easily got from the drawing curve object:  
Selected DrawingCurveSegment => parent DrawingCurve => parent DrawingView

Dim oCurve As DrawingCurve
Set oCurve = oCS.Parent


Dim oDrawView As DrawingView
Set oDrawView = oCurve.Parent

 I’ve attached slightly updated code from your previous post.

 

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network