Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - API access to Surface Bodies

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Holgarsson
2988 Views, 5 Replies

iLogic - API access to Surface Bodies

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.

 

 

Surface Bodies.png

 

 

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
5 REPLIES 5
Message 2 of 6
GeorgK
in reply to: Holgarsson

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

Message 3 of 6
Holgarsson
in reply to: GeorgK

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.

 

Surface bodies.png

Message 4 of 6
Boorda
in reply to: Holgarsson

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.

 

Selected Surface Bodies Only

  


Automation is key!
Tags (1)
Message 5 of 6
Holgarsson
in reply to: Boorda

Thanks for the reply. Perfekt.
Message 6 of 6
dschleede
in reply to: Boorda

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report