Needing macro help with proper use and reference of $tool.type ....,

Needing macro help with proper use and reference of $tool.type ....,

stheroux
Contributor Contributor
2,515 Views
23 Replies
Message 1 of 24

Needing macro help with proper use and reference of $tool.type ....,

stheroux
Contributor
Contributor

Using tool.xml user menu with multiple selection function, I am stuck on how to find all $tool.types in folder 'tool'.

Then based on results, create individual folders (eg. BallNose, TipRad, TippedDisc....,) for found $tool.types and move each tool.type to corresponding tool.type folder created.

 

 

 

0 Likes
Accepted solutions (1)
2,516 Views
23 Replies
Replies (23)
Message 21 of 24

Anonymous
Not applicable

Some Powermill commands do not work well with variables, in which case the DoCommand statement should be used.

Please run  the next example  in debugger step by step:

STRING T=folder('tool')[0].Name
ACTIVATE TOOL $T // -working
DELETE TOOL $T // -working
EDIT RECYCLER RECOVER Tool $T // -working
FORM TOOL $T  // -not working
// Use instead the next sequence
STRING CMD="FORM TOOL '"+$T+"'"
DoCommand $CMD // -working

 

0 Likes
Message 22 of 24

stheroux
Contributor
Contributor

I ran both instances and they both work perfect!

Selects first tool, deletes it, recovers from trash and raises the tool form.

 

 

0 Likes
Message 23 of 24

stheroux
Contributor
Contributor

If you are running this to remove tools from a folder, it does not work if tool has been used.

If you use tool.xml user menu, add this macro to it. 

Select all tools you want to remove and run macro through user.xml

 

Function Main( STRING $Selected ) {
STRING LIST $ToolNames = {}
CALL Get_Tool_List($Selected, $ToolNames)
STRING $FULL = ''
STRING $DIR = ''
DIALOGS MESSAGE OFF
FOREACH $T IN $ToolNames {
$FULL = $pathname('tool', '$T')
$DIR = $dirname('$FULL')
EDIT FOLDER $DIR REMOVE $T
}
}
Function Get_Tool_List(
STRING $Selected
OUTPUT STRING LIST $Selected_Tools
)
{
If $powermill.Status.MultipleSelection.total == 0 OR $powermill.Status.MultipleSelection.First {
IF NOT member(project._keys,"Multiple_Selected_Names") {
EDIT PAR CREATE STRING "Multiple_Selected_Names"
}
$Project.Multiple_Selected_Names = ""
} ELSE {
$Project.Multiple_Selected_Names = $Project.Multiple_Selected_Names + "\"
}
$Project.Multiple_Selected_Names = $Project.Multiple_Selected_Names + $Selected
IF NOT($powermill.Status.MultipleSelection.Last or $powermill.Status.MultipleSelection.total == 0) {
MACRO ABORT
}
$Selected_Tools = TOKENS($Project.Multiple_Selected_Names, "\")
}

 

0 Likes
Message 24 of 24

Anonymous
Not applicable

The next code working  (PM2017)

 

FUNCTION Main( STRING $Selected ) {
   STRING LIST $ToolNames = {}
   CALL Get_Tool_List($Selected, $ToolNames)
   STRING $FULL = ''
   STRING $DIR = ''
   DIALOGS MESSAGE OFF
   FOREACH $T IN $ToolNames {
      $FULL = $pathname('tool', '$T')
      $DIR = $dirname($FULL)
      IF $DIR != 'Tool' {
         STRING Cmd="EDIT FOLDER '"+$DIR+"' REMOVE '"+$T+"'"
         DoCommand $Cmd
      }
   }
}
FUNCTION Get_Tool_List(
STRING $Selected
OUTPUT STRING LIST $Selected_Tools
)
{
   IF $powermill.Status.MultipleSelection.total == 0 OR $powermill.Status.MultipleSelection.First {
      IF NOT member(project._keys,"Multiple_Selected_Names") {
         EDIT PAR CREATE STRING "Multiple_Selected_Names"
      }
      $Project.Multiple_Selected_Names = ""
   } ELSE {
      $Project.Multiple_Selected_Names = $Project.Multiple_Selected_Names + "\"
   }
   $Project.Multiple_Selected_Names = $Project.Multiple_Selected_Names + $Selected
   IF NOT($powermill.Status.MultipleSelection.Last or $powermill.Status.MultipleSelection.total == 0) {
      MACRO ABORT
   }
   $Selected_Tools = TOKENS($Project.Multiple_Selected_Names, "\")
}

Same result, but shortest:

FUNCTION Main( STRING $Selected ) {
   STRING $DIR = $dirname(pathname('tool',$Selected))
   IF $DIR != 'Tool' {
      STRING Cmd="EDIT FOLDER '"+$DIR+"' REMOVE '"+$Selected+"'"
      DoCommand $Cmd
   }
}

 

0 Likes