Problem with Deleting Attributes

Problem with Deleting Attributes

Anonymous
Not applicable
835 Views
4 Replies
Message 1 of 5

Problem with Deleting Attributes

Anonymous
Not applicable

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 

 

0 Likes
Accepted solutions (1)
836 Views
4 Replies
Replies (4)
Message 2 of 5

liujac
Alumni
Alumni

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

0 Likes
Message 3 of 5

Anonymous
Not applicable

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.

 

0 Likes
Message 4 of 5

liujac
Alumni
Alumni
Accepted solution

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

Anonymous
Not applicable
Thank you. It work in Execute event.
0 Likes