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: 

Can the Fusion 360 API create a fixed ID for each edge and face?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
2544173825
203 Views, 4 Replies

Can the Fusion 360 API create a fixed ID for each edge and face?

The face.tempId of the Fusion 360 API allows to go past the Id of a BRep entity, but this Id seems to be affected by the traversal method. To be precise this tempId is more like a order number to get the tempId. For example, for the same part, I get the tempId of an edge first, edge_Id = edge.tempId, at this time id=0 is an edge, but for the same geometry, if I get the tempId of a face first next time, face_Id = face.tempId, at this time id=0 is a face. Is there a way so that I can set (get) the Id of each face (edge) entity, and the acquired face (edge) entity Id is fixed regardless of the method used to parse the geometry.

4 REPLIES 4
Message 2 of 5
kandennti
in reply to: 2544173825

Hi @2544173825 .

 

I think tempId is outdated and entityToken should be used now.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-D9458206-A7FA-4371-94BA-636FE58F225C 

 

The following sample shows an entityToken when a face or edge is selected.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

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

        msg: str = 'Select Face or Edge'
        selFilter: str = 'Faces,Edges'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        selectEntity = sel.entity

        msgList = []
        selectEntity_token = selectEntity.entityToken
        msgList.append(f'EntityToken:{selectEntity_token}\n')

        msgList.append(f'SelectEntity Type:{selectEntity.classType()}\n')

        findEntities = des.findEntityByToken(selectEntity_token)
        if len(findEntities) > 0:
            msgList.append(f'FindEntity Type:{findEntities[0].classType()}\n')
        ui.messageBox('\n'.join(msgList))

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

def selectEnt(
        msg: str,
        filterStr: str) -> adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None

 

I haven't looked into it in detail, but moving the timeline marker should not change the entityToken for elements that are basically unchanged.
However, I am also having trouble understanding the rules by which the entityToken is changed.

Message 3 of 5
2544173825
in reply to: kandennti

Thanks for your prompt reply, I'll go try what you said!

Message 4 of 5
BrianEkins
in reply to: 2544173825

Entity tokens and temp ID's are both valid ways of uniquely identifying a B-Rep entity but they each have their own advantages and disadvantages and one is typically more appropriate than the other for a specific use case. The more generally useful of the two is entity tokens because they will continue to work across sessions and when the model changes. The downside of entity tokens is they are expensive for Fusion to generate and they are much larger to store. Internally, a token is much more than a simple ID. It's more accurate to think of it as a description of how to find a particular entity. Tokens are also supported by almost everything that is saved.

 

The big advantage of temp ID's is that they are fast and small. Their disadvantages are that they are only supported by B-Rep objects and their lifetime is as long as the body remains unchanged in any way. There are probably a lot of unique uses for temp ID's but the one I'm more familiar with is for an internal Autodesk project. In this case, the body is exported as an SMT file and read into another system. The temp ID's are carried with the SMT file and provide a way to do geometry matching between the two models to transfer additional information. Remember, these ID's only work as long as the model is not changed, so it's not a long-term connection but is only used during the initial transfer.

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 5
2544173825
in reply to: BrianEkins

Thanks!

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