Trouble toggling iPart plane visibility using VBA

Trouble toggling iPart plane visibility using VBA

Anonymous
Not applicable
594 Views
5 Replies
Message 1 of 6

Trouble toggling iPart plane visibility using VBA

Anonymous
Not applicable

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:

2014-09-16 11_25_11-Microsoft Visual Basic.png

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.

0 Likes
595 Views
5 Replies
Replies (5)
Message 2 of 6

YuhanZhang
Autodesk
Autodesk

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.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 6

C-Hoppen
Advocate
Advocate

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?

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

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

0 Likes
Message 5 of 6

C-Hoppen
Advocate
Advocate

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 🙄

0 Likes
Message 6 of 6

C-Hoppen
Advocate
Advocate

This may be small comfort, but it works with iParts: 

oAssmDoc.ObjectVisibility.AllWorkFeatures = false;