Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

openprofile loft help needed!

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
gabor.balint
218 Views, 2 Replies

openprofile loft help needed!

Hello Everyone,

I'm very new to python and scripting, and I have a goal. I want to create a surface loft, using 2 sketches. Later on, I want to create more complex things, but I'm unable to make the loft, and I have no idea why. Can someone tell me what I'm doing wrong and why?

 

Here's what the end result should look like:

Screen Shot 2018-02-05 at 15.41.29.png

Here's my code:

import adsk.core, adsk.fusion

app = adsk.core.Application.get()
ui = app.userInterface
        
design = app.activeProduct

# Get the root component of the active design.
rootComp = design.rootComponent

######

# Create a new sketch on the xy plane.
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(xyPlane)

# Create an object collection for the points.
points = adsk.core.ObjectCollection.create()  

Steps = 10 #How many fibonacci steps to go through
R = Steps - 2

points.add(adsk.core.Point3D.create(0, 0, 0)) # This plots the origin


Bin1 = range(0, R, 2)
Bin2 = range(1, R, 2)

xCoord = 0
yCoord = 0
hossz = 1

for i in range(R):

    if i in Bin1:
        xCoord = xCoord
        yCoord = yCoord + hossz
        points.add(adsk.core.Point3D.create(xCoord, yCoord, 0))

    if i in Bin2:
        xCoord = xCoord + hossz
        yCoord = yCoord
        points.add(adsk.core.Point3D.create(xCoord, yCoord, 0))


# Create the spline.
spline1 = sketch.sketchCurves.sketchFittedSplines.add(points)


#create second sketch
planes = rootComp.constructionPlanes
        
####        # Create construction plane input

planeInput = planes.createInput()
        
        # Add construction plane by offset
offsetValue = adsk.core.ValueInput.createByReal(5.0)
planeInput.setByOffset(rootComp.xYConstructionPlane, offsetValue)
planeOne = planes.add(planeInput)

sketch2 = rootComp.sketches
offsetplane = planeOne
sketch = sketch2.add(offsetplane)

lines = sketch.sketchCurves.sketchLines;
line1 = lines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(4, 4, 0))


########LOFT

openProfile1 = rootComp.createOpenProfile(spline1)
openProfile2 = rootComp.createOpenProfile(line1)


 # Create loft feature input
loftFeats = rootComp.features.loftFeatures
loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
loftSectionsObj = loftInput.loftSections
loftSectionsObj.add(openProfile1)
loftSectionsObj.add(openProfile2)
loftInput.isSolid = False

# Create loft feature
loftFeats.add(loftInput)

Thanks in advance!

2 REPLIES 2
Message 2 of 3
marshaltu
in reply to: gabor.balint

Hello,

 

Unfortunately it was API bug and logged as UP-38138 in our internal system. A workaround for you is as below:

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface
            
    design = app.activeProduct
    
    # Get the root component of the active design.
    rootComp = design.rootComponent
    
    ######
    
    # Create a new sketch on the xy plane.
    sketches = rootComp.sketches
    xyPlane = rootComp.xYConstructionPlane
    sketch = sketches.add(xyPlane)
    
    # Create an object collection for the points.
    points = adsk.core.ObjectCollection.create()  
    
    Steps = 10 #How many fibonacci steps to go through
    R = Steps - 2
    
    points.add(adsk.core.Point3D.create(0, 0, 0)) # This plots the origin
    
    
    Bin1 = range(0, R, 2)
    Bin2 = range(1, R, 2)
    
    xCoord = 0
    yCoord = 0
    hossz = 1
    
    for i in range(R):
    
        if i in Bin1:
            xCoord = xCoord
            yCoord = yCoord + hossz
            points.add(adsk.core.Point3D.create(xCoord, yCoord, 0))
    
        if i in Bin2:
            xCoord = xCoord + hossz
            yCoord = yCoord
            points.add(adsk.core.Point3D.create(xCoord, yCoord, 0))
    
    
    # Create the spline.
    spline1 = sketch.sketchCurves.sketchFittedSplines.add(points)
    
    
    #create second sketch
    planes = rootComp.constructionPlanes
            
    ####        # Create construction plane input
    
    planeInput = planes.createInput()
            
            # Add construction plane by offset
    offsetValue = adsk.core.ValueInput.createByReal(5.0)
    planeInput.setByOffset(rootComp.xYConstructionPlane, offsetValue)
    planeOne = planes.add(planeInput)
    
    sketch2 = rootComp.sketches
    offsetplane = planeOne
    sketch = sketch2.add(offsetplane)
    
    lines = sketch.sketchCurves.sketchLines;
    line1 = lines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(4, 4, 0))
    
    
    ########LOFT
    
    openProfile1 = adsk.fusion.Path.create(spline1, adsk.fusion.ChainedCurveOptions.noChainedCurves)
    openProfile2 = adsk.fusion.Path.create(line1, adsk.fusion.ChainedCurveOptions.noChainedCurves)
    
    
     # Create loft feature input
    loftFeats = rootComp.features.loftFeatures
    loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
    loftSectionsObj = loftInput.loftSections
    loftSectionsObj.add(openProfile1)
    loftSectionsObj.add(openProfile2)
    loftInput.isSolid = False
    
    # Create loft feature
    loftFeats.add(loftInput)
    
    
  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 


Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 3
gabor.balint
in reply to: marshaltu

wow! thank you!! it works now!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report