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: 

Import multiple sketches and revolve each

0 REPLIES 0
Reply
Message 1 of 1
panajotovic
184 Views, 0 Replies

Import multiple sketches and revolve each

Hi,

 

It's my first time using the Fusion API and I am struggling with it. I am using Windows 10 and Python. I want to import multiple splines into the Fusion (which currently works nicely with the "ImportSplineCSV" sample script or "ImportCSVPoints" Add-In by hanskellner. After importing the splines, I want to create closed profiles with them and revolve each profile around the same axis. Here is how it looks like the UI: 

 

panajotovic_0-1627633750748.pngThat's simple, but I would like to automate it since I will need to import dozens of splines at a later point and revolve each in the same manner. As many similar examples, I tried modding the "ImportSplineCSV" sample code to first batch import all three splines as .csv files as done in this thread (https://forums.autodesk.com/t5/fusion-360-api-and-scripts/trouble-with-batch-import-and-loft-of-csv-...

 

 

 sketches = []

for i in range(0, 3):  
filename = "C:/.../df_vis_{}.csv".format(i)        
        
   with io.open(filename, 'r', encoding='utf-8-sig') as f:         
      points = adsk.core.ObjectCollection.create()  
      line = f.readline() 
      data = []                                                  
         while line:
            pntStrArr = line.split(',')
            for pntStr in pntStrArr:  
               try:
                  data.append(float(pntStr))
               except:
                  break
            if len(data) >= 3 :                                                 
               point = adsk.core.Point3D.create(data[0], data[1], data[2])     
               points.add(point)                                                               
            line = f.readline()
            data.clear()

   if points.count:
      root = design.rootComponent
      sketch = root.sketches.add(root.xYConstructionPlane)
      sketch.sketchCurves.sketchFittedSplines.add(points)   
      sketches.append(sketch) 
   else:
      ui.messageBox('No valid points', title)  

 

This works well enough and I am able to import all three splines simultaneously. However, I am unsure how to create closed profiles from these splines using python API as I did manually on the middle image above. Once that is done, I would use the following piece of code to create the revolved solid body from each profile:

# Creating profiles from the imported splines

profiles = adsk.core.ObjectCollection.create()
for profile in sketch.profiles:
   profiles.add(profile)

# Revolve each profile around the X axis
revolves = root.features.revolveFeatures
input = revolves.createInput(profiles, sketch.sketchCurves.sketchLines.item(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
input.setAngleExtent(True, adsk.core.ValueInput.createByString('360 deg'))    
revolves.add(input)

Can someone point me in the right direction on how to create these closed profiles from imported splines? 

 

Another more general question: I would like Fusion to print imported points (like I would print contents of a list or data frame in VSCode terminal). Is this possible and if yes how?

 

Thank you in advance!

 

Stefan

 

 

Labels (3)
0 REPLIES 0

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