Using Macros With Powershape
Using Macros With Powershape
Recording macros
An easy way to create a macro file is to record the commands as
you are working. When you record macros, you create a set of
commands that are carried out in the order you record them.
To record a macro:
1 Select Home tab > Macro panel > Record to display the Record
Macro dialog:
2 Select the location you want to save the macro to using the Save
in drop-down list.
3 In the File name box, enter the name of the file you want to
record to. If you enter the name of an existing file, it is
overwritten with the new commands.
4 Click Save to begin recording the macro.
5 Perform the actions you want to record.
6 Select Home tab > Macro panel > Record to stop recording. You
can use any text editor to view and edit a macro.
If you record a macro of a Paint Triangles or Mesh command, an
extra macro file is created. This file is named with the following
convention:
<psmacroname>_cc_<nnnn>.mac
Writing macros
Written macros can be longer, and more elaborate than those you
record. For example, you can add comments or add testing
conditions.
Use any text editor to create or edit your own macro files:
1 Type your own macro commands into the text editor.
2 Save the file in .mac format.
You can then run the macro (see page 9).
When you interact with the PowerShape interface, commands are
sent to the program. These are the commands that you must write
into your macro file if you want to drive PowerShape using a macro.
To find macro commands used by PowerShape:
1 Record a macro (see page 6) of the operations you want to find
the commands for. This records the operations as command
lines.
2 Open the macro file using a text editor.
3 Copy the commands into your macro.
The following table lists examples of commands you can add to
macros:
Running macros
To run a previously recorded macro:
1 Select Home tab > Macro panel > Macro > Run to display the
Run Macro dialog.
2 Select the macro you want to run.
3 Click Open to run the macro.
If you want to stop the macro while it is running, press the Esc key.
The macro finishes the command it is currently processing and
stops.
In addition to the Run option, the Step option runs one command in
the macro at a time. This enables you to watch the macro in detail
and check that each section is working correctly.
To step through a macro:
1 Select Home tab > Macro panel > Macro > Step. The Step
Through Macro dialog is displayed.
2 Select the macro you want to run.
3 Click Open to start the macro.
The Command window is displayed, showing the first command
in the macro, for example:
Macro 1: Line 1: command in first line >
4 Select the Command window, and press the Enter key to run the
command.
The next command is displayed:
Macro 1: Line 2: command in second line >
5 Continue pressing the Enter key to run each command in the
macro.
To stop a macro at any point, select Home tab > Macro panel >
Macro > Abandon.
Point information
If you want the user to enter a point, use the command:
INPUT POINT 'string' $variable_name
This command displays a dialog.
The characters in the string are displayed on the dialog and the X,
Y, Z coordinates of the point entered are assigned to three
variables:
▪ variable_name_x,
▪ variable_name_y
▪ variable_name_z.
For example:
INPUT POINT 'Enter a point' $centre_pos
This displays the following dialog when the macro is run.
Selection information
If you want the user to select one or more objects for use in the
macro, use the command:
INPUT SELECTION 'string'
This command displays a dialog, which shows the number of objects
selected. The characters in the string are used for the title on the
dialog. When objects are selected, the number of objects selected is
shown in the dialog.
When items are selected, the dialog shows the number of objects
that are selected.
print selection.number
prints the number of objects selected.
print selection.object[0]
prints the type and name of the first object in the selection.
You can use the selection object information (see page 142) to
check that the correct number or types of objects are selected.
Example - Select a line and check selection:
This example asks the user to select a line. The macro then checks
that a single line is selected. If a single line is not selected, an error
message is displayed.
LET $no_line = 1
WHILE $no_line {
select clearlist
INPUT SELECTION 'select a line'
IF (selection.number == 1) {
LET $no_line = !(selection.type[0] == 'Line')
}
IF $no_line {
PRINT ERROR 'You must select a single line'
}
}
For further information see:
▪ IF (see page 34)
▪ WHILE loop (see page 39)
Number information
Use this command to ask the user to enter a number.
INPUT NUMBER 'string' $variable_name
This command displays a dialog where:
▪ 'string' is used as the dialog title.
▪ variable_name is the label of the text box.
For example:
INPUT NUMBER 'Input radius of arc 1' $Radius1
String information
Use the following command to request a text string:
INPUT TEXT 'string' $variable_name
Like INPUT NUMBER, this command displays a dialog where:
▪ the 'string' characters are used for the dialog title.
▪ variable_name is the label of the text box.
For example:
INPUT TEXT 'Reverse the surface? Y/N' $Answer
When the macro is run, the following dialog is displayed:
Query information
If you want to ask a question that requires a yes or no answer, use:
INPUT QUERY 'string' $variable_name
This command displays a dialog with Yes and No buttons. The
question you want to ask is contained in the string. If the user
selects Yes, then $variable_name becomes 1, otherwise it
becomes 0.
For example:
INPUT QUERY 'Do you want to exit the macro?' $prompt
Displaying information
To display a message that does not require any information from
the user, use PRINT command.
PRINT 'Type your message here'
For example:
If a user provides an incorrect response, a macro displays an error
message and prompts for another response:
PRINT '***Invalid response. Please try again.***'
You can also display error message dialogs when an invalid answer
has been given, using:
Variable types
A variable type specifies the kind of information that can be stored
by the variable. A variable can have only one type. The type must
be specified when you define it.
You can specify the following variable types:
▪ INT — integer numbers for example 1, 21, 5008
▪ REAL — real numbers for example 20.1, -70.5, 66.0
▪ STRING — for example ‘hello’
▪ VECTOR
▪ LIST
▪ ERROR
Determining the type of a variable or expression
Use the following command to determine the type of an expression
or variable:
TYPE(...)
The command returns a string that is:
INT
REAL
STRING
VECTOR
LIST
ERROR
For example:
LET a = 12.345
PRINT TYPE($a)
// this prints REAL
PRINT TYPE('hello')
// this prints STRING
PRINT TYPE(SQRT(-57))
// this prints ERROR, because you are trying to take square root of a
negative number.
For example, if you have a line with the name 2, then all the
information about line is available by referring to line[2].
The start coordinates of line 2 are accessed as follows:
line[2].start retrieves the start coordinates [x, y, z]
of line 2.
line[2].start.x retrieves the x coordinate of the start of
line 2.
line[2].start.y retrieves the y coordinate of the start of
line 2.
line[2].start.z retrieves the z coordinate of the start of
line 2.
Use this object information to assign values to variables.
Example: Create a full arc with its centre point at the start
coordinates of line 2
LET $a = line[2].start.x
LET $b = line[2].start.y
LET $c = line[2].start.z
CREATE ARC
FULL
$a $b $c
Assigning an object to a variable
Use the following syntax to assign an object to a variable.
LET $t = Line[2]
This variable can be used to access information about the object.
The following is the x coordinate of the start point of Line[2].
$t.start.x
Comparison operators
Use these operators to compare two given values A and B.
A == B outputs 1 if A equals B and 0 otherwise
A != B outputs 1 if A does not equal B and 0
otherwise
A < B outputs 1 if A is less than B and 0
otherwise
A <= B outputs 1 if A is less or equal to B and 0
otherwise
A > B outputs 1 if A is greater than B and 0
otherwise
A >= B outputs 1 if A is greater or equal to B and
0 otherwise
Arc tangent
Use the following variable to calculate the arc tangent:
atan2(arg1;arg2)
This is useful for finding the azimuth and elevation for a unit vector
[i; j; k]
let azimuth = atan2(j; i)
let elevation = asin(k)
The first bracket must be the last item on the line and on the
same line as the IF. The closing bracket must be on a line by
itself.
You can also specify commands that are performed only when the
condition is false. These commands are specified using the IF-ELSE
(see page 35) and IF-ELSEIF-ELSE (see page 35) commands.
IF - ELSEIF - ELSE
IF $condition_1 {
Commands A
} ELSEIF $condition_2 {
Commands B
} ELSE {
Commands C
}
Commands D
The above construct works as follows:
▪ If condition_1 is true, then Commands A are executed followed
by Commands D.
▪ If condition_1 is false and condition_2 is true, then
Commands B are executed followed by Commands D.
Within WHILE loops, you can jump to the end of the block of
commands to:
▪ cancel the loop using the BREAK command
▪ continue with the next iteration using the CONTINUE command.
The WHILE loop checks its conditional test first to decide whether to
perform its commands, by contrast, the DO-WHILE loop performs its
commands and then checks whether to repeat.
DO {
Commands A
} WHILE $condition
Within DO loops, you can jump to the end of the block of commands
to:
▪ cancel the loop using the BREAK command
▪ continue with the next iteration using the CONTINUE command.
CONTINUE
CONTINUE causes a jump to the conditional test of any one of the
loop constructs WHILE and DO-WHILE in which it is encountered, and
starts the next iteration, if any.
An example is given below.
LET $a = 1
WHILE $a {
INPUT NUMBER 'Input number of holes' $Holes
LET $zerotest = ($Holes <= 0)
IF $zerotest {
Print "***Invalid input***"
Print "Input must be greater than zero"
CONTINUE
}
LET $a = 0
LET $angle = (360/$Holes)
}
BREAK
BREAK causes a jump to the statement beyond the end of any one of
the constructs WHILE, DO-WHILE, SWITCH in which it is encountered.
Nested constructs can require multiple breaks.
//Error messages
:Error1
PRINT '**A lateral must have more than 1 point.**'
GOTO input
Labels
Labels are used in conjunction with the GOTO command to control
progression through the macro.
Use a label as follows:
▪ At the beginning of any line in a macro file. They are
alphanumeric prefixed with a colon :. For example:
:draw
The first non-space character defines the label, all other text is
ignored. If text is added after the label it is treated as a
comment. For example:
:draw This text is a comment
▪ To jump forwards or backwards in the file to a position marked
with a label.
▪ In macro files; it cannot be used as a typed command in the
Command window.
Ensure that you do not create an infinite loop (that is a loop in the
macro which never exits):
When you initiate a macro from a running macro, you can also pass
values into the macro. The command to do this is described in
Entering values during macro initiation (see page 14).
You can also pass expressions as arguments in the command line to
run a macro from another macro. The result of the expression must
be real.
macro run create_block.mac $length ($Length/2)
(2*$Length)
If one of the arguments in the command is a variable or an
expression, or you have a negative number, you must take care
with the use of brackets.
If you run the macro with the arguments
10 ($bob) -1
PRINT $a
PRINT $b
PRINT $c
PRINT $d
PRINT $e
PRINT $f
Macro2 has the following code:
ARGS{
INT a
INT b
INT c
}
LET $d = $a / 2
LET $e = $b / 2
LET $f = $c / 2
EXPORT $d
Ending a macro
A macro ends in the following cases:
▪ when it reaches its last command.
▪ when it executes a RETURN command.
Adding a loop
We want the helix to turn 10 times. To do this, we add a while loop.
You can:
▪ Edit your macro file
▪ Open and examine the file helix_variable.mac in the folder:
C:\Program
Files\Autodesk\PowerShapexxxxx\file\examples\Macro_Writing
where xxxxx is the version number of PowerShape and C is the
disk on which PowerShape is installed.
The variable numturn indicates how many times the helix turns. The
following command assigns a value to this variable:
▪ LET $numturn = 10
The value of numturn is also the condition of the while loop. You can
read the while loop commands as:
▪ While numturn does not equal zero, perform the commands in
the brackets, { }.
When the last bracket is reached, PowerShape checks numturn:
▪ If numturn does not equal zero, then the commands in the
brackets {} are performed again.
▪ If numturn equal zero then the commands below the last bracket
are carried out.
To run the macro that includes a loop:
1 Select Home tab > Macro panel > Macro > Run. The Run Macro
dialog is displayed.
2 Select your macro file or helix_loop.mac. For further details see,
Running the macro (see page 53).
3 Click Open.
Adding comments
You can add comments to your macro to remind you what each
command does. Two slashes // are added at the start of a line to
show it is a comment. You can also use blank lines to separate
blocks of commands.
For example, when you add:
// Calculating values for the co-ordinates
The two slashes // indicate the line contains a comment. When you
run a macro, PowerShape ignores any comment lines, so it behaves
in the same way with or without comments added. The comments
can remind you of what a block of commands does.
You can either:
▪ Edit your macro file
▪ Open and examine the file helix_variable.mac in the folder:
C:\Program
Files\Autodesk\PowerShapexxxxx\file\examples\Macro_Writing
where xxxxx is the version number of PowerShape and C is the
disk on which PowerShape is installed.
The changes are given in black text.
// This macro creates a helix
// Written by: John Doe
The dialog remains displayed on the screen until the user enters a
point.
The point data is entered into the variable $cenpos. You can obtain
the x co-ordinate of the point using the variable $cenpos_x.
Similarly, the y and z co-ordinates can be obtained.
The following commands enter the first point of the helix relative to
the input position.
LET start_x = $radius + $cenpos_x
LET start_y = $cenpos_y
LET start_z = $cenpos_z
$start_x $start_y $start_z
To run the macro that changes the origin of the helix:
1 Select Home tab > Macro panel > Macro > Run. The Run Macro
dialog is displayed.
2 Select your macro file or helix_origin.mac.
3 Click Open. The Point entry dialog appears asking for you to input
a position.
4 Click a point on the screen. The three dialogs are displayed as
described in interacting with the user (see page 59).
5 Enter values in each dialog and click OK. The helix is drawn on
the screen.
// Selecting a cylinder
INPUT SELECTION 'Select a cylinder'
LET cyl = selection.object[0]
MODIFY
NAME tmpwkhelix
XAXIS DIRECTION
X $cyl.xaxis.x
Y $cyl.xaxis.y
Z $cyl.xaxis.z
ACCEPT
YAXIS DIRECTION
X $cyl.yaxis.x
Y $cyl.yaxis.y
Z $cyl.yaxis.z
ACCEPT
ZAXIS DIRECTION
X $cyl.zaxis.x
Y $cyl.zaxis.y
Z $cyl.zaxis.z
ACCEPT
ACCEPT
Select
SELECT CLEARLIST
SELECT ADD WORKPLANE 'tmpwkhelix'
DELETE
Before the cylinder is selected, we clear the selection list using the
following command.
SELECT CLEARLIST
The command
INPUT SELECTION 'Select a cylinder'
The commands to use in your macro may not be obvious. You may
need to:
1 Record a macro
2 Open the macro in a text editor
3 Copy the commands in your macro.
For example, to create and edit a workplane, record a macro to
create a workplane, and then edit the properties you want to use in
your macro.
The following command:
LET $radius = abs($cyl.lat[1].point[1].x)
uses the x co-ordinate of point 1 of lateral 1 of the cylinder to define
the radius.
The command below uses the origin of the workplane to define the
start point of the helix.
$radius 0 0
The following three lines clear the selection, then select and delete
the workplane.
// Selecting a cylinder
INPUT SELECTION 'Select a cylinder'
LET cyl = selection.object[0]
MODIFY
NAME tmpwkhelix
XAXIS DIRECTION
X $cyl.xaxis.x
Y $cyl.xaxis.y
Z $cyl.xaxis.z
ACCEPT
YAXIS DIRECTION
X $cyl.yaxis.x
Y $cyl.yaxis.y
Z $cyl.yaxis.z
ACCEPT
ZAXIS DIRECTION
X $cyl.zaxis.x
Y $cyl.zaxis.y
Z $cyl.zaxis.z
ACCEPT
ACCEPT
Select
SELECT CLEARLIST
SELECT ADD WORKPLANE 'tmpwkhelix'
DELETE
Before the cylinder is selected, clear the selection list using the
following command.
SELECT CLEARLIST
The command
INPUT SELECTION 'Select a cylinder'
If you click Yes, the macro exits. If you click No, the Select a
cylinder dialog appears.
8 Click Yes to exit the macro.
9 Run the macro again.
10 Select a couple of objects.
11 This time, when the Query dialog asks you whether to exit the
macro, click No.
12 The Select a cylinder dialog appears. Select a cylinder.
13 Click OK.
14 The two dialogs appear as described earlier asking for the pitch
and the number of turns. Enter values in each dialog and click
OK. The helix is created around the cylinder.
▪ If the helix is larger than the cylinder the following message
appears.
// Selecting a cylinder
INPUT SELECTION 'Select a cylinder'
IF $no_cyl {
PRINT ERROR 'You must select a single cylinder'
INPUT QUERY 'Do you want to exit the macro?' $prompt
IF $prompt {
RETURN
}
}
}
MODIFY
NAME tmpwkhelix
XAXIS DIRECTION
X $cyl.xaxis.x
Y $cyl.xaxis.y
Z $cyl.xaxis.z
ACCEPT
YAXIS DIRECTION
X $cyl.yaxis.x
Y $cyl.yaxis.y
Z $cyl.yaxis.z
ACCEPT
ZAXIS DIRECTION
X $cyl.zaxis.x
Y $cyl.zaxis.y
Z $cyl.zaxis.z
ACCEPT
ACCEPT
Select
SELECT CLEARLIST
SELECT ADD WORKPLANE 'tmpwkhelix'
DELETE
This tells you what is wrong. As soon as the user clicks OK, the
following command is carried out.
LET i = $i + 1
LET carry_on = ($i <= $numpts)
}
SELECT
EVERYTHING PARTIALBOX
// Selecting a workplane
INPUT SELECTION 'Select a workplane'
if $yesno {
} else {
Create geometry
Use this macro to create geometry to be used in the macro.
// this creates the geometry to be used in the macro
// Two intersecting planes are created and then a curve
is created from the intersection.
PRINCIPALPLANE XY
create surface PLANE
0
PRINCIPALPLANE ZX
create surface Plane
PLANE
0
SelectAll
create curve INTERSECT
ACCEPT
//
// set the name to be used for the curve
When LIVETEXT is on, this macro will not work; you cannot
enter live text using a variable.
// How to create text using a variable in a macro
// Livetext on does not work
//
//
TOOLS PREFERENCES
UNITPREFS
TEXTPREFS
TEXT LIVETEXT OFF
ACCEPT
//
STRING fred = 'wibble'
LET MYTEXT = 'fred'
// INPUT TEXT 'Enter some text' $fred
//
CREATE TEXT TEXT HORIZONTAL YES
0 0 0
ScrolledText $fred
Accept
TEXT FONT Arial
TEXT HEIGHT 0.3
TEXT PITCH 0.1
SELECT
select clearlist
//
Deleting pcurves
Use this macro to delete pcurves.
toolbar tools edit
toolbar tools fixing
TRIMREGIONEDIT
//
// The following command was added
//
EDITPCURVE
//
ADD_ALL_CURVES
DELETE
TOOLBAR TREDIT LOWER SELECT
SELECT CLEARLIST
Dynamic sectioning
Use this macro to create a dynamic section.
VIEW CLIPPLANES RAISE
VIEW CLIPPLANES EDGES ON
// Other conversions
//===================================
// inttoreal
// inttostring
// realtoint
// realtostring
// stringtoint
// stringtoreal
//====================================
EVERYTHING PARTIALBOX
select clearlist
// ----------------------------------------
// Close the file you are printing to
file outfile close
Using SWITCH
Use this macro to use SWITCH to define a variable which is
compared against a list of possible values.
// you need some objects in the model and some selected
// IF you have two objects selected it will DO case 2 and
the default
STYLE LOWERFORM
LET e = selection.number
PRINT $e
</HEAD>
<BODY>
</BODY>
</HTML>
3 Save the file as helix.htm.
<h1>Helix creation</h1>
<FORM NAME=helix>
</FORM>
</BODY>
2 Save the file.
The FORM object lets you to add controls that input data. It is
defined as follows:
<FORM NAME=helix>
</FORM>
The INPUT object lets you add controls inside the form. The code
has added two types of control:
▪ Text box
<INPUT TYPE=text NAME=radius VALUE="10" >
You can change the values in the text boxes and click the Apply
button, but, as yet, this application does nothing in PowerShape.
</script>
</HEAD>
2 Save the file.
The line with the two slashes // is a comment. The script is enclosed
in the following lines of code:
▪ <script language="VBscript">
</script>
The language used by the script is given in the first line.
The following command connects PowerShape using the object
called pshape:
▪ set pshape = Window.external
The following steps show you how to convert these commands into
vbscript commands:
1 In the script section, add the procedure called Apply_click() as
shown below.
<script language="VBscript">
// Connect to PowerShape
set pshape = Window.external
Sub Apply_click()
End Sub
</script>
2 Save the file.
<p>
X <INPUT TYPE=text NAME=x_text VALUE="0"> <p>
Y <INPUT TYPE=text NAME=y_text VALUE="0"> <p>
Z <INPUT TYPE=text NAME=z_text VALUE="0"> <p>
<hr>
2 Save the HTML file.
End Sub
Sub point_read()
End Sub
2 Save the HTML file.
In the first procedure, the code allows you to click points on the
screen. Remember the following command from the macro tutorial:
▪ INPUT POINT 'Position of centre' $cenpos
This is used in the application as follows:
▪ pshape.Exec "INPUT POINT 'Click origin' $pos"
You will notice that we added a zero to some of the variables, for
example:
document.helix.rad_text.value
This variable is a string, which represents a number. By adding the
zero to the variable, the string is converted into a number and used
in the expression.
Instead of removing the following command, we have turned it into
a comment by placing // in front of it:
//pshape.Exec "abs " & document.helix.radius.value & " 0 0"
This lets you to use the command again later.
Selecting objects
To extend the application so that it can create a helix around a
selected cylinder, you need to add another button to the interface:
1 Add the following code before the Apply button in the HTML file:
Create helix around a cylinder<p>
<INPUT TYPE=button VALUE="Select Cylinder"
onClick=cyl_select() >
<hr>
2 Save the HTML file.
End Sub
2 Save the HTML file.
Temporary workplane
To create the helix in the right direction along the cylinder, you can
use a temporary workplane.
In the Apply_click procedure, the commands can be updated to:
▪ Create a temporary workplane (see page 119)
▪ Input the first point of the helix relative to the temporary
workplane (see page 121)
▪ Delete the temporary workplane (see page 121)
MODIFY
NAME tmpwkhelix
XAXIS DIRECTION
X $cyl.xaxis.x
Y $cyl.xaxis.y
Z $cyl.xaxis.z
ACCEPT
YAXIS DIRECTION
X $cyl.yaxis.x
Y $cyl.yaxis.y
Z $cyl.yaxis.z
ACCEPT
ZAXIS DIRECTION
X $cyl.zaxis.x
Y $cyl.zaxis.y
Z $cyl.zaxis.z
ACCEPT
ACCEPT
<HTML>
<HEAD>
<script language="javascript">
// Connect to PowerShape
var pshape = window.external;
function Apply_click()
{
if (cylinder == true)
{
//create a workplane and modify it
pshape.Exec ("create workplane");
pshape.Exec ("$cyl.origin.x $cyl.origin.y $cyl.origin.z");
pshape.Exec ("MODIFY");
pshape.Exec ("NAME tmpwkhelix");
pshape.Exec ("XAXIS DIRECTION");
pshape.Exec ("X $cyl.xaxis.x");
pshape.Exec ("Y $cyl.xaxis.y");
pshape.Exec ("Z $cyl.xaxis.z");
pshape.Exec ("ACCEPT");
pshape.Exec ("YAXIS DIRECTION");
pshape.Exec ("X $cyl.yaxis.x");
pshape.Exec ("Y $cyl.yaxis.y");
pshape.Exec ("Z $cyl.yaxis.z");
function point_click()
{
//Send command to ask for user point input
pshape.Exec ("INPUT POINT 'Click origin' $pos")
} // end of function point_click
function cyl_select()
{
//Check if a single cylinder is selected
if (pshape.Evaluate("selection.number") == "1") {
if (pshape.Evaluate("selection.object[0].type") == "Cylinder")
//Cylinder selected
cylinder = true
}
if (cylinder == false)
{
//Tell user that 1 cylinder must be selected
//and exit the procedure
window.alert ("1 cylinder must be selected!");
return
} //end if
</script>
</HEAD>
<BODY>
<h1>Helix creation</h1>
<hr>
Input origin of the helix<p>
<INPUT TYPE=button VALUE=" Click Point " onClick="point_click();"
>
<INPUT TYPE=button VALUE=" Read Point " onClick="point_read();"
>
<p>
X <INPUT TYPE=text NAME=x_text VALUE="0"> <p>
Y <INPUT TYPE=text NAME=y_text VALUE="0"> <p>
Z <INPUT TYPE=text NAME=z_text VALUE="0"> <p>
<hr>
</FORM>
</BODY>
</HTML>
End Sub
</script>
Sub point_read()
//Extract the position input from the PowerShape
//variable $pos
document.helix.x_text.value = pshape.Evaluate("$pos_x")
document.helix.y_text.value = pshape.Evaluate("$pos_y")
document.helix.z_text.value = pshape.Evaluate("$pos_z")
End Sub
You cannot combine these commands into one procedure. If you do,
the following happens when you use the application.
▪ When the user clicks the position, the application continues to
the next command line without receiving the $pos data from
PowerShape.
▪ If you pause the application using the pshape.busy property, it
will loop.
Selecting objects
This topic describes how to use selected objects in your application.
You can use the following methods to select objects for use:
▪ Before it is run.
As soon as the application is run, you can use the selection
object information to interrogate the selection and then operate
on the selection.
▪ While it is running.
You need some method of telling the application that the objects
are selected. One way is to add a button to the application. When
you have selected the required objects, click the button to
complete the selection. You can then use the selection object
information (see page 142) to interrogate the selection and
operate on the selection.
For example:
Private Sub Cmd_cyl_Click()
'Check if a single cylinder is selected
If pshape.Evaluate("selection.number") = "1" Then
If pshape.Evaluate("selection.object[0].type") = "Cylinder" Then
TU-coordinates commands
Command Description
comassembly insert attachment inserts new attachment linked
linked_by_tu ["name of defn"] ["name to surface by tu-coordinate.
of attachment"] ["surface's
name"]/surface ID POINT/PLANE t-value
u-value
component_defn[name].attachment[na 1 if attachment is linked to
me].is_linked_by_tu surface by tu-coordinates; 0
otherwise.
component_defn["name"].attachment["n get t-value stored in
ame"].t attachment.
component_defn["name"].attachment["n get u-value stored in
ame"].u attachment.
Clipboard command
Command Description
clipboard.valid 1 if there is something on the
clipboard; 0 otherwise.
Cloud commands
Command Description
cloud[name].level returns the level that the
specified cloud is on.
cloud[name].exists 1 if the cloud exists, 0 otherwise.
cloud[name].id unique identity number of the
cloud in the model.
cloud[id n].name name of the cloud that has the
given identity number n.
cloud[name].style.colour colour number of line style used
to draw the cloud.
cloud[name].style.color color (USA) number of line style
used to draw the cloud.
cloud[name].style.gap gap of line style used to draw the
cloud.
cloud[name].style.weight weight of line style used to draw
the cloud.
cloud[name].style.width width of line style used to draw
the cloud.
Curve commands
Command Description
curve[name].exists 1 if curve exists; 0 otherwise.
curve[name].id unique identity number of the curve
in the model.
curve[id n].name name of the curve that has the given
identity number.
curve[name].description the description of the curve is stored
in the database.
curve[name].type checks the curve and returns one of
the following strings:
▪ Bézier
▪ Bspline
curve[name].number number of points in the curve.
curve[name].closed 1 if the curve is closed; 0 otherwise.
Dimension commands
The following groups of dimension commands are available:
Command Description
dimension[name].exists 1 if dimension exists; 0 otherwise.
dimension[name].id unique identity number of the
dimension in the model.
dimension[id n].name name of the dimension that has the
given identity number.
dimension[name].value value of dimension.
dimension[name].diameter 1 if the dimension measures a
diameter; 0 otherwise.
dimension[name].leader.style style name of the leader of the
dimension
dimension[name].leader.trim 1 if the option Trim leader to text is
on; 0 otherwise. The Trim leader to
text option trims the leader to the
position of the dimension annotation.
▪ 3 — alignment
dimension[name].tolerance.decimal number of decimal places of the
tolerance.
dimension[name].style.colour colour number of line style used to
draw the dimension.
dimension[name].style.color color (USA) number of line style used
to draw the dimension.
dimension[name].style.gap gap of line style used to draw the
dimension.
dimension[name].style.weight weight of line style used to draw the
dimension.
dimension[name].style.width width of line style used to draw the
dimension.
dimension[name].level level on which the dimension exists.
There are also commands to retrieve information on the position of the
dimension (see page 168).
Command Description
dimension[name].position.text coordinates [x, y, z] of the position of
the text of the dimension.
dimension[name].position.one coordinates [x, y, z] of position.one of
the dimension.
Drawing commands
The following drawing commands are available:
Command Description
drawing[name].exists 1 if drawing exists; 0 otherwise.
drawing[name].description description of the drawing.
drawing.number the number of drawings.
drawing[name].id unique identity number of the
drawing.
drawing[id n].name name of the drawing that has the
given identity number.
drawing.name[index] returns a drawing name where index
is greater than 0 and less than or
equal to the number of drawings.
drawing[name].width width of the drawing.
drawing[name].height height of the drawing.
drawing[name].template_model name of the model containing the
template_drawing used by the
drawing.
drawing[name].template_drawing name of the template drawing used
by the drawing.
drawing[name].tmpl_model_invalid 1 if the model, containing the
template drawing used by the
drawing, exists in the database; 0
otherwise.
drawing[name].tmpl_drawing_invalid 1 if the template drawing, used by the
drawing, exists; 0 otherwise.
drawing[name].views number of views on the drawing.
drawing[name].view.name[N] name of the Nth view on the drawing,
where
0 < N <= number of views.
drawing[name].no_of_items number of objects on the drawing.
drawing[name].view[view_name].needs 1 if the view needs updating; 0
updating otherwise.
Electrode commands
The following electrode commands are available:
Command Description
electrode.list list of all electrode names.
electrode.list.all
electrode.list.originals list of electrode names, excluding
copies.
electrode.list.copies list of electrode names of electrode
copies.
electrode[name].datum coordinates [x, y, z] of the origin of
the electrode's datum.
electrode[name].datum.x x coordinate of the origin of the
electrode's datum.
electrode[name].datum.y y coordinate of the origin of the
electrode's datum.
electrode[name].datum.z z coordinate of the origin of the
electrode's datum.
electrode[name].blank.name name of the electrode's blank.
electrode[name].blank.rectangular 1 if the blank is rectangular; 0 if it is
circular.
electrode[name].blank.length length of the electrode's blank.
electrode[name].blank.width width of the electrode's blank.
electrode[name].blank.diameter diameter of the electrode's blank.
electrode[name].blank.height height of the electrode's blank.
electrode[name].blank.material material of the electrode's blank.
electrode[name].holder.catalogue name of holder catalogue.
electrode[name].holder.base name of base holder.
electrode[name].holder.edm name of additional EDM holder.
electrode[name].holder.machining name of additional Machining holder.
electrode[name].holder.<base|machinin number of items that make up the
g|edm>.items base, machining or edm holder.
electrode[name].holder.<base|machinin
g|edm>.item.number
File commands
Command Description
file move file "pathname_from" move a file to another location.
"pathname_to"
file copy file "pathname_from" copy a file to another location.
"pathname_to"
file move dir "pathname_from]
[pathname_to" move a directory to another location.
file copy dir "pathname_from" copy a directory to another location.
"pathname_to"
file create dir "pathname" create a new directory.
file[name].exists 1 if file exists; 0 otherwise.
file[name].readable 1 if file is readable; 0 otherwise.
file[name].writeable 1 if file is writeable; 0 otherwise.
file[name].size returns file size in bytes.
file[name].mode 0 if file does not exists
1 if file
2 if directory.
directory[name].exists 1 if directory exists; 0 otherwise.
directory[name].readable 1 if directory is readable; 0 otherwise.
directory[name].writeable 1 if directory is writeable; 0
otherwise.
directory[name].mode 0 is directory does not exists
1 if file
2 if directory.
directory['pathname'].files['pattern'] returns a list of files in a directory.
Language command
Command Description
print language.summary the language and system locale settings
being used by PowerShape.
Line commands
The following line commands are available:
Command Description
line[name].start start coordinates [x, y, z] of the line.
line[name].start.x x coordinate of the start of the line.
line[name].start.y y coordinate of the start of the line.
line[name].start.z z coordinate of the start of the line.
line[name].end end coordinates [x, y, z] of the line.
line[name].end.x x coordinate of the end of the line.
line[name].end.y y coordinate of the end of the line.
line[name].end.z z coordinate of the end of the line.
line[name].exists 1 if line exists; 0 otherwise.
line[name].id unique identity number of the line in the
model.
line[id n].name name of the line that has the given
identity number.
line[name].length length of the line.
line[name].style.colour colour number of line style used to draw
the line.
Model commands
The following groups of model commands are available:
Command Description
model.selected name of the selected model.
model[name].selected 1 if the named model is selected; 0
otherwise.
model[name].exists 1 if the named model exists; 0
otherwise.
model[name].id unique identity number of the model.
model[id n].name name of the model that has the given
identity number.
model[name].open 1 if the named model is open; 0
otherwise.
Pcurve command
Command Description
pcurve[name].exists 1 if pcurve exists; 0 otherwise.
pcurve[name].number number of points in the pcurve.
pcurve[name].level level on which the pcurve exists.
pcurve[name].closed 1 if the pcurve is closed; 0 otherwise.
pcurve[name].id unique identity number of the pcurve
in the model.
pcurve[id n].name name of the pcurve that has the given
identity number.
pcurve[name].edge 1 if the pcurve is on the edge of a
surface; 0 otherwise.
pcurve[name].parent.name name of the surface on which the
pcurve lies.
pcurve[name].parent.id unique identification number of the
surface on which the pcurve lies.
pcurve[name].in_boundary 1 if the pcurve exists in any
boundary; 0 otherwise.
pcurve[name].start coordinates [x, y, z] of the start
position in the pcurve.
pcurve[name].start.xyz coordinates [x, y, z] of the start
position in the pcurve.
Point commands
Command Description
point[name].exists 1 if the point exists; 0 otherwise.
point[name].id unique identity number of the point in
the model.
point[id n].name name of the point that has the given
identity number.
point[name].description description of the point as stored in
the database.
point[name].position coordinates [x, y, z] of the point.
point[name].position.x x coordinate of the point.
point[name].position.y y coordinate of the point.
point[name].position.z z coordinate of the point.
point[name].style.colour colour number of line style used to
draw the point.
point[name].style.color color (USA) number of line style used
to draw the point.
point[name].style.gap gap of line style used to draw the
point.
point[name].style.weight weight of line style used to draw the
point.
point[name].style.width width of line style used to draw the
point.
point[name].level level on which the point exists.
Renderer commands
Command Description
renderer.has_hardware_triangles 1 if the hardware supports triangles; 0
otherwise.
renderer.has_depth_cueing 1 if the hardware supports depth
cueing; 0 otherwise.
renderer.has_anti_aliasing 1 if the hardware supports anti-
aliasing; 0 otherwise.
Sketcher command
Command Description
sketch 1 if Sketcher is on; 0 otherwise.
Solid commands
The following solid commands are available:
Command Description
solid[name].closest_face(x; y; z) returns a string representing the name of
the closest face of a solid to a given
point. Enter the point in current units
and absolute coordinates.
solid[name].exists 1 if the solid exists; 0 otherwise.
XXXX[entity_name].owner returns the Owner string
XXXX[entity_name].owner.id returns the Owner ID
XXXX[entity_name].owner.name returns the Owner Name
XXXX[entity_name].owner.type returns the Owner Type, where XXXX is a
solid.
solid_active retrieves the id of the active solid.
solid.active returns the name of the currently active
solid.
solid[name].id unique identity number of the solid in the
model.
solid[id n].name name of solid that has the given identity
number.
Features commands
Command Description
solid[name].feature[fname].exists 1 if the feature exists; 0 otherwise.
feature[fname].exists
solid[name].feature[fname].id the integer id of the feature.
feature[fname].id
solid[name].feature[fname].exists 1 if the feature exists; 0 otherwise.
feature[fname].exists
solid[name].feature[fname].name name of the feature.
feature[fname].name
solid[name].feature[fname].type type of feature (for example, " fillet",
feature[fname].type "boss").
solid[name].feature[fname].suppress 1 if the feature currently suppressed;
ed 0 otherwise.
feature[fname].suppressed
Holes commands
Command Description
solid[name].feature[fname].origin origin of the hole
solid[name].feature[fname].main_dep depth of the hole's main section
th
solid[name].feature[fname].main_dia diameter of the hole's main section
meter
solid[name].feature[fname].bore_dep depth of the hole's bore section (if any)
th
solid[name].feature[fname].bore_dia diameter of the hole's bore section (if
meter any)
solid[name].feature[fname].sink_dia diameter of the hole's sink section (if
meter any)
solid[name].feature[fname].tap_dept depth of the hole's tap section (if any)
h
solid[name].feature[fname].tap_diam diameter of the hole's tap section (if
eter any)
solid[name].feature[fname].tap_pitch pitch of the hole's tap section (if any)
pick face add name <face_name> Use these commands to add the named
pick face add <face_name> face to the current selection.
This is the same as holding down the
SHIFT key and left-clicking.
pick face toggle name <face_name> Use these commands to toggle the
pick face toggle <face_name> named face into/out of the current
selection.
This is the same as holding down the
CTRL key and left-clicking.
<face_name> can be a word, string, integer or variable. The following are
valid:
▪ pick face fred
▪ pick face 'fred'
▪ pick face 23
▪ string face_name = 'fred'
▪ pick face $face_name
The commands are also available during the following operations:
Surface commands
The following surface commands are available:
Command Description
surface[name].exists 1 if the surface exists; 0 otherwise.
surface[name].id unique identity number of the surface
in the model.
surface[id n].name name of surface that has the given
identity number.
surface[name].description description of the surface as stored in
the database
surface[1].tangentpoint(1;2;3;4;5;6) A point on a surface such that if
viewed from an outside point, the line
joining the two points is tangent to the
surface. The first three coordinates are
a point outside the surface and the
last three coordinates are the initial
guess point on the surface.
surface[name].direction unit vector of the reference direction
of the surface.
surface[name].direction.x x value of the unit vector of the
reference direction of the surface.
surface[name].direction.y y value of the unit vector of the
reference direction of the surface.
Spine commands
Command Description
surface[name].spine.exists 1 if the spine exists; 0 otherwise.
surface[name].spine.id unique identity number of the spine.
surface[id n].spine.name name of the spine that has the given
identity number.
surface[name].spine.number number of spine points.
surface[name].spine.length length of the spine.
surface[name].spine.length_between( length along the spine between spine
a; b) points a and b.
surface[name].spine.start start coordinates [x, y, z] of the spine.
surface[name].spine.start.x x coordinate of the start of the spine.
surface[name].spine.start.y y coordinate of the start of the spine.
surface[name].spine.start.z z coordinate of the start of the spine.
surface[name].spine.end end coordinates [x, y, z] of the spine.
surface[name].spine.end.x x coordinate of the end of the spine.
surface[name].spine.end.y y coordinate of the end of the spine.
surface[name].spine.end.z z coordinate of the end of the spine.
surface[name].spine.point[number] coordinates [x, y, z] of the spine point.
surface[name].spine.point[number].x x coordinate of the spine point.
surface[name].spine.point[number].y y coordinate of the spine point.
surface[name].spine.point[number].z z coordinate of the spine point.
surface[name].spine.point[number].ta unit vector of the tangent direction
ngent through the spine point.
Symbol commands
The following symbol commands are available:
Command Description
symbol[name].exists 1 if the symbol exists; 0 otherwise.
symbol[name].id unique identity number of the symbol
in the model.
symbol[id n].name name of the symbol that has the given
identity number.
symbol[name].position[pin number] coordinates [x, y, z] of the named pin.
symbol[name].position[pin x coordinate of the named pin.
number].x
symbol[name].position[pin y coordinate of the named pin.
number].y
symbol[name].position[pin number].z z coordinate of the named pin.
symbol[name].number number of pins in the symbol.
symbol[name].style.colour colour number of line style used to
draw the symbol.
symbol[name].style.color color (USA) number of line style used
to draw the symbol.
symbol[name].style.gap gap of line style used to draw the
symbol.
Units commands
Command Description
unit[type].name name of the units for type. For example,
type length's output can be mm.
unit[type].factor number by which the default unit is
multiplied by to give the units in
unit[type].name.
For example, type length has default units mm. If unit[length].name is inches,
then the unit[length].factor is 0.039370.
Window commands
Command Description
cwindow clear clears the Command window.
window.selected number of the selected window.
window.number number of windows opened.
window[name].exists 1 if the window exists; 0 otherwise.
window[name].id unique identity number of the window.
window[name].size size of the window in x and y.
window[name].size.x size of the window in x.
window[name].size.y size of the window in y.
window[name].type type of the window from one of the
following: model or drawing.
window[name].model name of the model opened in the window.
window[name].drawing name of the drawing if opened in the
window and a blank string otherwise.
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS
OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR
"LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR
OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS
PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU
ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS
LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO
BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF
SUCH TERMS AND CONDITIONS.
1. Definitions
Trademarks
The following are registered trademarks or trademarks of Autodesk,
Inc., and/or its subsidiaries and/or affiliates in the USA and other
countries: 123D, 3ds Max, ADSK, Alias, ArtCAM, ATC, AutoCAD LT,
AutoCAD, Autodesk, the Autodesk logo, Autodesk 123D, Autodesk
Alias, Autodesk Forge, Autodesk Fusion, Autodesk Inventor,
AutoSnap, BIM 360, Buzzsaw, CADmep, CAMduct, Civil 3D,
Configurator 360, Dancing Baby (image), DWF, DWG, DWG
(design/logo), DWG Extreme, DWG TrueConvert, DWG TrueView,
DWGX, DXF, Eagle, Ember, ESTmep, FBX, FeatureCAM, Flame,
FormIt 360, Fusion 360, The Future of Making Things, Glue, Green
Building Studio, InfraWorks, Instructables, Instructables (stylized
robot design/logo), Inventor, Inventor HSM, Inventor LT, Make
Anything, Maya, Maya LT, Moldflow, MotionBuilder, Mudbox,
Navisworks, Netfabb, Opticore, PartMaker, Pier 9, PowerInspect,
PowerMill, PowerShape, Publisher 360, RasterDWG, RealDWG,
ReCap, ReCap 360, Remake, Revit LT, Revit, Scaleform, Shotgun,
Showcase, Showcase 360, SketchBook, Softimage, Tinkercad,
TrustedDWG, VRED All other brand names, product names or
trademarks belong to their respective holders.
Disclaimer
THIS PUBLICATION AND THE INFORMATION CONTAINED HEREIN IS
MADE AVAILABLE BY AUTODESK, INC. "AS IS." AUTODESK, INC.
DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
REGARDING THESE MATERIALS.