MoI discussion forum
MoI discussion forum

Full Version: ArcCAM

Show messages:  1-8  9-28  29-48  49-68  69-73

From: Michael Gibson
20 Sep   [#29] In reply to [#28]
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
20 Sep   [#30] In reply to [#29]
Michael,

Thanks! See that's why you make the big bucks. ;-)

>Len
From: probotix
21 Sep   [#31] In reply to [#30]
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
21 Sep   [#32] In reply to [#31]
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
21 Sep   [#33] In reply to [#32]
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
21 Sep   [#34] In reply to [#33]
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
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

Show messages:  1-8  9-28  29-48  49-68  69-73