Added scale and grid commands.
scale,grid explain
scale (Category: Draw)
[SEGMENTLIST FACTOR] Scale each item in SEGMENTLIST by
FACTOR, using the midpoint of all segments as the center.
grid (Category: Draw)
[SEGMENTLIST GRID] Move points of SEGMENTLIST to be a
multiple of GRID.
Here’s an example. With the existing commands, I created a new command called regularsize:
Usage: SIDELENGTH PARALLELANGLE regularsize
regularsize takes the selected segments, joins them into a regular polygon, then
sizes the edges to the specified length, and places one of the edges parallel
to the specified angle
Before:
30 mm 0 regularsize
After:
This works for any number of sides that you draw.
If you are interested, here is the regularsize command that I’ve defined:
You can use the see command and explain command to view details about user defined commands:
'regularsize see
: regularsize drawings selected copy connect copy
regular copy copy length delist stack 4 pick swap /f
scale copy delist list angle delist 2 pick swap -f rotate
pop pop ;
A lot of this is parameter manipulation (4 pick, copy, swap, pop) but it shows a little bit of the power of KiCommand. The key commands in the regularsize command are scale, angle and rotate.
'regularsize explain
: regularsize drawings selected copy connect copy regular copy copy length delist stack 4 pick swap /f scale copy delist list angle delist 2 pick swap -f rotate pop pop ;
drawings (Category: Elements)
Get all top-level drawing objects (lines and text)
selected (Category: Attributes)
[objects] Get selected objects
: copy 0 pick ;
0 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
connect (Category: Action)
Using selected lines, connect all vertices to each closest
one.
: copy 0 pick ;
0 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
regular (Category: Draw)
[SEGMENTLIST] Move/stretch the selected segments into a
regular polygon (equal length sides, equal angles).
: copy 0 pick ;
0 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
: copy 0 pick ;
0 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
length (Category: Geometry)
[SEGMENTLIST] Get the length of each segment (works with
segment and arc types
delist (Category: Conversion)
[LIST] Output index 0 of LIST.
stack (Category: Programming)
Output the string representation of the objects on the stack
4 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
swap (Category: Stack)
Switches the two top objects on the stack.
/f (Category: Numeric)
[OPERAND1 OPERAND2] Return the the floating point OPERAND1 /
OPERAND2.
scale (Category: Draw)
[SEGMENTLIST FACTOR] Scale each item in SEGMENTLIST by
FACTOR, using the midpoint of all segments as the center.
: copy 0 pick ;
0 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
delist (Category: Conversion)
[LIST] Output index 0 of LIST.
list (Category: Conversion)
[OBJECT] Make OBJECT into a list (with only OBJECT in it).
angle (Category: Geometry)
[SEGMENTLIST] Return the angle of each segment in
SEGMENTLIST.
delist (Category: Conversion)
[LIST] Output index 0 of LIST.
2 - A literal value (argument)
pick (Category: Stack)
[NUMBER] Copy the value that is NUMBER of objects deep in
the stack to the top of the stack.
Examples:
0 pick - copies the top of the stack.
1 pick - pushes a copy of the second item from the
top of the stack onto the top of the stack.
swap (Category: Stack)
Switches the two top objects on the stack.
-f (Category: Numeric)
[OPERAND1 OPERAND2] Return the the floating point OPERAND1 -
OPERAND2.
rotate (Category: Geometry)
[SEGMENTLIST DEGREES] Rotate segments by DEGREES around
additive center.
pop (Category: Stack)
Removes the top item on the stack.
pop (Category: Stack)
Removes the top item on the stack.