Detect visibility of objects in drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm completely lost, having tried so many different approaches to what I want to achieve...
What's the goal?
I want to check for a given view on a drawing, whether there are objects (parts, assemblies, pattern features of parts/assemblies) not visible. This applies only to drawing views that are not associative to any DesignViewRep. Later on I'd like to have a list of these objects, right now I only want to detect if there are such objects.
What I tried in the first place
I tried traversal of the ReferencedDocument's Occurrences and SubOccurrences, then get the visibility of the Occurrence in question via DrawingView.GetVisibility(Occurrence). The method GetVisibility fails (more on that later). I thought, this method would fail, as I didn't use proxies so far, which is not trivial. Then I tried to use Proxies, but...
- I'm not sure, whether I would need to build a chain of proxies (proxy for part in subassy2, proxy for subassy2 in subassy1, proxy for subassy1 in mainassy, proxy for mainassy in view...)
- I couldn't find any information on how to create proxies for ComponentOccurrences or if that is possible at all
- Creating proxies via ComponentOccurrence.CreateGeometryProxy() on itself doesn't work.
- For parts I tried to circumvent this by iterating over the SurfaceBodies (for which proxies can be created), yet GetVisibility did fail on these as well sometimes... that's been the point where I gave up with that approach...
- For assemblies...? No idea...
Alternative approach
In order to circumvent the proxy issue, I thought of traversing the tree. This is cumbersome, as I would have to specify, which types of nodes are interesting. I don't know exactly, how to specify assemblies and patterns, but so far at least that part of the code works. The idea was, that the tree should provide the "context" (part/assembly somewhere deep down in the tree but depicted in the view) so no proxies would be needed. The following code is, what I've got so far:
Private Function CheckBrowserNodeVisRecursive(oBrowserNode As BrowserNode) As Boolean
If bailOut = True Then Exit Function
CheckBrowserNodeVisRecursive = False
Dim oSubBrowserNode As BrowserNode
Dim oCompOcc As ComponentOccurrence
Dim bVis As Boolean
Dim sbVis As String
bVis = True
If Not (oBrowserNode.NativeObject Is Nothing) Then
If (TypeName(oBrowserNode.NativeObject) = "DrawingView") Or _
(TypeName(oBrowserNode.NativeObject) = "ComponentOccurrence") Or _
(TypeName(oBrowserNode.NativeObject) = "AssemblyComponentDefinition") Then
'' Need to include AssemblyComponentDefinition in order to go deeper later on...
If (TypeName(oBrowserNode.NativeObject) = "ComponentOccurrence") Then
Set oCompOcc = oBrowserNode.NativeObject
On Error Resume Next
bVis = oDoc.Sheets(1).DrawingViews(1).GetVisibility(oCompOcc)
If Err.Number <> 0 Then
sbVis = "GetVisibility-Error"
Err.Clear
Else
sbVis = CStr(bVis)
End If
On Error GoTo 0
MsgReturn = MsgBox("BrowserNode: " + vbCrLf + oBrowserNode.FullPath + vbCrLf + vbCrLf + _
"Type: " + TypeName(oBrowserNode.NativeObject) + vbCrLf + vbCrLf + _
"BrowserNode visible? " + CStr(oBrowserNode.Visible) + vbCrLf + vbCrLf + _
"BrowserNode.NativeObject visible? " + CStr(oBrowserNode.NativeObject.Visible) + vbCrLf + vbCrLf + _
"oCompOcc GetVisibility result: " + sbVis, vbOKCancel, "DEBUG")
Set oCompOcc = Nothing
If MsgReturn = vbCancel Then
bailOut = True
Exit Function
End If
If bVis = False Then
CheckBrowserNodeVisRecursive = True
Exit Function
End If
End If
If oBrowserNode.BrowserNodes.Count <> 0 Then
For Each oSubBrowserNode In oBrowserNode.BrowserNodes
If (CheckBrowserNodeVisRecursive(oSubBrowserNode) = True) Then
CheckBrowserNodeVisRecursive = True
Exit Function
End If
Next
End If
End If '' check for relevant types of oBrowserNode.NativeObject
End If '' oBrowserNode.NativeObject is not nothing
End Function
Notes:
- bailOut is used to get out of the whole thing quickly, not having to click 10000 ok buttons or killing Inventor...
- sbVis is just a string to contain either bVis (result of GetVisibility) or an error message
- Error handling of GetVisibility should be clear, runtime error (see below) will not appear with that error handling
- At this point I only need to know if there is ANYTHING not visible, so I get out of the whole recursion if I detect something invisible.
- Function is initially called with the respective view's browser node as argument
BrowserNode.Visible
This is obviously not, what I want. Example:
In an assembly, there are (read: exist) browser nodes for constraints and representations.
If this assembly is depicted in a drawing view, the assembly's browser nodes itself still exist, but they're not visible in the tree in context of the drawing.
BrowserNode.NativeObject.Visible
I thought this would be the holy grail... however it isn't. Either Inventor lies to me and returns plain wrong values or the .visible property isn't what I think it is. Example:
DrawingView.GetVisibility
As you can see by the above screenshot, I tried to use DrawingView.GetVisibility on a ComponentOccurrence that I retrieved from BrowserNode.NativeObject once again. This seems to work in THIS very situation, however the method fails every now and then, throwing a runtime error (comment out error handling to see this!):
The situation this happened in looks like that:
And the moment the runtime error comes up, we're processing the correct object:
Funny enough, the ComponentOccurrence has a .visible property of its own, holding no useful (or wrong) information anyway (yes, in this case, it's right, however there seems to be no reliable relation to what I'm interested in... can say true when invisible, can say false when visible, can say anything...) :
Now what's even worse, the GetVisibility method seems to fail reproducibly under certain (unclear) circumstances.
Have a look at the above depicted tree: If I set everything to be visible, the method fails on the first two parts of each instance of the subassembly. Notice the third part is exactly the same as the second part in that subassembly and with this Occurrence (and all others) however, GetVisibility doesn't fail.
If I set only the very first part in the main assembly to be "not visible", the method provides the correct result - notice this part is exactly the same as the first part in all subassemblies (where the method fails, as per last paragraph). So it seems to be not a problem of the object itself... but rather something "situational"...?
Conclusion
All I want to do is: Get to know, which ComponentOccurrences in the tree are not visible / "greyed out".
How to do that?
Am I using the method GetVisibility wrongly? Why doesn't that work?
Am I checking the wrong objects or properties? Why is BrowserNode.NativeObject.Visible telling lies?
Thank you in advance
W. Kretzschmar