Show/Hide JointOrigin

Show/Hide JointOrigin

jonrbloom
Advocate Advocate
2,474 Views
12 Replies
Message 1 of 13

Show/Hide JointOrigin

jonrbloom
Advocate
Advocate

Is there an equivalent to isLightBulbOn for JointOrigins? I see this for other objects, but JointOrigins appear to be visible by default when created through the API, and there's no obvious way to hide them.

0 Likes
Accepted solutions (2)
2,475 Views
12 Replies
Replies (12)
Message 2 of 13

kandennti
Mentor
Mentor
Accepted solution

Hi @jonrbloom .

 

After trying various things, I was able to switch in this way.

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des  :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # First JointOrigin
        jointOrigin = root.allJointOrigins[0]

        # Switching Show/Hide
        SwitchingLight(jointOrigin)

        _ui.messageBox('Done')
        
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


# Switching Show/Hide
def SwitchingLight(item :adsk.core.Base):
    app = adsk.core.Application.get()
    ui = app.userInterface

    sels = ui.activeSelections
    sels.clear()
    sels.add(item)

    txtCmd = u'Commands.Start VisibilityToggleCmd'
    # txtCmd = u'Commands.Start CAMVisibilityToggleCmdDef' #OK
    # txtCmd = u'Commands.Start ShowHideBodyCmd' #OK
    app.executeTextCommand(txtCmd)

    sels.clear()

However, I didn't know how to judge Show / Hide.

0 Likes
Message 3 of 13

jonrbloom
Advocate
Advocate

@kandennti - That's thinking out of the box 🙂 Thank you for taking the time to experiment with this.

 

Your solution does work, but only if the JointOrigin is obtained from the root component context.

 

I'm still a newbie with the API. Is there an easy way to convert a JointOrigin (or any of the other objects for that matter) obtained from a sub-component into it's corresponding root context? I can use a brute force search to find it by iterating over the roots allJointOrigins, but am hoping there's a more direct method to do this?

 

0 Likes
Message 4 of 13

kandennti
Mentor
Mentor

Just put JointOrigin in the parameter of the SwitchingLight function and it should work.

However, this is useless because it cannot be determined whether it is displayed or hidden.

0 Likes
Message 5 of 13

MichaelT_123
Advisor
Advisor

Hi Fellows,

It seems that the issue is still ringing...

FYI:

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/jointorigin-isvisible/td-p/9306477

Regards

MichaelT

MichaelT
Message 6 of 13

kandennti
Mentor
Mentor

Thank you @MichaelT_123 .


There was a problem from the past.
I've tried various things, but I can't find a solution.

0 Likes
Message 7 of 13

jonrbloom
Advocate
Advocate

@kandennti  - I did try your example. But it only worked if I obtain the JointOrigin drirectly from the rootComponent. If I create a sub-component, adding a JointOrigin as I go to that sub-component, the created JointOrigin is rejected by the sels.add() call.

 

It seems I can only add entities obtained from the rootComponent to activeSelections.

0 Likes
Message 8 of 13

jonrbloom
Advocate
Advocate

@kandennti  - I should add, that I don't think your solution is useless at all. As it stands my script assumes a blank design, so all JointOrigins are new, and guaranteed to be visible. Even without the per-component toggling, this is far better than leaving lots of ugly warts over the final model.

 

So thank you for the help 🙂

 

But it would be nice if this does get fixed eventually, as per @MichaelT_123's thread. Fingers crossed.

0 Likes
Message 9 of 13

kandennti
Mentor
Mentor
Accepted solution

@jonrbloom .

 

I didn't understand the proxy.
I referred to the @BrianEkins sample.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/cannot-select-object-in-component-using-ac... 

 

The following sample creates a Box in RootComponent and Occurrence and hides the jointOrigin created at the vertex.

 

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # create document
        _app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # --- try root ---
        # create box
        box = createBox(root, adsk.core.Point3D.create(0.0, 0.0, 0.0))

        # create jointOrigin
        jointOrigins = createJointOriginList(box, root)

        # jointOrigin Hide
        [SwitchingLight_JointOrigin(o) for o in jointOrigins]

        # --- try occurrence ---
        # create occurrence
        matZero = adsk.core.Matrix3D.create()
        occ :adsk.fusion.Occurrence = root.occurrences.addNewComponent(matZero)

        # create box
        box = createBox(occ.component, adsk.core.Point3D.create(20.0, 0.0, 0.0))

        # create jointOrigin
        jointOrigins = createJointOriginList(box, occ.component)

        # jointOrigin Hide
        [SwitchingLight_JointOrigin(o) for o in jointOrigins]
        

        # finish
        _ui.messageBox('Done')
        
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def createJointOriginList(
    box :adsk.fusion.BRepBody,
    comp :adsk.fusion.Component
    ) -> list:

    jointGeo = adsk.fusion.JointGeometry
    jointGeos = [jointGeo.createByPoint(p) for p in box.vertices]
    originIpts = [comp.jointOrigins.createInput(p) for p in jointGeos]
    return [comp.jointOrigins.add(ipt) for ipt in originIpts]

def createBox(
    comp :adsk.fusion.Component,
    pnt :adsk.core.Point3D
    ) -> adsk.fusion.BRepBody:

    vec3D = adsk.core.Vector3D
    lVec = vec3D.create(1.0, 0.0, 0.0)
    wVec= vec3D.create(0.0, 1.0, 0.0)

    bouBox3D = adsk.core.OrientedBoundingBox3D
    box = bouBox3D.create(pnt, lVec, wVec, 10, 10, 10)

    tmpBrMgr = adsk.fusion.TemporaryBRepManager.get()

    baseFeats = comp.features.baseFeatures
    baseFeat = baseFeats.add()
    baseFeat.startEdit()
    cube :adsk.fusion.BRepBody = comp.bRepBodies.add(tmpBrMgr.createBox(box),baseFeat)
    baseFeat.finishEdit()

    return cube

# Switching Show/Hide JointOrigin
def SwitchingLight_JointOrigin(
    jointOrigin :adsk.fusion.JointOrigin):

    app :adsk.core.Application = adsk.core.Application.get()
    ui :adsk.core.UserInterface = app.userInterface
    des :adsk.fusion.Design = app.activeProduct
    root :adsk.fusion.Component = des.rootComponent

    comp :adsk.fusion.Component = jointOrigin.parentComponent

    sels :adsk.core.Selections = ui.activeSelections
    sels.clear()

    occs :adsk.fusion.OccurrenceList = root.allOccurrencesByComponent(comp)
    if occs.count < 1:
        # root
        sels.add(jointOrigin)
    else:
        # occ
        proxy :adsk.fusion.JointOrigin = jointOrigin.createForAssemblyContext(occs[0])
        sels.add(proxy)

    txtCmd = u'Commands.Start VisibilityToggleCmd'
    # txtCmd = u'Commands.Start CAMVisibilityToggleCmdDef' #OK
    # txtCmd = u'Commands.Start ShowHideBodyCmd' #OK
    app.executeTextCommand(txtCmd)

    sels.clear()

 

Pass the new JointOrigin to the SwitchingLight_JointOrigin function and it should be hidden. 

Message 10 of 13

jonrbloom
Advocate
Advocate

This works, and helped me understand the proxy concept better too. Thanks.

0 Likes
Message 11 of 13

MichaelT_123
Advisor
Advisor

Hi Fellows,

 

Just to let you know.

jointOrigin.isVisible = True/False

works!

 

Regards

MichaelT

 

MichaelT
Message 12 of 13

jonrbloom
Advocate
Advocate

It looks like isVisible is intended to be read-only. And recent changes are locking that down to return an error for such properties. If it is still working today I would be wary of relying on this.


@MichaelT_123 wrote:

Hi Fellows,

 

Just to let you know.

jointOrigin.isVisible = True/False

works!

 

Regards

MichaelT

 


 

0 Likes
Message 13 of 13

MichaelT_123
Advisor
Advisor

Hi Mr JonRBloom,

As per this thread and perhaps other posts related to the issue, the problem one would consider quite simple is not new.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/jointorigin-isvisible/td-p/9306477

I don't know how you are familiar with API and its development (or changes) over the years.

Let's look at this particular trivial case of visibility of an icon marking visibility of browser members (including jointOrigin).

If you study API documentation, you will find that this property can be set or/and get using two properties isVisible and isLightBulbOn. On top, there are also (added not long time ago group properties like for example isJointsFolderLightBulbOn.

It seems that during the software development life, there were two competing parties in not necessarily well-synchronized teams.

One party I would call Visi_Cratic and other GE_Cratic (short for LightBulbOn_Cratic).

There was also the vicious battle about the colour of the respective icon.

isVisible parameter is sometime settable & gettable and, on other occasions, only gettable. It is hard to devise the pattern here (perhaps the research of the phenomena could lead to a high degree in Methods Of Software Development Department at Esteemed University)

 isLightBulbOn seems to be set/get/able.

So about your concern: 'If it is still working today, I would be wary of relying on this.'

I agree I can't predict the outcome when I pick my nose. Predicting what will happen when F360 digs into the problem is much, much harder, perhaps impossible.

Regards

MichaelT

PS.

As jointOrigin.isVisible = True/False seems to work now, it is still not documented. (checked couple days ago)

MichaelT
0 Likes