Hiding or Show only Select Set of an assembly

Valued Contributor
Valued Contributor

Hello,

I wrote a code to  hide the select set in an assembly.

This code loops each selected item and set its vissible property to false:

Dim oASM As SolidEdgeAssembly.AssemblyDocument
Dim oSelectSet As SellectSet
Dim oOccurrence as Occurrence
Dim NumberOfSellectedOccurrences as integer
		
Set oSelectSet = oASM.SelectSet
NumberOfSelectedOccurrences = oSelectSet.Count
		
For i = 1 To NumberOfSelectedOccurrences
	Set oOccurrence = oSelectSet(i)
	oOccurrence.Visible = False
Next

 

Unfortunatly, one of each hiding operation takes on average 1 second. For a big select set it easily takes minutes to hide each component one by one.

 

So i have two questions:

1) Is there a way to hide the entire selectSet in one time in order to save time?

2) Related to the pervious question: is there a way to do the oposite: Preform a show only of the selectSet?

 

Thanks for your help!

7 REPLIES

Re: Hiding or Show only Select Set of an assembly

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

There are usually "tricks" to improve performance. Application.DelayCompute = false and Application.ScreenUpdating = false are two off the top of my head.

 

I wrote some quick and dirty code to test with and pasted it below. The code also answers your two how-to questions. This code assumes that Solid Edge is already started with an assembly open with items in the SelectSet.

 

As commented in the code, simply using Application.ScreenUpdating = false yielded a 3X speed improvement. There may be other speed improvements to be had but again, this was off the top of my head.

 

Imports System
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Linq
Imports System.Runtime.InteropServices
Imports System.Text

Namespace ConsoleApplication1
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			Dim application = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
			Dim assemblyDocument = TryCast(application.ActiveDocument, SolidEdgeAssembly.AssemblyDocument)

			HideUnselectedOccurrences(assemblyDocument)
			HideSelectedOccurrences(assemblyDocument)
			TestScreenUpdatingPerformance(assemblyDocument)
		End Sub

		Private Shared Sub HideSelectedOccurrences(ByVal assemblyDocument As SolidEdgeAssembly.AssemblyDocument)
			Dim application = assemblyDocument.Application
			Dim selectSet = assemblyDocument.SelectSet

			Dim stopwatch As New Stopwatch()

			stopwatch.Start()

			application.DelayCompute = True

			' ScreenUpdating = true is the default.
			'application.ScreenUpdating = true; // Duration: {00:00:01.1296055}

			' ScreenUpdating = false can improve API performance.
			application.ScreenUpdating = False ' Duration: {00:00:00.3458345} -- 3X faster...


			For i As Integer = 1 To selectSet.Count
				Dim item = selectSet.Item(i)

				If TypeOf item Is SolidEdgeAssembly.Occurrence Then
					Dim occurrence = TryCast(item, SolidEdgeAssembly.Occurrence)

					occurrence.Visible = False
				End If
			Next i

			application.ScreenUpdating = True
			application.DelayCompute = False

			stopwatch.Stop()

			Dim elapsed = stopwatch.Elapsed
			Console.WriteLine(elapsed)
		End Sub

		Private Shared Sub HideUnselectedOccurrences(ByVal assemblyDocument As SolidEdgeAssembly.AssemblyDocument)
			Dim application = assemblyDocument.Application
			Dim selectSet = assemblyDocument.SelectSet
			Dim occurrences = assemblyDocument.Occurrences
			'List<SolidEdgeAssembly.Occurrence> selectSetList = new List<SolidEdgeAssembly.Occurrence>();

			Dim stopwatch As New Stopwatch()

			stopwatch.Start()

			application.DelayCompute = True

			' ScreenUpdating = true is the default.
			'application.ScreenUpdating = true; // Duration: {00:00:01.1296055}

			' ScreenUpdating = false can improve API performance.
			application.ScreenUpdating = False ' Duration: {00:00:00.3458345} -- 3X faster...

			' Leverage Linq for easy querying of items.
			Dim queryableSelectSet = selectSet.OfType(Of SolidEdgeAssembly.Occurrence)()

			For i As Integer = 1 To occurrences.Count
				Dim occurrence = occurrences.Item(i)

				' Check to see if current occurrence exists in the SelectSet.
				Dim selectSetItem = queryableSelectSet.FirstOrDefault(Function(x) x.Equals(occurrence))

				If selectSetItem Is Nothing Then
					occurrence.Visible = False
				Else
					occurrence.Visible = True
				End If
			Next i

			application.ScreenUpdating = True
			application.DelayCompute = False

			stopwatch.Stop()

			Dim elapsed = stopwatch.Elapsed
			Console.WriteLine(elapsed)
		End Sub

		Private Shared Sub TestScreenUpdatingPerformance(ByVal assemblyDocument As SolidEdgeAssembly.AssemblyDocument)
			Dim application = assemblyDocument.Application
			Dim occurrences = assemblyDocument.Occurrences

			Dim stopwatch As New Stopwatch()

			stopwatch.Start()

			application.DelayCompute = True

			' ScreenUpdating = true is the default.
			'application.ScreenUpdating = true; // Duration: {00:00:01.1296055}

			' ScreenUpdating = false can improve API performance.
			application.ScreenUpdating = False ' Duration: {00:00:00.3458345} -- 3X faster...


			For i As Integer = 1 To occurrences.Count
				Dim occurrence = occurrences.Item(i)

				' Toggle visibility of occurrence.
				occurrence.Visible = Not occurrence.Visible
			Next i

			application.ScreenUpdating = True
			application.DelayCompute = False

			stopwatch.Stop()

			Dim elapsed = stopwatch.Elapsed
			Console.WriteLine(elapsed)
		End Sub
	End Class
End Namespace

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Hiding or Show only Select Set of an assembly

Valued Contributor
Valued Contributor

Thanks for the tricks Jason,

 

I tried implementing an other workaround wich involves creating temporary AssemblyGroups.

First I put the SelectSet in the group and then I hide it. This workaround is a bit faster but also a bit devious.

 

Maybe I will see if the combination of your "trick" and my "groups" give an even faster result.

 

Kr,

David

Re: Hiding or Show only Select Set of an assembly

Siemens Phenom Siemens Phenom
Siemens Phenom

David,

 

I don't know if this will help or not, but you might also try calling SuspendDisplay on the SelectSet object before you do all your processing and then call ResumeDisplay after all your other processing. It is definitely a simple change you can try that could possibly help.

 

Greg

Re: Hiding or Show only Select Set of an assembly

Phenom
Phenom

Thats a great suggestion Greg and it occurred to me right off the bat after reading the question.

Here is the code:

 

Dim oASM As SolidEdgeAssembly.AssemblyDocument = oApp.ActiveDocument
Dim oSelectSet As SelectSet
Dim oOccurrence As Occurrence
Dim NumberOfSellectedOccurrences As Integer

oSelectSet = oASM.SelectSet
NumberOfSellectedOccurrences = oSelectSet.Count

oSelectSet.SuspendDisplay()

For i = 1 To NumberOfSellectedOccurrences - 1 oOccurrence = oSelectSet(i) oOccurrence.Visible = Not oOccurrence.Visible Next
oSelectSet.ResumeDisplay()

I however found this making no difference, to the extent that the behavior of Solid Edge hiding the occurrences was virtually the same, as if the two extra lines were not there. The assembly components still are hiding one after another. So I dared not to post and raise another sub-question to an already hot topic.

I tried this with Group objects in a Draft sheet and it does not seem to work there too.

These two over-simplistic methods are either used in a wrong fashion or simply do not work.

Re: Hiding or Show only Select Set of an assembly

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I think the SuspendDisplay and ResumeDisplay should be used when changing the SelectSet, so that its highlight only updates once at the end.

As you do NOT change the content of the SelectSet, these two properties have NO effect.

Re: Hiding or Show only Select Set of an assembly

Siemens Phenom Siemens Phenom
Siemens Phenom

Actually, Martin is correct. Since the select set contents aren't changing, Suspend/Resume Display shouldn't do anything. After thinking about this a little more, there is a much easier way to do this if you are simply interested in hiding or doing a show only on the select set contents - you can simply use the StartCommand method on the application object and start the appropriate assembly command. This will start the native Solid Edge command and you do not need to do any processing of the select set yourself:

 

 

Dim oApp As SolidEdge.Framework.Application

 

oApp = GetObject(, "SolidEdge.Application")

 

' Hide

oApp.StartCommand(SolidEdge.Constant.AssemblyCommandConstants.AssemblyAssemblyToolsHide)

 

' ShowOnly

oApp.StartCommand(SolidEdge.Constant.AssemblyCommandConstants.AssemblyAssemblyToolsShowOnly)

 

 

Hope this helps,

Greg

Re: Hiding or Show only Select Set of an assembly

Valued Contributor
Valued Contributor

Thanks Greg,

 

This was exactly what i was looking for!

I didn't know about this function yet. But it is verry usefull. I'm sure i will use this command function for other problems too!

 

Kr,