Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create macro to pick folder and activate it

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
iamcdn79
3305 Views, 22 Replies

Create macro to pick folder and activate it

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 i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

22 REPLIES 22
Message 2 of 23
tibor.vekasi
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
   }
}

 

 

Message 3 of 23
iamcdn79
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 i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 4 of 23
urizenYHS3W
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]}
Message 5 of 23
iamcdn79
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 i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 6 of 23
urizenYHS3W
in reply to: iamcdn79

Try this:

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


Message 7 of 23
tibor.vekasi
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
   }
}

Message 8 of 23
tibor.vekasi
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
}
}

Message 9 of 23
iamcdn79
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 i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 10 of 23
tibor.vekasi
in reply to: iamcdn79

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

 

Message 11 of 23
iamcdn79
in reply to: tibor.vekasi

Thanks! @tibor.vekasi never noticed that


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 12 of 23
iamcdn79
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 i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 13 of 23
tibor.vekasi
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

 

 

 

 

Message 14 of 23
iamcdn79
in reply to: tibor.vekasi

Perfect @tibor.vekasi


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 15 of 23
Mikhail_Voronin
in reply to: iamcdn79

Hi

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

 

Thanks

________________________________________
Mikhail
Message 16 of 23
iamcdn79
in reply to: Mikhail_Voronin

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


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 17 of 23
Mikhail_Voronin
in reply to: iamcdn79

Thank You

I saw it, but thought that there are other

________________________________________
Mikhail
Message 18 of 23
NanchenO
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

Message 19 of 23
Mikhail_Voronin
in reply to: NanchenO

ask here

 

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

 

 

 

________________________________________
Mikhail
Message 20 of 23
lbp1976
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)

 

 

 


 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report