MoI discussion forum
MoI discussion forum

Full Version: ArcCAM

Show messages:  1-14  15-34  35-54  55-73

From: probotix
21 Sep   [#35] In reply to [#34]
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
23 Sep   [#36] In reply to [#35]
Hey Michael!

Can we not use classes inside of our scripts?

>Len
From: Michael Gibson
23 Sep   [#37] In reply to [#36]
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
23 Sep   [#38] In reply to [#37]
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
23 Sep   [#39] In reply to [#38]
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
24 Sep   [#40] In reply to [#39]
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
24 Sep   [#41] In reply to [#40]
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
From: Michael Gibson
24 Sep   [#42] In reply to [#41]
Hi Len,

re:
> Is there a way to know if a curve is almost a circle or almost an arc?

MoI tests every curve that is created and if it is almost a circle or arc then the crv.isCircle or crv.isArc properties will return true.

The tolerance value used for the "almost" part is 0.000001 , scaled up or down depending on the size of the curve's bounding box diagonal.


> 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.

User text is the mechanism to do this. Having custom properties objects would make things more complex when the properties need to be copied or saved/restored from a file.

Thanks,
- Michael
From: probotix
25 Sep   [#43] In reply to [#42]
Michael,

I am now working on pocketing operations. My initial approach is to use Moi's offset operation to help create the toolpath stepovers. I can take the generated curves, separate them in to segments, and create bridges between the perimeters, and rejoin them into a continuous curve.

I already have a working offset function that repeats using a stepover value.

Can you think of a better way to do this?

>Len
From: Michael Gibson
25 Sep   [#44] In reply to [#43]
Hi Len,

re:
> Can you think of a better way to do this?

Nothing different really comes to mind, it sounds like you have a good approach worked out.

- Michael
From: probotix
3 Oct   [#45] In reply to [#44]
Any idea why curve is not an object?

code:
	var newcrv = crv.changeClosedCurveSeam( param ); 
	if ( newcrv )
	{
		moi.geometryDatabase.removeObject( crv );
		moi.geometryDatabase.addObject( newcrv );
	}
	debug(dump(newcrv));
	
	createPerpendicular( newcrv );
	
	var factory = moi.command.createFactory( 'separate' );
	factory.setInput( 0, newcrv );
	factory.commit();

	curve = moi.geometryDatabase.getCreatedObjects;
	debug(dump(curve));


newcrv is an object and createPerpendicular works fine, but separate does nothing.

>Len
From: Michael Gibson
3 Oct   [#46] In reply to [#45]
Hi Len,

re:
> Any idea why curve is not an object?

Several reasons:

Separate factory is expecting an object list for its input, not an individual object, so you need something like this instead:
code:
function WrapWithObjectList( obj )
{
	var list = moi.geometryDatabase.createObjectList();
	list.addObject( obj );
	return list;
}

	var factory = moi.command.createFactory( 'separate' );
	factory.setInput( 0, WrapWithObjectList(newcrv) );


Additionally, for this:
code:
    curve = moi.geometryDatabase.getCreatedObjects;


You're missing the () at the end there so instead of calling the function getCreatedObjects you're retrieving it as a property value.

Also getCreatedObjects() isn't on geometry database, it's on the factory but also to use it you've got to call it after an .update() and before .commit().

For scripting it can be better to call
var output_list = factory.calculate();

- Michael
From: probotix
4 Oct   [#47] In reply to [#46]
Can I pop the first segment and the last segment off of a list of segments, add my own segments to the ends and rebuild the curve?

>Len
From: Michael Gibson
4 Oct   [#48] In reply to [#47]
Hi Len,

re:
> Can I pop the first segment and the last segment off of a list of segments, add my own segments to
> the ends and rebuild the curve?

There isn't any direct API call for that currently but you can do all of that by using the same geometry factories that the regular commands use.

I'll see about adding in some functions for working with curve segments to make this more convenient.

- Michael
From: probotix
5 Oct   [#49] In reply to [#48]
Next question... can I do a similar calculation for clockwise/counterclockwise on a whole closed curve by picking 3 points along the curve, or will complex curves be problematic?

Thanks again!

>Len
From: Michael Gibson
5 Oct   [#50] In reply to [#49]
Hi Len,

re:
> Next question... can I do a similar calculation for clockwise/counterclockwise on a whole
> closed curve by picking 3 points along the curve, or will complex curves be problematic?

Unlike an arc, a general spline curve can have inflections in it so just 3 points isn't enough.

But if you evaluate a bunch of points along the curve so you have a closed polygon you can calculate the signed area of a 2D closed polygon like this:

code:
var area = 0;
var array_of_points = [];

// Get points to make a closed 2D polygon.

var numpoints = array_of_points.length;

for ( var i = 0; i < numpoints-1; i++ )
{
	var this_pt = array_of_points[i];
	var next_pt = array_of_points[i+1];

	area += this_pt.x * next_pt.y;
	area -= this_pt.y * next_pt.x;
}

// One more span to close it off, it is ok if the first and last point are coincident.

var this_pt = array_of_points[numpoints-1];
var next_pt = array_of_points[0];

area += this_pt.x * next_pt.y;
area -= this_pt.y * next_pt.x;

if area < 0 it's clockwise

if area > 0 it's counter-clockwise


- Michael
From: probotix
7 Oct   [#51] In reply to [#50]
Thanks to Michael's help, I have been able to add a script that will create a lead-in and lead-out for profiles that will use tool diameter compensation. I also added a couple of helper scripts to the repository. It presently only works on closed curves with arcs and lines, which is how I like to design my machined parts anyhow.

You can use OrderCurves to set the direction of the curve. CreateLeadInOut will set the start of the curve to a point on the curve of your choosing (using crv.changeClosedCurveSeam) after you set the lead-in radius and the overlap.

https://github.com/probotix/ArcCAM


>Len

Image Attachments:
arcCam_2.jpg 


From: blowlamp
8 Oct   [#52] In reply to [#51]
Hi Len.

I'd like to try this out, but I don't know how to install it properly.
The icons are missing and I get an error at startup.
Could you let me know where the various files should be located to get it running, please?

Many thanks.
Martin.
From: probotix
13 Oct   [#53] In reply to [#52]
Martin,

Let me finish moving some files around before you try. I recently found out I could link icons from the AppData folder.

>Len
From: probotix
13 Oct   [#54] In reply to [#50]
Michael,

Is there a way to pass data to the UI. As an example, I want to be able to populate input fields with defaults.

EDIT: I did discover moi.command.setOption and moi.command.getOption and that works. But in my testing, it fails if toIni is true.

>Len

Show messages:  1-14  15-34  35-54  55-73