Full Version: ArcCAM
Show messages:
1
2-21
22-41
42-61
62-73
From: probotix
This works:
usertext = curves.item(i).getAllUserText();
for ( var u = 0; u < usertext.length; u++ )
{
alert( usertext.item(u).key + " => " + usertext.item(u).value + "\n");
}
Thanks Michael!
>Len
From: stefano (LIGHTWAVE)
hi len - had a look at your website looks interesting...this new Linux-CNC product of yours (in the making)...
Is it going to be touchscreen and totally compact or "industrial" like your other control boxes. Could
consider throwing MACH 3 out of the window - literally.
Cheers
Stefano..
From: probotix
Hey Stefano
Here is the teaser image for the new machine series that will come with the new touchscreen:
It will be offered in an ethernet based version for interfacing with the Mesa Electronics FPGA control cards, which we use in our new UnityE controllers. It will also be offered with 2x DB25 ports for interfacing with older parallel port based controllers. There will be options for 15" and 10" versions.
>Len
Image Attachments:
EX_series_teaser_deltoro.jpg
From: probotix
Michael,
Tried your suggestion for clockwise/counterclockwise, but it doesn't work because I need to know clockwise or counterclockwise from the direction of travel, not relative to absolute cartesian space.
code:
// DOESNT WORK
function isClockwise(k,l,m)
{
var XLK = l.x - k.x;
var XMK = m.x - k.x;
var YLK = m.y - k.y;
var YMK = m.y - k.y;
signed_area = 0.5 * (( XLK*YMK ) - ( XMK*YLK ));
if( signed_area > 0)
return 1;
else if( signed_area < 0)
return -1;
else
return 0;
}
var min = segment.domainMin;
var max = segment.domainMax;
var len = max - min;
var start = segment.getStartPt();
var midpoint = segment.evaluatePoint( min + (0.5 * len) );
var end = segment.getEndPt();
var clockwise = isClockwise( start, midpoint, end );
This below works for any arcs that are not 180 deg, but 180 degree arcs resolve to an arc angle of pi, so it doesnt know which direction to turn:
code:
// WORKS FOR ANY ARC THAT IS NOT 180 degrees (pi radians).
function isClockwise( p0,p1,c )
{
var pi = Math.PI;
var angle = Math.atan2(p0.y - c.y, p0.x - c.x) - Math.atan2(p1.y - c.y, p1.x - c.x);
if ( angle == 0 || angle == pi )
return 0;
else if ( angle > 0 && angle < pi )
return 1;
else if ( angle> pi )
return -1;
else if ( angle < 0 && angle> (pi * -1))
return -1;
else if ( angle < (pi * -1))
return 1;
}
var clockwise = isClockwise( segment.getStartPt(),segment.getEndPt(), segment.conicFrame.origin );
>Len
From: Michael Gibson
Hi Len,
re:
> Tried your suggestion for clockwise/counterclockwise, but it doesn't work because I need
> to know clockwise or counterclockwise from the direction of travel, not relative to absolute
> cartesian space.
Can you please post a .3dm file with an example arc that doesn't work?
Could you maybe describe a little more about what coordinate system you need to use if it isn't global coordinates?
- Michael
From: probotix
Michael,
I have posted the latest code with both isClockwise functions. You can choose which one on lines 178 & 179.
https://github.com/probotix/ArcCAM
With const DEBUG = true, you'll have to change the path to a hard coded log file on line 48.
Here is a file. There are several arcs that do not compute properly in this file in isClockwise2. Segments 3, 14, 20, 24, and 28 are all reversed.
In the original isClockwise all arcs are generated just fine, except segment 14, the 180 degree arc. If I split that arc into 2x 90s, it will generate fine, but I dont consider that a solution.
I use ncviewer to preview the tool paths:
https://ncviewer.com/
You can just paste into the text box and you can also step through each block line by line. I should note that ncviewer has a bug where it doesnt display 180 degree arcs at all. Ncviewer has other issues, too, like it cannot handle arcs that use I & J instead of R. Eventually I'll build a gcode preview script Moi, maybe where it throws it into a certain named group or different color.
>Len
Attachments:
x3.3dm
From: probotix
For the algorithm you suggested, I'm thinking maybe I could take the entry angle (tangent of the first point I think) and rotate the mid and end points to align with cartesian before doing the calculation.
BTW, I'm not worried about circles yet because they will be a completely different tool path, and Haas has a circular pocket op from center and radius.
>Len
From: Michael Gibson
Hi Len,
re:
> For the algorithm you suggested, I'm thinking maybe I could take the entry angle (tangent of the first point I think)
> and rotate the mid and end points to align with cartesian before doing the calculation.
The property of clockwise/counter-clockwise direction is invariant to 2D rotation.
It looks like you have a typo in the isClockwise2() function.
You have this:
code:
function isClockwise2(k,l,m)
{
var XLK = l.x - k.x;
var XMK = m.x - k.x;
>>> var YLK = m.y - k.y; <<<
var YMK = m.y - k.y;
signed_area = 0.5 * (( XLK*YMK ) - ( XMK*YLK ));
if( signed_area > 0)
return 1;
else if( signed_area < 0)
return -1;
else
return 0;
}
There is a typo in the line marked with >>> <<< , it should be
(from
http://moi3d.com/forum/index.php?webtag=MOI&msg=11521.42):
code:
var YLK = l.y - k.y;
- Michael
From: probotix
Michael,
Thanks! See that's why you make the big bucks. ;-)
>Len
From: probotix
Michael,
I'm getting a much better understanding of arcs in Moi, now. But I am puzzled by this behaviour.
Here is the starting arc.
In this next image, I add a point snapped to the midpoint of an arc, and it adds another control point instead and keeps the arc intact.
In this third image, I trim the arc using the orange line and it splits the arc, but the top half has only one control point while the bottom has two.
>Len
Image Attachments:
add_point.jpg
beginning_arc.jpg
trim.jpg
From: Michael Gibson
Hi Len, when you show edit points on a circle, ellipse, or arc curve the points you see are from an automatically rebuilt approximation curve.
That's so that if you edit the points you'll get a smooth curve and not get kinks at internal fully multiple knots.
But if the segment is an arc with only 3 control points (without any internal fully multiple knots) it won't do the automatic rebuild because editing those points won't produce a sharp kink. The upper segment in your 3rd image falls into this category.
> In this next image, I add a point snapped to the midpoint of an arc, and it adds another control
> point instead and keeps the arc intact.
One thing to note is after you have added the control point, the result will be a rebuilt general spline curve and not a precise arc anymore.
If you want to keep exact arcs then you shouldn't edit their control points, when you do control point manipulation it is assumed that you want to make a squishable smooth curve.
- Michael
From: probotix
Yeah, not trying to add or edit the control points, but it wont let me add a point to the curve. It adds the point to the control points. The only way I can find to split the curve is to trim it with a line.
>Len
From: Michael Gibson
Hi Len, what is it you are trying to accomplish by adding a point to the curve?
re:
> The only way I can find to split the curve is to trim it with a line.
The Trim command is the right tool to use for splitting an arc into 2 arc pieces.
If you want to cut it at a particular point you don't have to use a line, there is an "Add trim points" button that you can use to pick a splitting point on the curve.
- Michael
From: probotix
I have added an origin point selector so that you can select the point that you want to be X0 Y0 of the gcode, plus some code cleanup after Michael helped me solve my clockwise/counterclockwise problem.
https://github.com/probotix/ArcCAM
I have been cutting parts with this all day on the Haas. Its saving me a ton of time, wasted parts, and broken tools already. I'm in the middle of a new product roll-out and building the production code is the most painful part.
>Len
From: probotix
Hey Michael!
Can we not use classes inside of our scripts?
>Len
From: Michael Gibson
Hi Len, the script engine used currently in MOI is a bit older and only supports ECMAScript 5.
Classes were a new language feature starting in ECMAScript 6, so sorry no that can't be used in MOI scripts.
However, you can still structure things in the same way as a class in ECMAScript 5, the new "class" keyword in ECMAScript 6 doesn't really do a whole lot.
- Michael
From: probotix
ES5 is only a minor annoyance so far. I have found work arounds for everything to this point.
I'm working on the drill functions and I have a few other questions:
Is there any way to order curves by their selection order?
Also, is there a way to sort object by one of their properties, for instance: select a bunch of circles and order them by the diameter?
Can you explain what's happening in the DoChangeClosedCurveSeam script and what the pickedpt.osnap(i).object and pickedpt.osnap(i).otherObject are revealing?
Thanks again!
>Len
From: Michael Gibson
Hi Len,
re:
> Is there any way to order curves by their selection order?
If you have them in an object list you can call object_list.sortBySelectionOrder();
> Also, is there a way to sort object by one of their properties, for instance:
> select a bunch of circles and order them by the diameter?
You can do this by putting them into a JavaScript Array and then using the array.sort(), passing in a compare function:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
A compare function for ordering circles by diameter would go something like this (warning untested code):
function CircleRadiusSortFunc( crvA, crvB )
{
if ( crvA.conicRadius < crvB.conicRadius )
return -1;
else if ( crvA.conicRadius > crvB.conicRadius )
return 1;
else
return 0;
}
my_array.sort( CircleRadiusSortFunc );
> Can you explain what's happening in the DoChangeClosedCurveSeam script and what
> the pickedpt.osnap(i).object and pickedpt.osnap(i).otherObject are revealing?
It waits for a point to be picked that is snapped onto a curve by calling GetPointOsnappedOnCurve(). Then it gets the "PickedPoint" object from the pointpicker (pointpicker.pt).
On a PickedPoint object there is a list of OsnapPoint objects, the number of those is on the PickedPoint.numOsnaps property and you can access them by calling PickedPoint.osnap( index );
Each OsnapPoint has these read-only properties:
.object - Object that was snapped on
.parameter - Parameter value for where it was snapped
.otherObject - Some object snaps like Intersection involve 2 objects, this holds the 2nd object for those.
.otherParameter - Parameter value on 2nd curve
.type - numeric value for type of osnap, :
0 : ObjectSnap_None
1 : ObjectSnap_Origin
2 : ObjectSnap_Axis
3 : ObjectSnap_End
4 : ObjectSnap_Mid
5 : ObjectSnap_Cen
6 : ObjectSnap_Int
7 : ObjectSnap_StraightSnapInt
8 : ObjectSnap_SelfInt
9 : ObjectSnap_CPlaneInt
10 : ObjectSnap_Quad
11 : ObjectSnap_Pt
12 : ObjectSnap_PtOnObject
13 : ObjectSnap_On
14 : ObjectSnap_OnSrf
15 : ObjectSnap_Perp
16 : ObjectSnap_Tan
17 : ObjectSnap_PerpPerp
18 : ObjectSnap_TanTan
19 : ObjectSnap_Div
.typeString - localized string value for object snap type.
.pt - 3D point with .x .y .z values.
.screenDist - Distance in screen pixels from mouse cursor to snap point
.isOnCurve - True if this is a type of osnap that is located on curve or construction line geometry. False if it's ObjectSnap_Origin, ObjectSnap_Cen, ObjectSnap_Pt, ObjectSnap_OnSrf
> what the pickedpt.osnap(i).object and pickedpt.osnap(i).otherObject are revealing?
it's the object that was snapped onto. Could be a construction line, curve, curve segment, or face object.
.otherObject is the 2nd object for things like intersection snaps that involve 2 objects.
- Michael
From: probotix
Thanks again! Here is my working sort code:
code:
function CircleRadiusSortFunc( crvA, crvB )
{
if ( crvA.conicRadius < crvB.conicRadius )
return -1;
else if ( crvA.conicRadius > crvB.conicRadius )
return 1;
else
return 0;
}
for ( var i = 0; i < curves.length; i++ )
{
if( curves.item(i).isCircle )
array_of_curves.push( curves.item(i) );
}
debug( "unsorted" );
for (var i = 0, len = array_of_curves.length; i < len; i++)
{
debug( round( array_of_curves[i].conicRadius * 2, decimals ) );
}
array_of_curves.sort( CircleRadiusSortFunc );
debug( "sorted" );
for (var i = 0, len = array_of_curves.length; i < len; i++)
{
debug( round( array_of_curves[i].conicRadius * 2, decimals ) );
}
>Len
From: probotix
Michael,
Making major headway on my project this week. I'm finally starting to wrap my head around the API. I have a couple more questions:
Is there a way to know if a curve is almost a circle or almost an arc? I am working with circular drill holes now and I wanna filter out selections that are, for instance, square, polygons, etc. I have rebuilt the ReplaceClosedCrvWCir script to change the size of multiple holes at the same time and give them hole type properties: ie thru, blind, tapped, etc.
Can I stuff a custom properties object into a curve object somewhere. Right now I am using user text, but it'd be easier if there was a way to handle custom properties objects.
I've loved this software for many years, but I never even knew how powerful it would become once I started scripting it.
Thanks again!
>Len
Show messages:
1
2-21
22-41
42-61
62-73