Precision of Path Pattern Feature only accurate to 3 decimal places in API

Precision of Path Pattern Feature only accurate to 3 decimal places in API

dbunch211
Contributor Contributor
449 Views
3 Replies
Message 1 of 4

Precision of Path Pattern Feature only accurate to 3 decimal places in API

dbunch211
Contributor
Contributor

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. 

 

PathPatternAccuracy.jpg

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()))

 

0 Likes
Accepted solutions (1)
450 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor
Accepted solution

I don't think there's a problem with the values but an issue with the precision in how they're displayed. Internally, values are double-precision floating points, but to display a value, it has to be converted to a string. You can control this display precision in preferences. The setting is shown below, where I've changed mine to the maximum of none decimal places. This doesn't change anything about how values are stored or used but only affects how values are displayed in the user interface.

 

BrianEkins_0-1717775865165.png

 

After changing this and running your test script, this is what I see in the dialog for Pattern on Path.

BrianEkins_1-1717775989127.png

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 4

dbunch211
Contributor
Contributor

Thanks for the explanation.  I had thought about looking in the preferences, but figured since I could change it manually that was not the problem.  Obviously, I was incorrect.  Thanks again and I will make a note of that for others using my threading program.  Onward & upward now.

0 Likes
Message 4 of 4

dbunch211
Contributor
Contributor

Just in case the user did not have this value set high enough, I added this code to save current General Precision, set it to the maximum value of 9 & then set it back to what it was after running the pathPatterns section.

    General_Precision = preferences.unitAndValuePreferences.generalPrecision    # Get current precision
    preferences.unitAndValuePreferences.generalPrecision = 9                    # Set to maximum of 9 before running the pathPatterns code
# Run the PathPatterns section of code
    preferences.unitAndValuePreferences.generalPrecision = General_Precision    # Set precision back to what user had

 

0 Likes