Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

findEntityByToken on occ.component

1 REPLY 1
SOLVED
Reply
Message 1 of 2
m0d0
637 Views, 1 Reply

findEntityByToken on occ.component

Hi all,

 

I realised, that when trying to get a component with the findByentityToken it returns an occurrence object of this component instead of the component itself. This happens only when using occurrence.component.entityToken for generating the entityToken.

This is the code to reproduce:

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)

        occ = ui.selectEntity('select Occurrence','Occurrences').entity
        comp = occ.component

        ui.messageBox(comp.classType())

        token = comp.entityToken
        entitiesByToken = des.findEntityByToken(token)
        
        ui.messageBox(str([entity.classType() for entity in entitiesByToken]))

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

If you use design.allComponents to access the component and generating the token, design.findEntityByToken will return a component as exspected.

 

I know that I can simply use occ.component on the returned occurrence but I am still wondering about this behavior. Will this always work? Whats the reason for this distinction?

 

 

Labels (2)
1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: m0d0

This is a bug and needs to be fixed.  A bug has been logged.  Thanks for reporting it.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report