- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on making my metric thread program P_ThreadTune work with English threads. I got most of the code working, but then ran into an accuracy problem with the English threads using the Path Pattern Feature. I seem to be only able to get 3 decimal place accuracy when using the Path Pattern feature within the API. I did not see the problem with metric since the pitch never went past 2 decimal places. With English threads designated as Threads Per Inch, I need more accuracy. I am not having an issue with the accuracy with drawing the helix the correct height or extruding the correct height. I can manually go back through the timeline, edit the Pattern on Path with the correct distance & it will work. So, in Fusion it is working for me, but in the API it is not. Am I doing something incorrectly here? I tried using the createByString method & rectangular pattern also, but I seem to also have another problem there which is probably a conversion problem there between units. I have included a sample program to show the problem & a screen shot. I have units set to "in" when running this sample code. With the .031 I get an overlap but changing it to .03125 it will not. I first thought it might just be the accuracy of the displayed number, but I can change it to .03125 in fusion.
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
# Create a new component
rootComp = design.rootComponent
global subComp1
allOccs = rootComp.occurrences
transform = adsk.core.Matrix3D.create()
occ1 = allOccs.addNewComponent(transform)
subComp1 = occ1.component
sketches = subComp1.sketches
xyPlane = subComp1.xYConstructionPlane
sketch = sketches.add(xyPlane)
# Draw a circle
circles = sketch.sketchCurves.sketchCircles
centerPoint = adsk.core.Point3D.create(0, 0, 0)
circle = circles.addByCenterRadius(centerPoint, 1.0) # 1 inch radius
rev = 33
# Convert inch to mm
TPI = 32 # 32 threads per inch
PitDist = 1 / TPI # 0.03125 Convert to distance between each thread
Ht = (PitDist * 25.4) * .1 # 0.079375 Convert to cm
ui.messageBox(f'PitDist = {PitDist}<br>Ht = {Ht}')
# Draw a vertical centerline
lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(0, 0, 0)
endPoint = adsk.core.Point3D.create(0, 0, Ht * .1) # Scale down to match the sketch's unit
Vert_Line = lines.addByTwoPoints(startPoint, endPoint)
# Create an extrude input
prof = sketch.profiles.item(0)
extrudes = subComp1.features.extrudeFeatures
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
# Define the distance
distance = adsk.core.ValueInput.createByReal(Ht)
extInput.setDistanceExtent(False, distance)
# Create the extrusion
extrudes.add(extInput)
bsubComp1_bodies = subComp1.bRepBodies # Collect the bodies used in our component
numBodies = bsubComp1_bodies.count # Get a count of the bodies used
targetBody = bsubComp1_bodies.item(numBodies-1) # This should be the Nut just drawnf
inputEntites = adsk.core.ObjectCollection.create()
# Create the path pattern
inputEntites.add(targetBody)
path = subComp1.features.createPath(Vert_Line)
patternQuantity = adsk.core.ValueInput.createByReal(rev)
patternDistance = adsk.core.ValueInput.createByReal(Ht)
pathPatterns = subComp1.features.pathPatternFeatures
pathPatternInput = pathPatterns.createInput(inputEntites, path, patternQuantity, patternDistance, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
pathFeature = pathPatterns.add(pathPatternInput) # This seems to only use 3 decimal place accuracy for distance within the API
###########################################################################
# inputEntites.add(targetBody)
# path = subComp1.features.createPath(Vert_Line)
# patternQuantity = adsk.core.ValueInput.createByString(str(rev))
# patternDistance = adsk.core.ValueInput.createByString(str(Ht))
# pathPatterns = subComp1.features.pathPatternFeatures
# pathPatternInput = pathPatterns.createInput(inputEntites, path, patternQuantity, patternDistance, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
# pathFeature = pathPatterns.add(pathPatternInput) # This seems to only use 3 decimal place accuracy for distance within the API
###########################################################################
# Create the rectangular pattern
# xAxis = subComp1.xConstructionAxis
# zAxis = subComp1.zConstructionAxis
# quantityOne = adsk.core.ValueInput.createByString('1') # quantity along X-Axis Not really used
# distanceOne = adsk.core.ValueInput.createByString('1 cm') # distance along X-Axis not really used
# quantityTwo = adsk.core.ValueInput.createByString(str(rev))
# distanceTwo = adsk.core.ValueInput.createByString(str (Ht))
# rectangularPatterns = subComp1.features.rectangularPatternFeatures
# rectangularPatternInput = rectangularPatterns.createInput(inputEntites, xAxis, quantityOne, distanceOne, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
# rectangularPatternInput.setDirectionTwo(zAxis, quantityTwo, distanceTwo)
# rectangularFeature = rectangularPatterns.add(rectangularPatternInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.