
Not applicable
09-10-2018
03:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to recreate a helical sweep operation in the API, I want to use a sketch line as the sweep profile to create a helical path on which I can then do a solid sweep along but am having trouble finding out how to perform this patch sweep using the API.
Trying to sweep the sketch line at the top of the construction line through the path to create an offset patch I can twist around the shaft.
Currently working in python, I've attempted to create the sweep but I'm unclear on how to use the patch feature in relation to the sweep feature. The current script is as follows:
# Assign variables - units are in cm pitch_ratio = 0.2456 # use a dictionary for future use, this is a test value screw_radius = 100 shaft_radius = 50 screw_angle_deg = 22 screw_angle = math.degrees(screw_angle_deg) head = 200 screw_length = (head + screw_radius) / math.sin(screw_angle) pitch = ((2*math.pi*pitch_ratio) / math.tan(screw_angle)) * screw_radius
revolutions = screw_length / pitch twist_angle = revolutions * 360 print('Variables Assigned:\nScrew Radius = %s m\nShaft Radius = %s m\nScrew Length = %s m\nTwist Angle = %s°\n' % (screw_radius/100, shaft_radius/100, screw_length/100, twist_angle)) # Document setup
app = adsk.core.Application.get() ui = app.userInterface design = app.activeProduct # Get the root component of the design and create a sub component rootComp = design.rootComponent newOcc = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) screwComp = newOcc.component screwComp.name = 'Archimedean Hydroscrew' shaftOcc = screwComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) shaftComp = shaftOcc.component shaftComp.name = 'Shaft' bladeOcc = screwComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) bladeComp = bladeOcc.component bladeComp.name = 'Blades'
# Create a sketch on xy (Front) and yz (Right) planes of the screw sub component sketches = screwComp.sketches shaft_sketches = shaftComp.sketches blade_sketches = bladeComp.sketches xyPlane = screwComp.xYConstructionPlane yzPlane = screwComp.yZConstructionPlane shaft_profile_sketch = shaft_sketches.add(xyPlane) shaft_profile_sketch.name = 'Shaft Profile' screw_path_sketch = sketches.add(xyPlane) screw_path_sketch.name = 'Screw_Path' # Draw the shaft profile and the screw path shaft_profile_circles = shaft_profile_sketch.sketchCurves.sketchCircles shaft_profile = shaft_profile_circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), shaft_radius) screw_path_line = screw_path_sketch.sketchCurves.sketchLines screw_path = screw_path_line.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 0, screw_length)) # Get the profile defined by the circle shaft_profile_prof = shaft_profile_sketch.profiles.item(0) # Create a path form the screw_path screw_path_path = shaftComp.features.createPath(screw_path) # Create a sweep input shaft_sweeps = shaftComp.features.sweepFeatures shaft_sweep_input = shaft_sweeps.createInput(shaft_profile_prof, screw_path_path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) shaft_sweep_input.taperAngle = adsk.core.ValueInput.createByString('0 deg') shaft_sweep_input.twistAngle = adsk.core.ValueInput.createByString('0 deg') # Create the sweep shaft_sweep = shaft_sweeps.add(shaft_sweep_input) # Create a construction plane at the start of the path path_plane = screwComp.constructionPlanes path_plane_input = path_plane.createInput() distance = adsk.core.ValueInput.createByReal(0.0) path_plane_input.setByDistanceOnPath(screw_path, distance) path_plane.add(path_plane_input) # Create a 1D profile for a patch blade_patch_sketch = blade_sketches.add(xyPlane) blade_patch_sketch.name = 'Blade Patch Profile' blade_patch_line = blade_patch_sketch.sketchCurves.sketchLines blade_patch_offset = blade_patch_line.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, screw_radius, 0)) blade_patch_offset.isConstruction = True blade_patch_profile = blade_patch_line.addByTwoPoints(adsk.core.Point3D.create(0, screw_radius, 0), adsk.core.Point3D.create(0, screw_radius + 0.01, 0)) # Sweep a blade in the patch workspace - this part is not working patch_sweeps = bladeComp.features.sweepFeatures patch_prof = blade_patch_sketch.profilecurve.item(0) patch_input = patch_sweeps.createInput(patch_prof, screw_path_path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) patch_input.taperAngle = adsk.core.ValueInput.createByString('0 deg') patch_input.twistAngle = adsk.core.ValueInput.createByReal(twist_angle) patch_input.isSolid = False patch_sweep = patch_sweeps.add(patch_input)
At the moment, the script produces this error:
Currently getting this error.
Can anyone help with this?
Cheers,
Jack
Solved! Go to Solution.