I am trying to create a macro where there is a prompt dialog that will show all my folders create in my toolpath tree. I want to select a folder in the prompt that is already created and activate it. How can I do that?
I need something like this
STRING LIST $FolderName = INPUT ENTITY MULTIPLE TOOLPATH "Select Folder"
Solved! Go to Solution.
Solved by tibor.vekasi. Go to Solution.
Solved by urizenYHS3W. Go to Solution.
Sample macro for folder selection:
FUNCTION Main() {
STRING FolderName=''
CALL SelectFolder('Toolpath','Please select a toolpath folder',$FolderName)
IF $FolderName !='' {
MESSAGE INFO $Foldername+' selected'
} ELSE {
MESSAGE INFO 'No folder selected'
}
}
FUNCTION SelectFolder(STRING FolderType,STRING Prompt,OUTPUT STRING Result) {
$Result=''
STRING LIST ValidFolderNames={'ncprogram','toolpath','tool','boundary','pattern','featureset','featuregroup','workplane','model','stockmodel'}
IF not member($ValidFolderNames,lcase($FolderType)) {
MESSAGE ERROR 'Invalid Name!'
RETURN
}
STRING LIST Folders = get_folders($FolderType)
IF (size($Folders) == 0) {
RETURN
}
$Folders=reverse($Folders)
STRING LIST F=tokens($Folders[0],'\')
STRING $cmd='EXPLORER SELECT $F[0] ROOT'
DoCommand $cmd
DEBUG EXPLORER KEY RIGHT_RECURSIVE
FOREACH ff in folders {
EXPLORER SELECT FOLDER $FF NEW
DEBUG EXPLORER KEY LEFT
}
$Folders=reverse($Folders)
STRING LIST ShortNames={}
INT I=length($FolderType)+1
STRING Space='........................'
FOREACH item in $Folders {
$F=tokens($item,'\')
INT S=size($f)
IF $S >12 {
MESSAGE INFO ' Sorry, only 12 sublevlel handled'
RETURN
}
IF $S >2 {
$F[1]=substring($Space,0,2*($S-2))+$F[size($F)-1]
}
INT J= add_last($ShortNames,$F[1])
}
INT C=-1
$C=INPUT CHOICE $ShortNames $Prompt
IF $C != -1 {
$Result=$Folders[$C]
$F=tokens($Folders[$C],'\')
STRING N=$F[0]
$i=1
DO {
$N=$N+'\'+$F[$i]
EXPLORER SELECT FOLDER $N NEW
DEBUG EXPLORER KEY RIGHT
$i=$i+1
} WHILE $i < size($F)
ACTIVATE FOLDER $N
}
}
Thanks @tibor.vekasi
Thats alot of lines just to pick a folder to activate.
When I try to add an active toolpath and deactivate the folder only the deactivation works. Any ideas why I can't add an active toolpath?
FUNCTION Main() { STRING FolderName='' CALL SelectFolder('Toolpath','Please select a toolpath folder',$FolderName) IF $FolderName !='' { // MESSAGE INFO $Foldername+' selected' } ELSE { // MESSAGE INFO 'No folder selected' } } FUNCTION SelectFolder(STRING FolderType,STRING Prompt,OUTPUT STRING Result) { $Result='' STRING LIST ValidFolderNames={'ncprogram','toolpath','tool','boundary','pattern','featureset','featuregroup','workplane','model','stockmodel'} IF not member($ValidFolderNames,lcase($FolderType)) { MESSAGE ERROR 'Invalid Name!' RETURN } STRING LIST Folders = get_folders($FolderType) IF (size($Folders) == 0) { RETURN } $Folders=reverse($Folders) STRING LIST F=tokens($Folders[0],'\') STRING $cmd='EXPLORER SELECT $F[0] ROOT' DoCommand $cmd DEBUG EXPLORER KEY RIGHT_RECURSIVE FOREACH ff in folders { EXPLORER SELECT FOLDER $FF NEW DEBUG EXPLORER KEY LEFT } $Folders=reverse($Folders) STRING LIST ShortNames={} INT I=length($FolderType)+1 STRING Space='........................' FOREACH item in $Folders { $F=tokens($item,'\') INT S=size($f) IF $S >12 { MESSAGE INFO ' Sorry, only 12 sublevlel handled' RETURN } IF $S >2 { $F[1]=substring($Space,0,2*($S-2))+$F[size($F)-1] } INT J= add_last($ShortNames,$F[1]) } INT C=-1 $C=INPUT CHOICE $ShortNames $Prompt IF $C != -1 { $Result=$Folders[$C] $F=tokens($Folders[$C],'\') STRING N=$F[0] $i=1 DO { $N=$N+'\'+$F[$i] EXPLORER SELECT FOLDER $N NEW DEBUG EXPLORER KEY RIGHT $i=$i+1 } WHILE $i < size($F) ACTIVATE FOLDER $N } EDIT FOLDER ; INSERT ; LAST DEACTIVATE FOLDER }
// get the list of toolpath folders
STRING LIST folders = get_folders('Toolpath')
// Let user pick one
INT idx = INPUT CHOICE folders "Pick a toolpath folder" // Now activate it
ACTIVATE FOLDER ${folders[idx]}
Thanks @urizenYHS3W
But why can't I insert the active toolpath to the active folder?
EDIT FOLDER ; INSERT ; LAST
Try this:
STRING act_tp = entity('toolpath','').Name EDIT FOLDER ; INSERT $act_tp LAST
INCLUDE SelectFolder.INC
FUNCTION Main() {
STRING FolderName=''
IF NOT entity_exists('toolpath','') {
MESSAGE INFO 'Please select a toolpath'
RETURN
}
STRING Tp=entity('toolpath','').Name
CALL SelectFolder('Toolpath','Please select a toolpath folder',$FolderName)
IF $FolderName !='' {
EDIT FOLDER $FolderName
INSERT $Tp LAST
}
}
sample for toolpath usermenu (MoveTp_mnu.mac 😞
//
// Sample for Toolpath usermenu (toolpath.xml)
//
// <button label="Move toolpaths to folder"
// command='MACRO MoveTp_mnu.mac "%s"'
// multiple_selection="allowed"/>
//
//
INCLUDE SelectFolder.INC
FUNCTION Main(STRING Tp) {
STRING FolderName=''
IF ($powermill.Status.MultipleSelection.Total == 0) {
CALL SelectFolder('Toolpath','Please select a toolpath folder',$FolderName)
IF $FolderName !='' {
EDIT FOLDER $FolderName
INSERT $Tp LAST
$FolderName=''
CALL ProjectPar('LastTpFolder',$FolderName)
}
} ELSEIF ($powermill.Status.MultipleSelection.First) {
CALL SelectFolder('Toolpath','Please select a toolpath folder',$FolderName)
CALL ProjectPar('LastTpFolder',$FolderName)
IF $FolderName !='' {
EDIT FOLDER $FolderName
INSERT $Tp LAST
}
} ELSEIF (powermill.Status.MultipleSelection.Last) {
CALL ProjectParGET('LastTpFolder',$FolderName)
IF $FolderName !='' {
EDIT FOLDER $FolderName
INSERT $Tp LAST
$FolderName=''
CALL ProjectPar('LastTpFolder',$FolderName)
}
} ELSE {
CALL ProjectParGET('LastTpFolder',$FolderName)
IF $FolderName !='' {
EDIT FOLDER $FolderName
INSERT $Tp LAST
}
}
}
FUNCTION ProjectPar(STRING par,STRING value) {
STRING IsEx =member(project._keys,$par)
IF ($IsEx == 0) {
edit par create STRING $par
}
${project[$par]} = $value
}
FUNCTION ProjectParGET(STRING par,OUTPUT STRING value) {
STRING IsEx =member(project._keys,$par)
IF ($IsEx == 0) {
edit par create STRING $par
${project[$par]} = $value
} ELSE {
STRING cmd="$"+"value ="+"$"+ "project."+$par
DoCommand $cmd
}
}
@tibor.vekasi I get a 'call to unknown function' error msg on this line
CALL SelectFolder('Toolpath','Please select a toolpath folder',$FolderName)
@urizenYHS3W Thanks, this worked
STRING act_tp = entity('toolpath','').Name EDIT FOLDER ; INSERT $act_tp LAST
Thanks! @tibor.vekasi never noticed that
@tibor.vekasi Do you know what is controlling the explorer slider to move to the top of the Toolpath tree? When I have a long list of toolpaths I have to always move the slider to the bottom of the Toolpath tree.
I would prefer that it didn't move at all, is that possible?
The attached SelectFolder_INC.zip contains two version of function:
-SelectFolder(STRING FolderType,STRING Prompt,OUTPUT STRING Result) - The original version
-SelectFolderNA(STRING FolderType,STRING Prompt,OUTPUT STRING Result) - modified version, without expand/collapse Explorer Tree.
Please overwrite previous version of include file, then replace in macros the function SelectFolder calls with SelectFolderNA
Perfect @tibor.vekasi
Hi
where I can find the full list of commands for macros?
Thanks
Go to Help->Documentation->Parameters->Reference and Help->Documentation->Parameters->Macro Programming Guide
Thank You
I saw it, but thought that there are other
That's actually the most complete doc available.
You can find some other ones on the former Delcam forum if you're lucky or try to ask here if you are missing one. Someone (and/or Autodesk) could have your answer also.
Olivier
ask here
how to close dialog box (query) in a macro (see the attachment)
Try to insert
DIALOGS ERROR OFF
DIALOGS MESSAGE OFF
before
@Mikhail_Voronin wrote:ask here
how to close dialog box (query) in a macro (see the attachment)