How can I distinguish between Solid Bodies and Surface Bodies?
In my case I want to get the Surface Bodies only (and just the actual surface)
If I use SurfaceBodies it seems to control both Solid Bodies and Surface Bodies and if I use WorkSurfaces then nothing seems to happen.
Please see snippet below for a very simplified example.
Dim oDoc As Inventor.Document oDoc = ThisDoc.Document For Each oWS In oDoc.ComponentDefinition.SurfaceBodies 'For Each oWS In oDoc.ComponentDefinition.WorkSurfaces 'oWS.Visible = False oWS.Visible = True Next
Solved! Go to Solution.
Solved by Boorda. Go to Solution.
Sub HideSurfaces()
'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
It is a fine piece of code. I have seen it here on the forum, but it does not seem to work on the files that I have.
The files that we have here are imported files from a sub-supplier which we are using in some of our "as-built" documentation.
I have made an example file with the code, see attached files.
See also picture for Surface Bodies that I want to work with.
You were already very close. All you needed to do was check to see if the IsSolid property was set to false.
Here is a sample that selects only surfacebodies, turns them visible and adds them to the documents selection set.
Public Sub SelectAllSurfaces() 'Get the active document. Dim ActDoc As Document: Set ActDoc = ThisApplication.ActiveDocument 'Lets check to make sure we are in a part or assembly document. If ActDoc.DocumentType = kPartDocumentObject _ Or ActDoc.DocumentType = kAssemblyDocumentObject Then 'Do Nothing, we can continue... Else MsgBox "This funtion can only be performed on a part or assembly document.", vbInformation Exit Sub End If 'Create a select set to hold the selection. Dim SelSet As SelectSet: Set SelSet = ActDoc.SelectSet ActDoc.SelectionPriority = kBodySelectionPriority 'We know we are working with a part or assembly file so lets grab its component definition. Dim cDef As ComponentDefinition: Set cDef = ActDoc.ComponentDefinition 'Get the surfacebodies for the current document. Dim SrfBod As SurfaceBody Dim SrfBods As SurfaceBodies: Set SrfBods = cDef.SurfaceBodies 'Lets add the surfacebodies to the selection set. For Each SrfBod In SrfBods 'We only want surfaces that are not also solids. If Not SrfBod.IsSolid Then SelSet.Select SrfBod: SrfBod.Visible = True Next End Sub
After running the above code.
I realize that this is an old post; but when I try the above code in Inventor 2016 it doesn't work. I get an error on the line:
If Not SrfBod.IsSolid Then SelSet.Select SrfBod: SrfBod.Visible = True