Hello,
The code below crashes whereas the 3 points are disctinct. Setting the factor value f to 100 solves the issue.
The error message:
RuntimeError: 5 : Some input argument is invalid.
It seems that there is a problem with the precision of the numbers during the computation.
import adsk.core, traceback
p1 = [-0.00047752000000000005, 0.15192502000000002]
p2 = [-0.0006226001152828134, 0.15214303759958947]
p3 = [-0.0006731, 0.1524]
# The code works with f = 100
f = 1
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
rootComp = product.rootComponent
sketches = rootComp.sketches
sketchesPlane = rootComp.xYConstructionPlane
sketch = sketches.add(sketchesPlane)
arcs = sketch.sketchCurves.sketchArcs
pt1 = adsk.core.Point3D.create(p1[0]*f, p1[1]*f, 0.0)
pt2 = adsk.core.Point3D.create(p2[0]*f, p2[1]*f, 0.0)
pt3 = adsk.core.Point3D.create(p3[0]*f, p3[1]*f, 0.0)
arcs.addByThreePoints(pt1, pt2, pt3)
ui.messageBox('OK')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The issue occurs when trying to import a geometry from a file.
Here are all the triplets values that failed:
*****
-0.00047752000000000005 0.15192502000000002 0.0
-0.0006226001152828134 0.15214303759958947 0.0
-0.0006731 0.1524 0.0
*****
0.21081746 4.1827069 0.0
0.21083651 4.182706638774926 0.0
0.21085556 4.1827069 0.0
*****
-0.0006731 6.05536 0.0
-0.00047595357441652345 6.055835953574417 0.0
0.0 6.0560331 0.0
*****
0.07552690000000001 6.13156 0.0
0.07572404642558347 6.132035953574417 0.0
0.0762 6.1322331 0.0
*****
0.22860000000000003 6.1322331 0.0
0.22907595357441654 6.132035953574417 0.0
0.2292731 6.13156 0.0
*****
0.47744634 6.06242374 0.0
0.47746294213947027 6.062431160364481 0.0
0.4774793600000001 6.06243898 0.0
*****
0.5225669000000001 6.13156 0.0
0.5227640464255835 6.132035953574417 0.0
0.52324 6.1322331 0.0
*****
0.7518400000000001 6.1322331 0.0
0.7523159535744166 6.132035953574417 0.0
0.7525131 6.13156 0.0
*****
2.32301542 6.10663498 0.0
2.3232331941927846 6.106781307383965 0.0
2.3234904000000003 6.1068331 0.0
*****
2.8391104 6.1068331 0.0
2.8394962006423152 6.106711677988141 0.0
2.8397428600000003 6.10639114 0.0
*****
3.22893182 6.13170732 0.0
3.2291685860022112 6.132085526306413 0.0
3.22958968 6.1322331 0.0
*****
3.5775696800000003 6.1322331 0.0
3.578045633574417 6.132035953574417 0.0
3.5782427800000005 6.13156 0.0
*****
3.58109266 6.11100124 0.0
3.5810981213636035 6.1109835689610295 0.0
3.5811028200000004 6.11096568 0.0
*****
3.5811028200000004 6.11096568 0.0
3.581097665305647 6.1109834386587565 0.0
3.58109266 6.11100124 0.0
*****
3.7292965800000006 6.13156 0.0
3.729493726425584 6.132035953574417 0.0
3.72996968 6.1322331 0.0
*****
3.9598600000000004 6.1322331 0.0
3.960335953574417 6.132035953574417 0.0
3.9605331000000006 6.13156 0.0
*****
4.0284882600000005 6.0564141000000005 0.0
4.02893295481865 6.056200340963728 0.0
4.029113100000001 6.055741 0.0
*****
4.029113100000001 0.1524 0.0
4.029061396913553 0.15214275684889197 0.0
4.02891498 0.15192502000000002 0.0
*****
3.87651498 -0.00047498 0.0
3.8762972058072154 -0.0006213073839646991 0.0
3.87604 -0.0006731 0.0
*****
3.7846 -0.0006731 0.0
3.784124046425583 -0.00047595357441670744 0.0
3.7839269 0.0 0.0
*****
3.1401131000000007 0.0 0.0
3.1399159535744174 -0.0004759535744167994 0.0
3.13944 -0.0006731 0.0
*****
2.9171773 -0.0006731 0.0
2.9168084710412754 -0.0005632027482395946 0.0
2.91656008 -0.00026924 0.0
*****
2.7781173800000003 -0.00026924 0.0
2.777869005845322 -0.0005632285560581688 0.0
2.7775001599999998 -0.0006731 0.0
*****
2.42062 -0.0006731 0.0
2.4201440464255835 -0.00047595357441661544 0.0
2.4199469000000002 0.0 0.0
*****
1.6084931 0.0 0.0
1.6082959535744166 -0.00047595357441666136 0.0
1.60782 -0.0006731 0.0
*****
1.1077092400000002 -0.0006731 0.0
1.1072699286841035 -0.0005096272777208597 0.0
1.10704376 -9.906e-05 0.0
*****
0.70143624 -9.906e-05 0.0
0.7012100848537824 -0.0005096429720839872 0.0
0.70077076 -0.0006731 0.0
*****
0.46099730000000005 -0.0006731 0.0
0.4606284711372198 -0.000563202601607623 0.0
0.4603800800000001 -0.00026924 0.0
*****
0.32193738 -0.00026924 0.0
0.32168900584532195 -0.000563228556058086 0.0
0.32132016 -0.0006731 0.0
*****
0.1524 -0.0006731 0.0
0.15214153574088737 -0.0006215323168355681 0.0
0.15192248 -0.00047498 0.0
*****
Thank you
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
Hi @JeromeBriot .
It is very disappointing that it is still not fixed. It may be the SpurGear script that is most affected.
https://forums.autodesk.com/t5/fusion-360-api-and-scripts/gear-design/m-p/11675512
For now, it seems that the only way is to use splines instead.
Thank you @kandennti. I searched the forum but didn't find this thread.
So this bug seems to be already reported as mentioned by @BrianEkins
Hope it will be fixed soon.
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
Here is the code with the workaround by @jsugano_igears
import adsk.core, traceback
p1 = [-0.00047752000000000005, 0.15192502000000002]
p2 = [-0.0006226001152828134, 0.15214303759958947]
p3 = [-0.0006731, 0.1524]
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
rootComp = product.rootComponent
sketches = rootComp.sketches
sketchesPlane = rootComp.xYConstructionPlane
sketch = sketches.add(sketchesPlane)
pt1 = adsk.core.Point3D.create(p1[0], p1[1], 0.0)
pt2 = adsk.core.Point3D.create(p2[0], p2[1], 0.0)
pt3 = adsk.core.Point3D.create(p3[0], p3[1], 0.0)
# Fix by jsugano_igears
# https://forums.autodesk.com/t5/fusion-360-api-and-scripts/gear-design/m-p/11679049/highlight/true#M18057
try:
sketch.sketchCurves.sketchArcs.addByThreePoints(pt1, pt2, pt3)
except:
tipArcPnts = adsk.core.ObjectCollection.create()
tipArcPnts.add(pt1)
tipArcPnts.add(pt2)
tipArcPnts.add(pt3)
sketch.sketchCurves.sketchFittedSplines.add(tipArcPnts)
ui.messageBox('OK')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
Hi Mr JeromeBriot,
It looks like you are messing around with old methods of gear teeth generators.😉
These methods utilize mapping a gear hobbing tool circular trajectory to the tooth profile. It is/was a natural approach as (in typical cases) gear cutting involves rotating tools, so approximation of the tooth profile by arc segments was a no-brainer at the time. Splines, NURBS, and other goodies were not in the main circulation amongst machinists, and neither double precision computing like today but rather dwarf floats were in charge of virtual reality. Legacy gear generators are still part of today's software chain, and your example might be proof of it.
The idea of Mr. @jsugano_igears is valid, as describing a tooth profile as a spline offers many benefits (including precision). Of course, it depends upon your goal in the project.
You can also try the following:
With Regards
MichaelT
@MichaelT_123 wrote:
It looks like you are messing around with old methods of gear teeth generators.😉
Actually, this is for my add-in IDF Import. A user reported a bug and I found that it was related to the addByThreePoints method. I have no control on the geometry because it is imported from files that are generated by external ECAD softwares.
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
This issue has a fix that will be released in next month's update - thank you for posting a workaround!
What's New says the "SketchArcs.addByThreePoints" method is fixed.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-36B1FFB5-5291-4532-8F11-90E912769B34
However, I still get an error when I try it. (Ver 2.0.16265)
This is what I tried when this topic was created.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
des: fusion.Design = app.activeProduct
root: fusion.Component = des.rootComponent
p1: core.Point3D = core.Point3D.create(0.1524, -0.0006731, 0.0)
p2: core.Point3D = core.Point3D.create(0.15214153574088737, -0.0006215323168355681, 0.0)
p3: core.Point3D = core.Point3D.create(0.15192248, -0.00047498, 0.0)
skt: fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
# sketchCircles.addByThreePoints - OK
skt.sketchCurves.sketchCircles.addByThreePoints(p1, p2, p3)
# sketchArcs.addByThreePoints - Error
skt.sketchCurves.sketchArcs.addByThreePoints(p1, p2, p3)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
At that time (one month ago), "SketchArcs.addByThreePoints" failed, but "sketchCircles.addByThreePoints" worked fine.
Unfortunately, in ver. 2.0.16265, "sketchCircles.addByThreePoints" also fails.
The situation is getting worse.
It's strange because the specific case causing the spur gear to fail is now working. However, this simpler case now fails. I can reproduce this in the UI by drawing two points 0.01 mm apart and then trying to create an arc or circle using those points. This is a new problem with the May release, and I've reported it. Hopefully, it's fixed soon.
Can't find what you're looking for? Ask the community or share your knowledge.