PDA

View Full Version : How Can I Add A Function To A Stroke?


dunklegend
06-19-2007, 10:54 AM
I would like to add commonly used functions to strokes.
Maybe one for measuring, and one to snap to center.
Right now I'm checking geometries to the new released drawings and I'm doing a lot of measuring and snapping.
If someone would show me how to do this or point me to a place that describes it, I would really appreciate it.

Right now I would like to do it in Librarian but maybe it would be useful to do it also for Layout.

Thanks in advance.

hockeycoach
09-20-2007, 08:24 AM
Try this:

// FILENAME: ~/ample/trace_length.ample
// PURPOSE:
// This userware contains a function which returns the TOTAL NET LENGTH of a selected net
// The ALIAS "len" is used as a shorcut to call this function
// The F4s KEY is also used as a shorcut to call this function
// The STROKE letter L, Bottom To Top is also used as a shorcut to call this function
// IMPLEMENTATION:
// -save this file to in a dir called amlple off of your unix homedir (~/ample/trace_length.ample)
// -add the following two lines to your ~/mgc/startup/layout.startup file
// $load_userware("~/ample/trace_length.ample");
// $load_userware("~/ample/trace_length.ample", "lay_area", @ample);

// _______________________________________________________________
FUNCTION $STROKE_98741() //the letter L, Bottom To Top
{
return_length_of_net();
}
/* stroke grid
1 2 3
4 5 6
7 8 9
*/

function $key_f4s()
{
return_length_of_net();
}
extern $key_label_f4s = "GET LENGTH";

function return_length_of_net()
{
local n = $get_seg_select_count();
local seg_info = $get_seg_select_info();
local node = $get_net_select_name();
local wir_length = 0;
local units = $get_geom_units($get_board_name());
local i, x1, x2, y1, y2;
for (i = 0; i < n; i = i + 1) {
x1 = seg_info[0 + (6 * i)];
x2 = seg_info[3 + (6 * i)];
y1 = seg_info[1 + (6 * i)];
y2 = seg_info[4 + (6 * i)];
calc(x1, y1, x2, y2);
wir_length = wir_length + seg_length;
}
wir_length = $round_prec(wir_length, 3);
//$writeln_file($strcat("Segment is ", wir_length, units, " long on net ", node));
$message($strcat("Segment is ", wir_length, units, " long on net ", node));
}



function calc(x1:number, y1:number, x2:number, y2:number)
{
extern seg_length;
seg_length = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}


function registermyfunction()
{
local handle ;
handle = $register_command("return_length_of_net","");
$register_alias("len" , handle);
}

dunklegend
09-22-2007, 10:58 AM
Thanks I'll try