MoI discussion forum
MoI discussion forum

Full Version: ArcCAM

Show messages:  1  2-21  22-41  42-61  62-73

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
From: Michael Gibson
13 Oct   [#55] In reply to [#54]
Hi Len,

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

Is it the UI for a command? There is usually a default="" attribute you can set on the control, like:
code:
    <moi:NumericInput id="Angle" default="360.0"/>


You'll need the control to have a unique id="" value on it. When the command starts, it will initialize controls, setting them to their last used value (unless style="persist:false" is set) or to the default="" value if it's the first run of that command.

The last used value is stored using the id="" value as a lookup key, so a unique id value should be set for each control for that to work.

- Michael
From: probotix
13 Oct   [#56] In reply to [#55]
Michael,

My previous post edit may have crossed your response.

I did discover moi.command.setOption and moi.command.getOption and that works. But in my testing, it fails if toIni is true. I dont wanna store any of my stuff in the main ini, but I did test to see if it would work, and it doesnt appear to.

I'm setting up my own ini file with defaults and last used value storage. From what I observe, Moi doesn't save last used values on restart.

>Len
From: Michael Gibson
13 Oct   [#57] In reply to [#56]
Hi Len, yes the normal behavior is that UI controls save and restore their last used values within the same program run but not between program runs.

The reason for that is to avoid the problem where someone who is learning MOI experiments with changing some options and then gets confused when their UI has different behavior than what is shown when they are following a tutorial.

If you want them to persist between program runs then you would need to do that with your own script code calling moi.command.getOption() / setOption() with the "to ini" parameter set to true. That will store the value in the [Commands] section of the moi.ini file.


> but I did test to see if it would work, and it doesnt appear to.

Can you post the code you tried that did not work? If the option hasn't been stored there yet it will throw an exception from getOption() so you need to have it set in a try {} catch {} block.

- Michael
From: probotix
13 Oct   [#58] In reply to [#57]
I would test by toggling these two lines on and off. If I remove true, it works. And BTW it just quietly dies without throwing an error.

code:
//alert( moi.command.getOption( 'ArcCAM.htm_test' ) );
	
//moi.command.setOption( 'ArcCAM.htm_test', '1234567', true );


And yes I did discover that it will throw an error is setOption is not called first.

>Len
From: Michael Gibson
13 Oct   [#59] In reply to [#58]
Hi Len, both getOption and setOption need to have the "use ini" parameter added.

If you call moi.command.getOption( 'ArcCAM.htm_test' ) that will get it from the runtime storage.

You need to call moi.command.getOption( 'ArcCAM.htm_test', true ) to get it from ini storage.

You don't want to have a mismatch with the get coming from runtime storage and the set going to ini storage.

It's good to have the get wrapped in a try / catch block to handle the exception that will be triggered if there isn't any value present.

var value = false;

try {
    value = moi.command.getOption( 'ArcCAM.htm_test', true );
} catch(e) {}

It would probably have been better for this to return undefined if no value had ever been set rather than throwing an exception but it's difficult to change things that are in use.

- Michael
From: probotix
13 Oct   [#60] In reply to [#59]
I was watching the ini file to see if it changed and it did not. Is the ini file only written on close?

>Len

From: probotix
13 Oct   [#61] In reply to [#60]
Is there a way to run a command from a directory other than moi://AppData/commands? I have tried a few different ways, but nothing seems to work.

code:
<moi:CommandButton icon="moi://appdata/icons/ArcCAMIcon.png" command="moi://appdata/ArcCAM/ArcCAM.js">


>Len

Show messages:  1  2-21  22-41  42-61  62-73