Set all surfacebodies to invisible. VBA code attached.

Set all surfacebodies to invisible. VBA code attached.

Anonymous
Not applicable
2,638 Views
4 Replies
Message 1 of 5

Set all surfacebodies to invisible. VBA code attached.

Anonymous
Not applicable

Hello. I'm new to the VBA and new in the forum.

I found a VBA-code on internet which turn off all work features (plane, axis, points) in all documents in an assembly.

I want to modify it so it turns of all surface bodies instead. I use skeleton modelling where i only want to keep the solids visible and not the surfaces. When I run this iLogic rule all solids get turned off instead of surface bodies. What do I do wrong? This code works (when edited) for axis, points, planes, allworkfeatures etc.

 

Thanks in advance 🙂

 

'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument  


'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
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set surface bodies visibility
    For Each oSurfaceBodies In oDoc.ComponentDefinition.SurfaceBodies
    oSurfaceBodies.Visible = wfBoolean
    Next
   Next
'update the files
InventorVb.DocumentUpdate()

 

0 Likes
Accepted solutions (1)
2,639 Views
4 Replies
Replies (4)
Message 2 of 5

matt_jlt
Collaborator
Collaborator
Accepted solution

Try this,  just replaces surface bodies with work surfaces. Surface bodies are just the solid bodies. Work surfaces are the actual "Surfaces".

 

Regards, Matt.

 

'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument  


'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
Dim oWS As WorkSurface
For Each oDoc In oAssyDoc.AllReferencedDocuments 'set surface bodies visibility For Each oWS In oDoc.ComponentDefinition.WorkSurfaces oSurfaceBodies.Visible = wfBoolean Next Next 'update the files InventorVb.DocumentUpdate()
Message 3 of 5

Anonymous
Not applicable

Thank you vert much for the fast reply. 🙂 It works! It is a little bit confusing with the name convention though :s.

 

I actually got all what I need, but is it any way to have multi-input RadioBox?

 

I attach the code here, maybe someone else also have use for it:

 

'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument  


'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
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set WorkPlane visibility
    'For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    'oWorkPlane.Visible = wfBoolean
    'Next
    
    'set WorkAxes visibility
    'For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    'oWorkAxis.Visible = wfBoolean
    'Next
    
    'set WorkPoints visibility
    'For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    'oWorkPoint.Visible = wfBoolean
    'Next
	
    'set AllWorkFeatures visibility
    'For Each oAllWorkFeatures In oDoc.ComponentDefinition.AllWorkFeatures
    'oAllWorkFeatures.Visible = wfBoolean
    'Next
	
    'set WorkSurfaces (all Surface bodies) visibility
    'For Each oWorkSurfaces In oDoc.ComponentDefinition.WorkSurfaces
    'oWorkSurfaces.Visible = wfBoolean
    'Next
	
    'set SurfaceBodies (all Solid bodies) visibility
    For Each oSurfaceBodies In oDoc.ComponentDefinition.SurfaceBodies
    oSurfaceBodies.Visible = wfBoolean
    Next
Next
'update the files
InventorVb.DocumentUpdate()

 

 

 

0 Likes
Message 4 of 5

ewcler
Enthusiast
Enthusiast

I tweaked the code for use within Inventor's API.  It works pretty good as far as I am concerned.

Sub HideSurfacesInAsm()


'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = ThisApplication.ActiveDocument
Dim oSurfacebody As WorkSurface

Dim Vis As Boolean
Dim result
result = MsgBox("Make all surfaces visible?", vbYesNoCancel)
Select Case result
    Case vbYes
        Vis = True
    Case vbNo
        Vis = False
    Case vbCancel
        Exit Sub
End Select

Dim oDoc As Inventor.Document

For Each oDoc In oAssyDoc.AllReferencedDocuments
    
    For Each oSurfacebody In oDoc.ComponentDefinition.WorkSurfaces
        oSurfacebody.Visible = Vis
    Next
Next
ThisApplication.ActiveDocument.Update

End Sub

 

Eddie Cler
Paul's Machine & Welding Corp.
Dell Precision T3600- Xeon E5-1620 @ 3.6 GHz 32GB Ram - Nvidia Quadro 4000 Windows 7
0 Likes
Message 5 of 5

Anonymous
Not applicable

Do you know how I can add a multiselection RadioBox? Have several questions Yes/No? I wan't to be able to select what to show and what to hide.

0 Likes