Revolve Feature, invalid profile but works great manualy

Revolve Feature, invalid profile but works great manualy

masounmardini
Contributor Contributor
571 Views
1 Reply
Message 1 of 2

Revolve Feature, invalid profile but works great manualy

masounmardini
Contributor
Contributor

Hello Everybody,

Can someone find where is my error in this code I got an invalid profile but running in manual mode works well!!!

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

def run(context):
    ui = None
    try: 
            app = adsk.core.Application.get()
            ui = app.userInterface
            design = app.activeProduct
            rootComp = design.rootComponent
            _id = 1
            _od = 2
            _T = 0.01
            _f = 0.03
            sketches = rootComp.sketches
            center = adsk.core.Point3D.create(0, 0, 0)
            xyPlane = rootComp.xYConstructionPlane
            xzPlane = rootComp.xZConstructionPlane
            
            headSketch = sketches.add(xzPlane)
            
            point1 = adsk.core.Point3D.create(center.x + (_id/2), -center.z, center.y)
            point2 = adsk.core.Point3D.create(center.x + (_id/2)  + (_T /math.sin(math.pi/3) ) , -center.z , center.y )
            point3 = adsk.core.Point3D.create(center.x + (_od/2), -center.z , center.y)
            point4 = adsk.core.Point3D.create(center.x + (_od/2) - _T , -center.z , center.y)
            arc1 = headSketch.sketchCurves.sketchArcs.addByCenterStartSweep(point1, point3, -math.pi/3)
            line1 = headSketch.sketchCurves.sketchLines.addByTwoPoints(arc1.startSketchPoint,point1)
            arc2 = headSketch.sketchCurves.sketchArcs.addByCenterStartSweep(point2, point4, -math.pi/3)
            line2 = headSketch.sketchCurves.sketchLines.addByTwoPoints(arc2.startSketchPoint,point2)
            headSketch.sketchCurves.sketchLines.addByTwoPoints(point1,point2)
            headSketch.sketchCurves.sketchLines.addByTwoPoints(point3,point4)
            farc1 = headSketch.sketchCurves.sketchArcs.addFillet(line1, line1.startSketchPoint.geometry, arc1, arc1.startSketchPoint.geometry, _f)
            farc2 = headSketch.sketchCurves.sketchArcs.addFillet(line2, line2.startSketchPoint.geometry, arc2, arc2.startSketchPoint.geometry, _f)
            prof = headSketch.profiles.item(0)
            axis_p1 =  adsk.core.Point3D.create(center.x , -center.z, center.y)
            axis_p2 =  adsk.core.Point3D.create(center.x , -center.z - 1  , center.y)
            lines = headSketch.sketchCurves.sketchLines
            axis_line = lines.addByTwoPoints(axis_p1,axis_p2)
            
            revolves = rootComp.features.revolveFeatures
            revInput1 = revolves.createInput(prof, axis_line, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
            revAngle = adsk.core.ValueInput.createByReal( 2 * math.pi)
            revInput1.setAngleExtent(False,revAngle)
            revBody = revolves.add(revInput1)
    except:
            if ui:
               ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 I get this error

masounmardini_0-1599492354181.png

while selecting the profile again works perfectly

masounmardini_1-1599492475211.png

What am I missing here????

 

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

masounmardini
Contributor
Contributor
Accepted solution

Hi Guys,

I was a little impatient, the problem was the profile definition was a little bit early it must come after adding the centerline, then it will be correctly used.

 

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

def run(context):
    ui = None
    try: 
            app = adsk.core.Application.get()
            ui = app.userInterface
            design = app.activeProduct
            rootComp = design.rootComponent
            _id = 1
            _od = 2
            _T = 0.01
            _f = 0.03
            sketches = rootComp.sketches
            center = adsk.core.Point3D.create(0, 0, 0)
            xyPlane = rootComp.xYConstructionPlane
            xzPlane = rootComp.xZConstructionPlane
            
            headSketch = sketches.add(xzPlane)
            
            point1 = adsk.core.Point3D.create(center.x + (_id/2), -center.z, center.y)
            point2 = adsk.core.Point3D.create(center.x + (_id/2)  + (_T /math.sin(math.pi/3) ) , -center.z , center.y )
            point3 = adsk.core.Point3D.create(center.x + (_od/2), -center.z , center.y)
            point4 = adsk.core.Point3D.create(center.x + (_od/2) - _T , -center.z , center.y)
            arc1 = headSketch.sketchCurves.sketchArcs.addByCenterStartSweep(point1, point3, -math.pi/3)
            line1 = headSketch.sketchCurves.sketchLines.addByTwoPoints(arc1.startSketchPoint,point1)
            arc2 = headSketch.sketchCurves.sketchArcs.addByCenterStartSweep(point2, point4, -math.pi/3)
            line2 = headSketch.sketchCurves.sketchLines.addByTwoPoints(arc2.startSketchPoint,point2)
            headSketch.sketchCurves.sketchLines.addByTwoPoints(point1,point2)
            headSketch.sketchCurves.sketchLines.addByTwoPoints(point3,point4)
            farc1 = headSketch.sketchCurves.sketchArcs.addFillet(line1, line1.startSketchPoint.geometry, arc1, arc1.startSketchPoint.geometry, _f)
            farc2 = headSketch.sketchCurves.sketchArcs.addFillet(line2, line2.startSketchPoint.geometry, arc2, arc2.startSketchPoint.geometry, _f)
            
            axis_p1 =  adsk.core.Point3D.create(center.x , -center.z, center.y)
            axis_p2 =  adsk.core.Point3D.create(center.x , -center.z - 1  , center.y)
            lines = headSketch.sketchCurves.sketchLines
            
            axis_line = lines.addByTwoPoints(axis_p1,axis_p2)
            prof = headSketch.profiles.item(0)
            
            revolves = rootComp.features.revolveFeatures
            revInput1 = revolves.createInput(prof, axis_line, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
            revAngle = adsk.core.ValueInput.createByReal( 2 * math.pi)
            revInput1.setAngleExtent(False,revAngle)
            revBody = revolves.add(revInput1)
    except:
            if ui:
               ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes