Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

findEntityByToken on occ.component

m0d0
Contributor

findEntityByToken on occ.component

m0d0
Contributor
Contributor

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?

 

 

0 Likes
Reply
Accepted solutions (1)
1,001 Views
1 Reply
Reply (1)

BrianEkins
Mentor
Mentor
Accepted solution

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
0 Likes