SelectMultiple fail

SelectMultiple fail

sebastien.forman
Advocate Advocate
416 Views
2 Replies
Message 1 of 3

SelectMultiple fail

sebastien.forman
Advocate
Advocate

Hello all,

 

I try to make a script who find and select in panel, all part who don't have body.

 

I have find this code, but last line "selectmultiple" doesn't work.

 

Someone can tell me why please?

 

Thank you very much

 

Public Sub selectAllNoBody()
Dim ocPartDocs As ObjectCollection
Set ocPartDocs = ThisApplication.TransientObjects.CreateObjectCollection
For Each obj In ThisApplication.ActiveDocument.AllReferencedDocuments
   If TypeOf obj Is PartDocument Then
        Dim oPartdoc As PartDocument
        Set oPartdoc = obj
        If oPartdoc.ComponentDefinition.MassProperties.Volume = 0 Then
              ocPartDocs.Add oPartdoc
              Debug.Print oPartdoc.FullDocumentName
              'ThisApplication.ActiveDocument.SelectSet.Select oPartdoc
        End If
   End If
Next

Call ThisApplication.ActiveDocument.SelectSet.SelectMultiple(ocPartDocs)
End Sub
0 Likes
Accepted solutions (1)
417 Views
2 Replies
Replies (2)
Message 2 of 3

AlexFielder
Advisor
Advisor
Accepted solution

On reading this page, I would assume the same applies for SelectMultiple:

2019-03-12 10_56_04-SelectSet.Select Method _ Search _ Autodesk Knowledge Network.png

Option Explicit

Public Sub selectAllNoBody()
If Not TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then Exit Sub
Dim assyDoc As AssemblyDocument
Set assyDoc = ThisApplication.ActiveDocument
Dim ocPartDocs As ObjectCollection
Set ocPartDocs = ThisApplication.TransientObjects.CreateObjectCollection
Dim obj As Object
For Each obj In ThisApplication.ActiveDocument.AllReferencedDocuments
   If TypeOf obj Is PartDocument Then
        Dim oPartdoc As PartDocument
        Set oPartdoc = obj
        If oPartdoc.ComponentDefinition.MassProperties.Volume = 0 Then
              ocPartDocs.Add oPartdoc
              Debug.Print oPartdoc.FullDocumentName
        End If
   End If
Next

Dim ocPartOccurrences As ObjectCollection
Set ocPartOccurrences = ThisApplication.TransientObjects.CreateObjectCollection

Dim AssyDef As AssemblyComponentDefinition
Set AssyDef = assyDoc.ComponentDefinition

Dim partOcc As ComponentOccurrence
For i = 1 To ocPartDocs.Count
    For Each partOcc In AssyDef.Occurrences
        If partOcc.Definition.Document = ocPartDocs.Item(i) Then
            ocPartOccurrences.Add partOcc
        End If
    Next
Next i

Call assyDoc.SelectSet.SelectMultiple(ocPartOccurrences)
End Sub

There may be a more efficient approach than the above, but the selection method works at least.

 

I have an assembly (Inventor 2019.3 format) with several occurrences that according to the code ^ have zero volume, which is incorrect as the do have volume values.

Message 3 of 3

sebastien.forman
Advocate
Advocate

Hello Alex,

 

Thank you for your help, that give me the good way for my script,

 

Here is my last code with your corrections:

Public Sub selectAllNoBody()
If Not TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then Exit Sub
Dim adActiveDoc As AssemblyDocument
Set adActiveDoc = ThisApplication.ActiveDocument
Dim ocPartDocs As ObjectCollection
Set ocPartDocs = ThisApplication.TransientObjects.CreateObjectCollection
Dim obj As Object
For Each obj In adActiveDoc.ComponentDefinition.Occurrences
   If TypeOf obj Is ComponentOccurrence Then
        Dim oPartdoc As ComponentOccurrence
        Set oPartdoc = obj
        If oPartdoc.MassProperties.Volume = 0 Then
              ocPartDocs.Add oPartdoc
              Debug.Print oPartdoc.name
        End If
   End If
Next

Call adActiveDoc.SelectSet.SelectMultiple(ocPartDocs)
End Sub

Have a nice day

0 Likes