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: 

Problem with Deleting Attributes

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
VitautTryputsin
398 Views, 4 Replies

Problem with Deleting Attributes

Hello. I have a problem with deleting attributes. I create custom class. It contain a list of BrepFaces Objetcs inside. I add to face an attribute, then i add this face to the list of faces. If i delete attribute from face from list later, brepFace in model still contains this attribut, but face in list - not. Why it occurs?

 

Python code:

add attribute function:

def setAttributeToFaceInModelByName ( pFace, pName):
    retCode=checkEFAttributes(pFace)
    if retCode != EFErrorNotFindAttributes: return retCode
    pFace.attributes.add(EFAttributeGroupName,pName,'1')
    return EFIsOK

Remove attributes function:

 

def removeEFAttributes(pFace):
    retCode=checkBrepface(pFace)
    if retCode != EFIsOK: return retCode
    if pFace.attributes.itemsByGroup(EFAttributeGroupName): 
        attributes = pFace.attributes.itemsByGroup(EFAttributeGroupName)
        for pAttib in attributes:
            pAttib.deleteMe()
    return EFIsOK 

 

4 REPLIES 4
Message 2 of 5
liujac
in reply to: VitautTryputsin

Hi,

 

I can’t reproduce the problem with the script below. Could you provide more info? How do you get the faces? That would be better if you can provide the runnable script and the model file.

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        face = design.rootComponent.bRepBodies[0].faces[0]
        face.attributes.add("GroupName", "Name", '1')
        ui.messageBox("face.attributes.count: " + str(face.attributes.count))
        
        attributes = face.attributes.itemsByGroup("GroupName")
        for attrib in attributes:
            attrib.deleteMe()
        ui.messageBox("face.attributes.count: " + str(face.attributes.count))

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

 

Thanks,

Jack

Message 3 of 5
VitautTryputsin
in reply to: liujac

I try add or delete Attributes in CommandInputChangedHandler (adsk.core.InputChangedEventHandler), when i click button "add" or "delete".

Attributes add or delete to faces succesfully. I check it in console. If I close CommandInput window, changes is missing. Faces not get new Attributes or not delete old Attributes.

 

Message 4 of 5
liujac
in reply to: VitautTryputsin

I recommend you make the changes in Execute event. We only commit the changes made in Execute event. The changes made in other command events like InputChanged event just are preview and aborted right away.

 

For more information about Fusion Commands, please read http://fusion360.autodesk.com/learning/learning.html?guid=GUID-3922697A-7BF1-4799-9A5B-C8539DF57051.

 

Thanks,

Jack

Message 5 of 5

Thank you. It work in Execute event.

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