AttributeError: 'BRepBody' object has no attribute 'bodies'

AttributeError: 'BRepBody' object has no attribute 'bodies'

victoriaN4VP7
Participant Participant
368 Views
1 Reply
Message 1 of 2

AttributeError: 'BRepBody' object has no attribute 'bodies'

victoriaN4VP7
Participant
Participant
I'm trying to have the user select a surface that will then be thickened. I'm able to run the code and select a surface but then I get AttributeError: 'BRepBody' object has no attribute 'bodies'. 
 
 
import adsk.core, adsk.fusion, traceback

def run(context) :
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct
       
        SurfaceSel = ui.selectEntity('select a surface', 'SurfaceBodies')
        if SurfaceSel:
            surface = adsk.fusion.BRepBody.cast(SurfaceSel.entity)
            des = adsk.fusion.Design.cast(app.activeProduct)
            root = des.rootComponent
            ui.messageBox('Pass:\n{}'.format(traceback.format_exc()))

        # Create thicken feature
            thickenFeatures = root.features.thickenFeatures
            inputSurfaces = adsk.core.ObjectCollection.create()
            bodies = surface.bodies
            for body in bodies :
                thickenFeatures.add(body)
            thickness = adsk.core.ValueInput.createByReal(1.0)
            thickenInput = thickenFeatures.createInput(inputSurfaces, thickness, False,  adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
            thickenFeatures.add(thickenInput)

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

 

victoriaN4VP7_0-1673018824534.png

 

0 Likes
Accepted solutions (1)
369 Views
1 Reply
Reply (1)
Message 2 of 2

kandennti
Mentor
Mentor
Accepted solution

Hi @victoriaN4VP7 .

 

Try this.

import adsk.core, adsk.fusion, traceback

def run(context) :
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct
       
        SurfaceSel = ui.selectEntity('select a surface', 'SurfaceBodies')
        if SurfaceSel:
            surfaceBody = adsk.fusion.BRepBody.cast(SurfaceSel.entity)
            des = adsk.fusion.Design.cast(app.activeProduct)
            root = des.rootComponent

        # Create thicken feature
            thickenFeatures = root.features.thickenFeatures
            inputSurfaces = adsk.core.ObjectCollection.create()
            for face in surfaceBody.faces:
                inputSurfaces.add(face)
            thickness = adsk.core.ValueInput.createByReal(1.0)
            thickenInput = thickenFeatures.createInput(
                inputSurfaces,
                thickness,
                False,
                adsk.fusion.FeatureOperations.NewBodyFeatureOperation
            )
            thickenFeatures.add(thickenInput)

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