Hide bodies from the user interface

Hide bodies from the user interface

victoriaN4VP7
Participant Participant
923 Views
4 Replies
Message 1 of 5

Hide bodies from the user interface

victoriaN4VP7
Participant
Participant

Is there a function to hide bodies from the user interface? I am trying to hide all bodies from view with the exception of 'Body 6' remaining visible using python script rather than clicking in the design tree to hide each body. 

0 Likes
Accepted solutions (2)
924 Views
4 Replies
Replies (4)
Message 2 of 5

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

The shortcut "V" hides the selected bodies.

What you want could be developed with an add-in that hides all bodies other that the selected ones.

 

Regards,

Jorge Jaramillo

 

Message 3 of 5

victoriaN4VP7
Participant
Participant

Hi Jorge,

 

I am looking for a python code or function that I can insert into an existing script that would hide all visible bodies in the design with exception of one body. 

 

Thanks!

0 Likes
Message 4 of 5

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi Victoria,

 

The following recursive script will hide all bodies except the name supplied as second argument:

 

def hide_all_bodies_except_one(comp: adsk.fusion.Component, body_name: str):
    for body in comp.bRepBodies:
        if body.name != body_name:
            body.isLightBulbOn = False
    for occ in comp.occurrences:
        if occ.component:
            hide_all_bodies_except_one(occ.component, body_name)

 

 

You can call it like:

 

hide_all_bodies_except_one(root, "Body6")

 

In this case it will hide all bodies except the ones with name "Body6".

It wont check if the body is visible or not, which could also be added.  As a reminder a body is visible if itself has bulb on and also all its parent component are also visible.

Does this met your needs?

 

I hope this could help you.

 

Regards,

Jorge Jaramillo

 

Message 5 of 5

kandennti
Mentor
Mentor
Accepted solution

Hi @Jorge_Jaramillo -San.

 

By using the Component.findBRepUsingPoint method and setting proximityTolerance to a large value, you can efficiently obtain only the displayed BreoBody.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-98FA52AD-C930-42D5-B67B-41ACB1691DBB 

 

def hide_all_bodies_except_one(body_name: str):
    app: adsk.core.Application = core.Application.get()
    des: adsk.fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    import sys

    showBodies = root.findBRepUsingPoint(
        adsk.core.Point3D.create(0,0,0),
        adsk.fusion.BRepEntityTypes.BRepBodyEntityType,
        sys.float_info.max,
    )

    body: adsk.fusion.BRepBody = None
    for body in showBodies:
        if body.name == body_name: continue

        body.isLightBulbOn = False