PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
This page has been translated for your convenience with an automatic translation service. This is not an official translation and may contain errors and inaccurate translations. Autodesk does not warrant, either expressly or implied, the accuracy, reliability or completeness of the information translated by the machine translation service and will not be liable for damages or losses caused by the trust placed in the translation service. To translate this discussion, select the language.

PowerMill Forum

Reply
Highlighted
Post 1 of 21
Accepted Solution

Create macro to pick folder and activate it

446 Views, 20 Replies
02-23-2017 06:08 AM

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"

 

______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit
// 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]}

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
}
}

Post 2 of 21

Re: Create macro to pick folder and activate it

02-23-2017 01:30 PM in reply to: iamcdn79

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
   }
}

 

 

Post 3 of 21

Re: Create macro to pick folder and activate it

02-23-2017 02:20 PM in reply to: tibor.vekasi

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
}
______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit
Post 4 of 21

Re: Create macro to pick folder and activate it

02-23-2017 02:58 PM in reply to: iamcdn79
// 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]}
Post 5 of 21

Re: Create macro to pick folder and activate it

02-23-2017 03:20 PM in reply to: urizenYHS3W

Thanks @urizenYHS3W

 

But why can't I insert the active toolpath to the active folder?

EDIT FOLDER ; INSERT ; LAST

 

______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit
Post 6 of 21

Re: Create macro to pick folder and activate it

02-23-2017 04:08 PM in reply to: iamcdn79

Try this:

STRING act_tp = entity('toolpath','').Name
EDIT FOLDER ; INSERT $act_tp LAST


Post 7 of 21

Re: Create macro to pick folder and activate it

02-23-2017 10:44 PM in reply to: iamcdn79

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
   }
}

Post 8 of 21

Re: Create macro to pick folder and activate it

02-23-2017 11:29 PM in reply to: tibor.vekasi

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
}
}

Post 9 of 21

Re: Create macro to pick folder and activate it

02-24-2017 04:13 AM in reply to: tibor.vekasi

@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
______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit
Post 10 of 21

Re: Create macro to pick folder and activate it

02-24-2017 04:33 AM in reply to: iamcdn79

The 7.post and 8.post attached zip contains "SelectFolder.INC"

 

Post 11 of 21

Re: Create macro to pick folder and activate it

02-24-2017 04:39 AM in reply to: tibor.vekasi

Thanks! @tibor.vekasi never noticed that

______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit
Post 12 of 21

Re: Create macro to pick folder and activate it

02-24-2017 06:47 AM in reply to: tibor.vekasi

@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?

______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit
Post 13 of 21

Re: Create macro to pick folder and activate it

02-24-2017 09:42 AM in reply to: iamcdn79

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

 

 

 

 

Post 14 of 21

Re: Create macro to pick folder and activate it

02-24-2017 10:55 AM in reply to: tibor.vekasi

Perfect @tibor.vekasi

______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit

Re: Create macro to pick folder and activate it

03-03-2017 12:15 AM in reply to: iamcdn79

Hi

where I can find the full list of commands for macros?

 

Thanks

________________________________________
Live and learn
Post 16 of 21

Re: Create macro to pick folder and activate it

03-03-2017 04:48 AM in reply to: Mikhail_Voronin

Go to Help->Documentation->Parameters->Reference and Help->Documentation->Parameters->Macro Programming Guide

______________________
Intel Core i7 5930K @ 3.5 GHz
NVIDIA Quadro K2000 2 GB
PNY 500 GB SSD
Corsair 32 GB DDR4 2666 MHz RAM
Windows 10 Professional 64-bit

Re: Create macro to pick folder and activate it

03-03-2017 05:28 AM in reply to: iamcdn79

Thank You

I saw it, but thought that there are other

________________________________________
Live and learn
Post 18 of 21

Re: Create macro to pick folder and activate it

03-03-2017 06:31 AM in reply to: Mikhail_Voronin

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

Re: Create macro to pick folder and activate it

03-15-2017 03:59 AM in reply to: NanchenO

ask here

 

how to close dialog box  (query) in a macro (see the attachment)

 

 

 

________________________________________
Live and learn
Post 20 of 21

Re: Create macro to pick folder and activate it

03-15-2017 07:09 AM in reply to: Mikhail_Voronin

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)

 

 

 


 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post