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: 

Trouble toggling iPart plane visibility using VBA

5 REPLIES 5
Reply
Message 1 of 6
mgall
380 Views, 5 Replies

Trouble toggling iPart plane visibility using VBA

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.

5 REPLIES 5
Message 2 of 6
YuhanZhang
in reply to: mgall

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.

Message 3 of 6
C-Hoppen
in reply to: YuhanZhang

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?

 

Message 4 of 6
vulic
in reply to: C-Hoppen

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

Message 5 of 6
C-Hoppen
in reply to: vulic

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 🙄

Message 6 of 6
C-Hoppen
in reply to: C-Hoppen

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

oAssmDoc.ObjectVisibility.AllWorkFeatures = false;

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

Post to forums  

Autodesk Design & Make Report