Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Attribute error when trying to select faces vertices

Anonymous

Attribute error when trying to select faces vertices

Anonymous
Not applicable

Hi! 

My current Python script prompts a user to select a face, saves these faces into a variable. Later on, I would like to get coordinates of the vertices of this face and it seems like `vertices` is a property of BRepFace [https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-5e31b969-2cdf-4793-ab06-3dee7de19378]. However, when I run the code I keep getting attribute error.

 

Wondering what is an issue here? Find a script below. 

(side note: before that I had a body being selected by a script and then I could get vertices coordinates using this code `rootComp.bRepBodies.item(body_idx).faces.item(face_idx).vertices.item(vertix_idx).geometry.x`. Why is it an issue now when user selects a face himself?) 

 

 

def run(context):
    ui = None
    try:
        # set up: 
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct

        # ensuring that there is model built & active:
        if not design:
            ui.messageBox('No active Fusion design', 'No Design')
            return
        
        # Get the root component of the active design:
        rootComp = design.rootComponent
        holes = rootComp.features.holeFeatures

        unsafe_faces = [] # [face_ref, which_side, length_x, width_y, height_z] storage for reference to objects

        ### -- Prompting a user to select faces that need to be modified
        user_answer = ui.inputBox("Do you want to specify faces where holes will be placed? Type 'yes', if so \
            \n Otherwise, if you want the program to determine faces for you, type 'no'. \
            \n Please select 'yes' for now [work in progress for 'no']")

        # TODO: 
        # if str(user_answer[0]).strip().lower() == 'no': 
            # TODO: choose the faces for user

        selected_face = ui.selectEntity("Please, choose faces which need better heat dissipation.\
             \n If needed, choose all the faces under the upper case.", 'PlanarFaces')
        ui.messageBox(str(selected_face.vertices.count) # ATTRIBUTE ERROR 
        unsafe_faces.append([selected_face])

 

0 Likes
Reply
Accepted solutions (1)
428 Views
1 Reply
Reply (1)

Anonymous
Not applicable
Accepted solution

Solved the issue by adding one simple word: entity

Last two lines of code:

ui.messageBox(str(selected_face.entity.vertices.count) # ATTRIBUTE ERROR 
        unsafe_faces.append([selected_face.entity])
1 Like