How to keep selectset contain ?

How to keep selectset contain ?

TONELLAL
Collaborator Collaborator
435 Views
3 Replies
Message 1 of 4

How to keep selectset contain ?

TONELLAL
Collaborator
Collaborator

Hello,

I trying to create a macro modifying several DesignViews :

-select parts to hide in several views

-for all unlocked views, hide selected parts

 

Here's the basic code :

Sub modif_vues()

Dim oDoc As AssemblyDocument
Dim oViews As DesignViewRepresentations
Dim oView As DesignViewRepresentation
Dim oSelectSet As SelectSet
Dim oObj As Object

Set oDoc = ThisApplication.ActiveDocument
Set oViews = oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations

Set oSelectSet = oDoc.SelectSet
For Each oView In oViews
    If oView.Locked = False Then
        Call oView.Activate
        For Each oObj In oSelectSet
                oObj.Visible = False
        Next oObj
    End If
Next oView

End Sub

The problem is when the code evaluate the red line, oSelectset is cleared... Where is the problem ?

 

0 Likes
436 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

hi the problem is not the red line but the line before that. when you switch from DesignView your selection gets undone. what you can do is save the selection list in a new list. Then use that list to loop over the selection. something like this:

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oViews As DesignViewRepresentations = oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations
Dim oSelectSet As SelectSet = oDoc.SelectSet
Dim inVisableList As List(Of Object) = New List(Of Object)()
For Each item As Object In oSelectSet
    inVisableList.Add(item)
Next

For Each oView As DesignViewRepresentation In oViews
    If oView.Locked = False Then
        oView.Activate()

        For Each oObj As Object In inVisableList
            oObj.Visible = False
        Next oObj
    End If
Next oView

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

TONELLAL
Collaborator
Collaborator

Hi,

Your solution is ok, but in my code the selection set is saved in oSelectSet, precisely to keep it when the current selection set is cleared... So, why oSelectSet, which is supposed to be independent from oDoc.selectSet, is cleared too ? It seems oDoc.selectSet and oSelectset have the same reference.

0 Likes
Message 4 of 4

JelteDeJong
Mentor
Mentor

the variable "oSelectSet" contains a refrence to the object "oDoc.SelectSet". That object contains refrences to all objects that you selected but can change (for example when you switch DesignView)  I this case its importend to see that the refrence is to the object that contains refrences to the selected object. What you need is refrences to the selected objects. That is what i did in my code. I made explicit refrences to the selected objects.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes