- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'd like to have my program take in user input, create an F360 Parameter from that input, use that parameter to create a sketch (all of this is already done) then give the user the ability to change the parameters retroactively and have the model update to the new values as they are modified.
The simplest example of this in action would be a script that asks for the radius of a circle then creates a sketch where that parameter and updates drive the radius as the parameter is changed. The ability to use parameters when making sketches is a fundamental feature of F360 when using the typical GUI, so it would make sense to me that the API would allow it. I've written an example script like this, but the radius of the circle does not change when the user retroactively changes the radius parameter (like it would if a user parameter was created and then used to define the radius of a circle in the GUI).
#Author - Jake Birkmaier
#Description- Example for forum of an API created Parametric sketch
#Goal - To have the radius change after the script is ran when the user changes the 'radius' param
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
#Create an Input Circle Variable and Pull the input
inputCircleRadius = ui.inputBox('Enter Radius','Radius Input Circle','5 mm')
inputCircleRadiusValue = inputCircleRadius[0]
#Creating variables for the parameter
paramRadiusName = 'Radius'
paramRadiusUnit = 'mm'
paramValueInput = adsk.core.ValueInput.createByReal(5)
#Creating the actual parameter
paramRadius = design.userParameters.add(paramRadiusName,paramValueInput,paramRadiusUnit,'')
#Grabbing the Root Component
compRoot = design.rootComponent
#Create a new sketch on the Xy Plane
sketches = compRoot.sketches
xy_plane = compRoot.xYConstructionPlane
sketch = sketches.add(xy_plane)
#Create the circle trying to use the parameter.
sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0),paramRadius.value)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Use case: have been working on an Add-In for the past few years that takes user inputs and creates various stair flights (see accompanying picture). This has worked very well for me and has helped me save a ton of time for my business and hopefully will help me scale in the future as I can have other employees use the tool. I initially designed the whole add-in to work in a direct modeling environment, since it seemed easier to code for at the time. After testing the program extensively in the field, I realize the huge advantages of parametric modeling, and would really like to integrate it into the tool that I've created.
My Eventual goal is to group the entire make-flight operation into a singular base feature with the ability to retroactively change parameters just like you would be able to for any other tool in F360.
If I could just understand how to make a cylinder with a parameter-based radius in the API, I think I should be able to apply that concept to what I currently have.
I would greatly appreciate any help!
Solved! Go to Solution.