Executing a macro string variable as a command using DOCOMMAND
The macro command, DOCOMMAND, executes a macro string variable as a command. This enables you to construct a command from string variables and then have that command run as a macro statement. Suppose you have a function to create a copy of a boundary and then fit arcs to the copy:
FUNCTION CopyAndArcfit(ENTITY Ent) {
STRING $NewName = new_entity_name('boundary')
COPY BOUNDARY $Ent
EDIT BOUNDARY $NewName ARCFIT 0.01
}
If you then want to use the same function to copy a pattern and then fit arcs to the copy. You can replace all instances of 'boundary' with 'pattern' when you give the function a pattern entity. Unfortunately you cannot do this by using variables directly because the PowerMill command syntax does not allow variable substitution in network KEYWORDS for example you cannot use $Type
like this:
COPY $Type $Ent
However, you can build the command as a string and then use DOCOMMAND to execute the resulting string as a command:
FUNCTION CopyAndArcFit(Entity Ent) {
STRING $NewName = new_entity_name(Ent.RootType)
STRING Cmd = "COPY "+ Ent.RootType + " " + Ent.name
DOCOMMAND $Cmd
$Cmd = "EDIT " + Ent.RootType + " " + Newname + " ARCFIT 0.01"
DOCOMMAND $Cmd
}
You can use this technique whenever you find that a variable value cannot be used in a particular point in a command.