I am attempting to toggle the visibility of every WorkPlane in every part of a SelectionSet using VBA. I am using the following code to do so:
Public Sub toggleBasePlanes() Dim selectedParts As SelectSet Dim oOccurence As ComponentOccurrence Dim oWorkPlane As WorkPlane Dim basePlanes As WorkPlanes Set selectedParts = ThisApplication.ActiveDocument.SelectSet For Each oOccurence In selectedParts Set basePlanes = oOccurence.Definition.WorkPlanes For Each oWorkPlane In basePlanes oWorkPlane.Visible = Not oWorkPlane.Visible Next oWorkPlane Next oOccurence End Sub
This works well for standard parts and assemblies, but I get the following error when I run it on an iPart:
Furthermore, it appears that I do not get the error when I run the code on iParts that were created in the current session of Inventor. I am out of ideas, maybe I need to access the planes differently for an iPart? Any help would be appreciated.
In UI if you can't toggle the visibility of WorkPlane of an iPart member you should also fail to toggle it via API. You can treat the iPart member as an exception to avoid to toggle the visibility of WorkPlane in it.
Nowadays it is possible to toogle the visibility via context menu. But it still seems to fail via api...?
It took me some time having trouble with an exception I didn't understand. Now I stumbled over this post.
Is there a solution to the problem by now?
From my experince with iparts you have to open the ipart factory from the member. Togle the visibility of the ipart factory planes, save and close the ipart factory and then update the assemblly. I think that would work
Thanks for reply, but that doesn't solve my problem. The goal is to turn on/off the visibilty of planes in occurrences. Imagine you have one iPart-Member placed twice in an assembly. Lets say iPart_Member:01 and iPart_Member:02.
Now toggle visibility of yz origin plane in iPart_Member:01 and visibility of xy origin plane in iPart_Member:02.
Inventor.ComponentOccurrenceProxy occProxy... ...
Inventor.PartComponentDefinition partDef = (Inventor.PartComponentDefinition)occProxy.Definition; foreach (Inventor.WorkPlane workPlane in partDef.WorkPlanes) { occProxy.CreateGeometryProxy(workPlane, out object oo); if (oo is Inventor.WorkPlaneProxy) { Inventor.WorkPlaneProxy workPlaneProxy = (Inventor.WorkPlaneProxy)oo; if (workPlaneProxy.Visible == true) workPlaneProxy.Visible = false; // <--- fails when occurrence is ipart member } }
The code works fine with any standard part, but fails with iPart members. Since 2014 🙄