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

thicken feature body appears in Root-Component instead in NewComponent

adminTCYL2
Enthusiast

thicken feature body appears in Root-Component instead in NewComponent

adminTCYL2
Enthusiast
Enthusiast

The following skript creates a new component. There it revolves a curve (witch is done by math) into a surface. 
The surface appears as a new body in the component. 
Then the skript thickens this surface to a solid. This new body appears in the Root-Component. 
But can someone tell me why?

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

def run(context):
    ui = None
    try:
        d = 3
        width = 1
        height = 2
        vase = 0.5
        pointsOnLine = 48
        points = adsk.core.ObjectCollection.create()
        for t in range(12, 37):
            circ = 2*math.pi*t/(pointsOnLine)
            cosWind = math.cos(circ)
            sinWind = math.sin(circ)
            vas  = vase * math.cos(circ*2)*sinWind
            y= height*sinWind
            x= math.cos(0) * (d+ width*cosWind -vas)
            z= math.sin(0) * (d+ width*cosWind -vas)

            point = adsk.core.Point3D.create(x, y, z)
            points.add(point)

        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        rootComp = design.rootComponent
        # create new component
        newOcc1 = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        revComp = newOcc1.component
        revComp.name = 'Revolved_Body'
        sketches = revComp.sketches
        xzPlane = revComp.xZConstructionPlane
        sketch0 = sketches.add(xzPlane)
        lineA = sketch0.sketchCurves.sketchFittedSplines.add(points)

        prof = revComp.features.createPath(lineA, False)
        revolves = revComp.features.revolveFeatures
        zAxis = revComp.zConstructionAxis
        revInput1 = revolves.createInput(prof, zAxis, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        revInput1.isSolid = False
        revAngle = adsk.core.ValueInput.createByReal( 2 * math.pi)
        revInput1.setAngleExtent(False,revAngle)
        revBody = revolves.add(revInput1)
        
        thickenFeatures = revComp.features.thickenFeatures
        inputSurfaces = adsk.core.ObjectCollection.create()
        bodies = revBody.bodies
        for body in bodies :
            inputSurfaces.add(body)
        thicknes = adsk.core.ValueInput.createByReal(0.5)
        thickenInput = thickenFeatures.createInput(inputSurfaces, thicknes, False,  adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        thickenFeatures.add(thickenInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Reply
Accepted solutions (1)
590 Views
6 Replies
Replies (6)

kandennti
Mentor
Mentor

Hi @adminTCYL2 .

 

I tried with Ver. 2.0.10446.

It did not work correctly here either.

・・・
        thickenFeatures = revComp.features.thickenFeatures
        inputSurfaces = adsk.core.ObjectCollection.create()
        bodies = revBody.bodies
        for body in bodies :
            occBody = body.createForAssemblyContext(newOcc1)
            inputSurfaces.add(occBody)
        thicknes = adsk.core.ValueInput.createByReal(0.5)
・・・

 

It also did not work correctly here.

・・・
        thickenFeatures = revComp.features.thickenFeatures
        inputSurfaces = adsk.core.ObjectCollection.create()
        bodies = newOcc1.bRepBodies
        for body in bodies :
            inputSurfaces.add(body)
        thicknes = adsk.core.ValueInput.createByReal(0.5)
・・・

 

The only thing I could do was to activate it, which gave me the correct result.

・・・
        thickenFeatures = revComp.features.thickenFeatures
        inputSurfaces = adsk.core.ObjectCollection.create()
        bodies = revBody.bodies
        newOcc1.activate()
        for body in bodies :
            inputSurfaces.add(body)
        thicknes = adsk.core.ValueInput.createByReal(0.5)
・・・


This seems like a bug to me.

0 Likes

BrianEkins
Mentor
Mentor

I was also able to reproduce this and it does seem to be a bug.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

adminTCYL2
Enthusiast
Enthusiast

Hi Brian and Kandennti, 
Thank you, for your reply and for the workaround by activating it. But how do I set the activation back after creating the body? rootComp.activate() does not work and rootComp has no occurance that I could activate.  

 

 

0 Likes

adminTCYL2
Enthusiast
Enthusiast
I still not solved the problem, because I can not put the activation back to the root-component:

adsk
.fusion.Occurrence.activate() 
leads to the failure:

TypeError: in method 'Occurrence_activate', argument 1 of type 'adsk::core::Ptr< adsk::fusion::Occurrence > *'

 

app.activeProduct.rootComponent.activate()
Failure:

AttributeError: 'Component' object has no attribute 'activate'

 

app.activeProduct.rootComponent.occurrences[0].activate()
Failure: This activates the first Component, but not the root Component. 
0 Likes

kandennti
Mentor
Mentor
Accepted solution

@adminTCYL2 .

 

To activate the Root Component, use Design.activateRootComponent.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7ef8fb96-1a85-4fc8-9a88-3b94853c30c0 

 

・・・
        bodies = revBody.bodies
        newOcc1.activate()
        for body in bodies :
            inputSurfaces.add(body)
        thicknes = adsk.core.ValueInput.createByReal(0.5)
        thickenInput = thickenFeatures.createInput(inputSurfaces, thicknes, False,  adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        thickenFeatures.add(thickenInput)

        design.activateRootComponent()
・・・

 

0 Likes

adminTCYL2
Enthusiast
Enthusiast

Thanks a lot! this works 🙂

 

0 Likes