
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Task:
I want to make a custom function using the inventor API that enables us to programmatically hide all Surface Bodies in a drawing.
Using the GUI:
It is possible to hide Surface Bodies by right clicking on the "Surface Bodies (1)" node in the "Model Tree" and then toggle visibility by clicking on "Visibility". In the screen snap below "Surface Bodies" on the first part has been hidden.
The "Surface Bodies" is the circular Extrusion of Srf1. It is visble on the second part and hidden on the first.
Problem:
How can I achieve this through the API.
I need to make a C# function that can do this - but for a start we try using VBA.
First I tried to use the DrawingView Objects in the ActiveDocument but I was not able find the "Surface Bodies" by browsing the view object hierarchy.
Next i tried acces via the BrowserNodes - but faild to find the object that actually controls the visibility of the "Surface Bodies".
Failed attempt:
Sub HideSurfaceBodies() Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument For Each Item In oDrawDoc.BrowserPanes If Item.Name = "Model" Then For Each Level2Item In Item.TopNode.BrowserNodes Debug.Print Level2Item.FullPath DumpLevel 1, Level2Item Next Level2Item End If Next Item oDrawDoc.Update oDrawDoc.Update2 End Sub Sub DumpLevel(level, itemN) If InStr(1, itemN.FullPath, "Surface Bodies") > 0 Then Debug.Print Left(" ", level * 3) _ & itemN.FullPath If Not itemN.NativeObject Is Nothing Then If itemN.NativeObject.Type = kWorkSurfaceObject Then If Not itemN.NativeObject.SurfaceBodies Is Nothing Then If itemN.NativeObject.SurfaceBodies.Count > 0 Then For Each Body In itemN.NativeObject.SurfaceBodies Debug.Print Body.Name & " " & Body.Visible & " parent: " _ & Body.Parent.Visible Body.Visible = False Next Body End If End If End If End If End If If itemN.BrowserNodes.Count > 0 Then For Each nextLevelItem In itemN.BrowserNodes DumpLevel level + 1, nextLevelItem Next nextLevelItem End If End Sub
The debug output from the above code looks like this:
SurfaceBodyTest.dwg:Drawing Resources SurfaceBodyTest.dwg:Sheet:1 SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:1:Surface Bodies SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:1:Surface Bodies:Srf1 Srf1 False parent: False SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:1:Surface Bodies:Srf1:ExtrusionSrf1 SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:1:Surface Bodies:Srf1:ExtrusionSrf1:Sketch5 SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:2:Surface Bodies SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:2:Surface Bodies:Srf1 Srf1 False parent: False SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:2:Surface Bodies:Srf1:ExtrusionSrf1 SurfaceBodyTest.dwg:Sheet:1:VIEW1:201587.iam:201587.iam:201586:2:Surface Bodies:Srf1:ExtrusionSrf1:Sketch5
I am at a loss here. I suspect that i need to find some sort of Proxy Object but I don't know how.
Any suggestions would be highly appreciated.
Thanks in advance
Lars Lund Hansen
Solved! Go to Solution.