Toggle Isolate with VBA / iLogic

Toggle Isolate with VBA / iLogic

Anonymous
Not applicable
1,123 Views
7 Replies
Message 1 of 8

Toggle Isolate with VBA / iLogic

Anonymous
Not applicable

Hi.

 

I already know how to run "isolate" and "Undo Isolate" commands using VBA (check here), but how can I toggle it automatically? I want to create a button to call the macro. I need to know current isolate status to toggle it.

 

Any help is highly appreciated.

 

Thanks!

0 Likes
1,124 Views
7 Replies
Replies (7)
Message 2 of 8

pball
Mentor
Mentor

I looked around and it seems there is not a built in method for knowing if the isolate command has been ran. This means there probably isn't a simple way to toggle them.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 3 of 8

Anonymous
Not applicable

Thank you for the reply.

 

I thought that would be an easy request. With your reply, it looks impossible now 😞

 

BTW. How did you "looked around"? Is there any index of internal funcions?

 

And do you have any idea on how this request could be partially solved?

0 Likes
Message 4 of 8

pball
Mentor
Mentor

Searching Google and this forum is how I normally look around. With that searching I was only able to find examples where code set and then unset the isolation all in one operation. There was also a mention somewhere that there isn't a method for seeing if isolate was used. The good/bad news I just figured out is it seems Inventor remembers which parts were turned invisible by the isolate command and any parts that were already invisible, meaning Inventor must know that the isolate command was ran. That being said there doesn't seem to be a way to access that info.

 

You could always make an idea station post requesting an api method to know if isolate was used, then it would be easy to make a function toggle between isolate and undo isolate.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 5 of 8

Brett.G
Enthusiast
Enthusiast

Could you toggle the visibility of the component occurrence in the assembly or use that property as a substitute for the isolate command?  For example, if the component is visible then it may be isolated, if it is not visible then it may not be isolated.  This may get tricky if you have visible/hidden parts in your assembly.  It would be best if everything started as visible.  

 

Tweaking the "Assembly Ground Occurrences Example" in the API Reference you could do something like:

 

Dim oAsmCOmpDef as AssemblyComponentDefinition

set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

 

'Iterate through all occurrences and make them visible

Dim oOccurrence as ComponentOccurrence

For Each oOccurrence in oAsmCompDef.Occurrences

      oOccurrence.Visible = true

Next

 

This would make everything visible.  Then you could identify the occurrences you want to isolate, then run that loop again with oOccurrence.Visible = false for everything except the items you want to isolate.  

 

Basically, you're making your own isolate command.  It could be slow depending on the size of the assembly I imagine.

Message 6 of 8

Anonymous
Not applicable

Thank you for the reply.

 

Could you help me with text to make the request for the feature?

0 Likes
Message 7 of 8

Anonymous
Not applicable

That could be a nice start. If before the command is run, maybe it could save in a array the list of hidden parts?

0 Likes
Message 8 of 8

gerrardhickson
Collaborator
Collaborator

Reviving an old thread here I realise, but I had the need to "Isolate" from VBA today, so I wrote up some code that took care of it for me. It's pretty clunky so there's probably a neater way, but it did the job for me.

 

Basically, it creates a String Array of ComponentOccurrences in your select set, then iterate through ALL ComponentOccurrences, and hide them if they're not selected. This also works recursively - meaning it'll check occurrences within Assemblies that you may have if you selected components with the "PartPriority" selection filter.

 

Sub AddSelectedToViewRep()

Dim oAssy As AssemblyDocument
Dim oView As DesignViewRepresentation
Dim oSSet As SelectSet
Dim oSSetOcc As ComponentOccurrence
Dim SelectedNames() As String
Dim X1 As Integer

Set oAssy = ThisApplication.ActiveDocument
Set oSSet = oAssy.SelectSet
ReDim SelectedNames(1 To 1)
X1 = 1

For Each oSSetOcc In oSSet
    SelectedNames(X1) = oSSet(X1).Name
    X1 = X1 + 1
    ReDim Preserve SelectedNames(1 To X1)
    'creates a blank value in the last position of SelectedNames - ignoring that for now.
Next oSSetOcc

CheckOccurences oAssy.ComponentDefinition.Occurrences, SelectedNames()

Set oView = oAssy.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add
oAssy.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("Default").Activate

End Sub

Function CheckOccurences(Occurrences As ComponentOccurrences, OccurrenceName() As String)
Dim oCompOcc As ComponentOccurrence
Dim X2 As Integer
Dim bolSel As Boolean
Dim bolAssy As Boolean
bolSel = False

For Each oCompOcc In Occurrences
    
    If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
        'Stop
        bolAssy = True
        CheckOccurences oCompOcc.SubOccurrences, OccurrenceName()
    End If
    
    For X2 = 1 To UBound(OccurrenceName()) - 1
        'Debug.Print oCompOcc.Name & " - " & OccurrenceName(X2) '& " - " & SelectedNames(X2) = oCompOcc.Name
        If OccurrenceName(X2) = oCompOcc.Name Then
            bolSel = True
            GoTo Exitif
        Else
            bolSel = False
        End If
        
    Next X2
Exitif:
If bolSel = False And bolAssy = False Then oCompOcc.Visible = False
bolAssy = False

Next oCompOcc
End Function

 

Hope this helps.

 

 

0 Likes