Reply

SelectSet Objects

Hello,

I trying to create a macro where:
- I create a query
- Objects selected by the query need to take from oAsm.SelectSet and put them into my variable iRefObj (for using later in the code)
I'm beginner so I did just simple loop:

Dim iRefObj As Object
.
selObjCount As Integer = oQuery.MatchCount
For i=0 to selObjCount
iRefObj(i) = oAsm.SelectSet.item(i)
Next

'later when I need add the objects from iRefObj to SelectSet :
oAsm.SelectSet.RemoveAll()
For i=0 to selObjCount
oAsm.SelectSet.Add(i) = iRefObj(i)
Next
oAsm.SelectSet.Refreshdisplay

..all works fine.
Maybe I did some typing errors in the code as I'm not currently at my workstation with all programs and I don't remember the details.

The issue is that when the query find more objects (for example 1000) the loop is too slow.
Faster way to put the objects from selectset to my variable could be Array.Copy, but it didn't works because of narrowing of types.
SelectSet objects are another type as my variable , and both are another type than "Array"
However oAsm.SelectSet.Add(i) = iRefObj(i) works - here is not issue with different types, which is funny to me Smiley Happy

Have anybody idea, what could be the best(fastest) way to put selectset objects in the variable ?

 

Thank you

20 REPLIES

Re: SelectSet Objects


blackbird257 wrote:

Hello,

I trying to create a macro where:
- I create a query
- Objects selected by the query need to take from oAsm.SelectSet and put them into my variable iRefObj (for using later in the code)
I'm beginner so I did just simple loop:

Dim iRefObj As Object
.
selObjCount As Integer = oQuery.MatchCount
For i=0 to selObjCount
iRefObj(i) = oAsm.SelectSet.item(i)
Next

'later when I need add the objects from iRefObj to SelectSet :
oAsm.SelectSet.RemoveAll()
For i=0 to selObjCount
oAsm.SelectSet.Add(i) = iRefObj(i)
Next
oAsm.SelectSet.Refreshdisplay

..all works fine.
Maybe I did some typing errors in the code as I'm not currently at my workstation with all programs and I don't remember the details.

The issue is that when the query find more objects (for example 1000) the loop is too slow.
Faster way to put the objects from selectset to my variable could be Array.Copy, but it didn't works because of narrowing of types.
SelectSet objects are another type as my variable , and both are another type than "Array"
However oAsm.SelectSet.Add(i) = iRefObj(i) works - here is not issue with different types, which is funny to me Smiley Happy

Have anybody idea, what could be the best(fastest) way to put selectset objects in the variable ?

 

Thank you


 

You can try using SuspendDisplay and ResumeDisplay on the SelectSet object. Before calling RemoveAll, call SuspendDisplay and then call ResumeDisplay right before calling RefreshDisplay. That should help - give it a try and let us know.

 

Greg

Re: SelectSet Objects

Hi Greg, thank you for fast reply.

 

However, I don't understand how this can help me.

My issue is how to save selected parts into some array variable, for later using.

Now I using a loop to copy objects to iRefObj(i), which is too slow and looking for faster alternative like "Array.Copy" to copy all selected parts to my variable in the program at once.

 

I don't have any issue regarding displaying selection or something like that..

 

 

Re: SelectSet Objects

[ Edited ]

Just try what @GregLuckett asked you to do....

It's probably the screen update which slows down your loop!!

It has speed up dramatically many lines of code to me in the past by NOT updating the screen display after each line!

Re: SelectSet Objects


blackbird257 wrote:

Hi Greg, thank you for fast reply.

 

However, I don't understand how this can help me.

My issue is how to save selected parts into some array variable, for later using.

Now I using a loop to copy objects to iRefObj(i), which is too slow and looking for faster alternative like "Array.Copy" to copy all selected parts to my variable in the program at once.

 

I don't have any issue regarding displaying selection or something like that..

 

 


 

The loop that goes through and adds each item to the select set is going to be a much bigger performance issue than simply going through the loop that adds each item in the select set to your array variable unless you use Suspend/ResumeDisplay since it will redisplay the selection each time something is added.

 

I guess the bigger question is why you even need to go through and work with the select set in the first place. When running a query using Query.MatchCount, the select set is cleared and only the items matching the query criteria will be in the select set afterwards. Are you doing something else that may add or remove some of those items from the select set between the time you run the query and go add the items back to the select set?

 

Greg

Re: SelectSet Objects

I trying to do macro which shows all hidden parts and hide all shows parts at once.

I do that by this way:

1. I use query to select all shown parts 

2. put them in my variable array (here I'm using the loop)

3. by using query find all hidden parts and show them,

4. put parts which are in my variable (those which were in the beginning shown ) to select set and hide them (I can't use the query here, because the shown part group is changed)

 

the part of loading shown objects to my variable and later in reverse mode is the slowest.

 

Regarding suspend/resume display is of course much faster, but the loop is still too slow.

 

 

 

 

Re: SelectSet Objects


blackbird257 wrote:

I trying to do macro which shows all hidden parts and hide all shows parts at once.

I do that by this way:

1. I use query to select all shown parts 

2. put them in my variable array (here I'm using the loop)

3. by using query find all hidden parts and show them,

4. put parts which are in my variable (those which were in the beginning shown ) to select set and hide them (I can't use the query here, because the shown part group is changed)

 

the part of loading shown objects to my variable and later in reverse mode is the slowest.

 

Regarding suspend/resume display is of course much faster, but the loop is still too slow.

 

 

 

 


 

I'm not really sure what else there is you can do to speed that part up. Have you tried using

 

For Each using oAsm.SelectSet as the group instead of using oAsm.SelectSet.Item? I haven't personally tried that with the select set, so I'm not sure if it will even work or if it will be faster, but that's the only other thing I can think of.

 

For Each usage:

https://msdn.microsoft.com/en-us/library/vstudio/5ebk1751(v=vs.100).aspx

Re: SelectSet Objects

[ Edited ]

Can you please try the following code?

I did a simple test on a small size assembly and it seemed to me that the query took more time than the visibility change itself.

Spoiler
'----------------------------------------------------------------------
' ASM: Toggle the visibility of all assembly (sub)occurrences
'----------------------------------------------------------------------

Sub ToggleVisibilityInAsm(ByVal objDoc As AssemblyDocument)
  For Each objOcc As Occurrence In objDoc.Occurrences
    If objOcc.Subassembly Then
      ' Toggle visibility of each individual subpart recursively
      ToggleVisibilityInSubOccs(objOcc.SubOccurrences)
    Else
      ' Toggle the visibility of the part
      objOcc.Visible = Not objOcc.Visible
    End If
  Next
End Sub

Sub ToggleVisibilityInSubOccs(ByVal objSubOccs As SubOccurrences)
  For Each objSubOcc As SubOccurrence In objSubOccs
    If objSubOcc.Subassembly Then
      ToggleVisibilityInSubOccs(objSubOcc.SubOccurrences)
    Else
      ' Toggle the visibility of the part
      objSubOcc.Visible = Not objSubOcc.Visible
    End If
  Next
End Sub


Sub Main()
  Dim objApp As SolidEdgeFramework.Application = Marshal.GetActiveObject("SolidEdge.Application")
  Dim objDoc As SolidEdgeAssembly.AssemblyDocument = objApp.ActiveDocument
  objApp.ScreenUpdating = False
  objApp.Interactive = False
  ToggleVisibilityInAsm(objDoc)
  objApp.Interactive = True
  objApp.ScreenUpdating = True
  MsgBox("Click OK to toggle visibility again", Microsoft.VisualBasic.MsgBoxStyle.OkOnly)
  objApp.ScreenUpdating = False
  objApp.Interactive = False
  ToggleVisibilityInAsm(objDoc)
  objApp.Interactive = True
  objApp.ScreenUpdating = True
End Sub

 

Re: SelectSet Objects

I'm not too experienced in programming macro, so I thought that is possible to copy one array of objects to another by simple command - no filtration, no conditions just 1:1 copy - it was just my feeling that this MUST be possible Smiley Happy

 

I test for - next loop on assembly with 1200parts, and it takes 1min. 50sec (18sec takes query)

 

Time to time we have assembly with 5k of parts..

 

Re: SelectSet Objects


blackbird257 wrote:

 

I'm not too experienced in programming macro, so I thought that is possible to copy one array of objects to another by simple command - no filtration, no conditions just 1:1 copy - it was just my feeling that this MUST be possible Smiley Happy

 

I test for - next loop on assembly with 1200parts, and it takes 1min. 50sec (18sec takes query)

 

Time to time we have assembly with 5k of parts..

 


 

Unfortunately, the select set is not simply an array of objects that can be copied.

Almost 2 minutes seems like a very long time to loop through 1200 items...