Fastest way to switch off Visibility of all SurfaceBodies in Multi-Part

Fastest way to switch off Visibility of all SurfaceBodies in Multi-Part

Maxim-CADman77
Advisor Advisor
705 Views
5 Replies
Message 1 of 6

Fastest way to switch off Visibility of all SurfaceBodies in Multi-Part

Maxim-CADman77
Advisor
Advisor

I'd like to know the most efficient (fastest) way to switch off visibility of all SurfaceBodies in Multi-Part.

I've already tried to call appropriate UI command directly:

ThisApplication.CommandManager.ControlDefinitions("PartVisibilityCtxCmd").Execute

Executing this line seems to have no effect.

 

The workaround I currently use  - switching visibility one-by-one in For-Each cycle. This works OK but takes unreasonably much time for Multi-Parts containing several hundreds of bodies.

 

I wonder if LINQ query can do the trick..

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
706 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

How does selecting the surface bodies folder sound? That command works when you select multiple surface bodies or when you select the folder you can select all at the same time. 

AAcheson_0-1662938271860.png

 

Sub Main
   
    Dim oPartDoc As PartDocument = ThisDoc.Document
 
	'Get the BrowserPane For PartDocument
	Dim nodes As BrowserNodesEnumerator = oPartDoc.BrowserPanes.Item("PmDefault").TopNode.BrowserNodes
	
	SelectPartsLoop(nodes)  
	MessageBox.Show("All Done", "Title")
End Sub

Private Sub SelectPartsLoop(nodes As BrowserNodesEnumerator)
    For Each node As BrowserNode In nodes 
		If node.BrowserNodeDefinition.Label.StartsWith("Surface Bodies")
			node.DoSelect 
			ThisApplication.CommandManager.ControlDefinitions("PartVisibilityCtxCmd").Execute
		Else	
			SelectPartsLoop(node.BrowserNodes)
		End If
    Next
End Sub

  

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

TechInventor20
Advocate
Advocate

This is what you are looking for 

'***** alle workfeatures vanuit de Part uitzetten ****
	'dit gaat dan om sketches workplanes and workpoints

'*****catch and skip errors
On Error Resume Next

'*****get user input as True or False
wfBoolean = InputRadioBox("Turn all Work Features On/Off", "On", "Off", False, "iLogic")

'*****Check all referenced docs
Dim oDoc As Inventor.Document
oDoc = ThisDoc.Document
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
       oWorkPlane.Visible = wfBoolean
    Next

    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
       oWorkAxis.Visible = wfBoolean
    Next

    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
       oWorkPoint.Visible = wfBoolean
    Next
    'sketches uitzetten
    Dim oSketches As PlanarSketches
    oSketches = oDoc.ComponentDefinition.Sketches
    Dim oSketch As PlanarSketch
    For Each oSketch In oSketches
	oSketch.Visible = wfBoolean
    Next

    'surfaces uitzetten
    'Get the surfacebodies for the current document.
    'Dim oBody As worksurface
    
    For Each oBody In oDoc.ComponentDefinition.WorkSurfaces
    	oBody.Visible = wfBoolean
    Next

'*****update the files
InventorVb.DocumentUpdate()
Message 4 of 6

Maxim-CADman77
Advisor
Advisor

@A.Acheson,

The solution you've provided is much faster* than For-Each cycle (0,4 sec on my slow config) yet Is seems not a bulletproof (would work only within non-localized Inventor session).

I still hope there is more universal (?LINQ?) solution thus would not mark it as solved right now.

Anyway Thank you.

 

* To get it work on my site I should have replaced 

.Label.StartsWith("Surface Bodies")

to 

.Label.StartsWith("Solid Bodies").

 

PS: It seems recursive call in private sub is not necessary, right?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 6

Maxim-CADman77
Advisor
Advisor

Here is LINQ query to get list of all visible Bodies:

 

 

Dim VisSBs = From x In oPartDoc.ComponentDefinition.SurfaceBodies Where x.Visible = True

 

 

... yet I have no idea on how to use it to switch off visibility of those bodies (if possible).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

Using a loop is probably not the problem. And also any LINQ function will loop over all bodies. The problem is the overhead from each command done by Inventor. You can eliminate most overhead by wrapping all actions in 1 transaction. Have a look at this example.

Dim doc As PartDocument = ThisDoc.Document

Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(doc, "Make all bodies invisable")
Try
    For Each body As SurfaceBody In doc.ComponentDefinition.SurfaceBodies
        body.Visible = False
    Next
    trans.End()
Catch ex As Exception
    trans.Abort()
End Try

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