Project folder

Project folder

Felipe_Callegario
Advocate Advocate
1,967 Views
8 Replies
Message 1 of 9

Project folder

Felipe_Callegario
Advocate
Advocate

Could anyone help me find a solution to my problem. in the macro below it takes me only to the main directory, but I would like to go further and select the folders that are inside them, I will use this macro to save the project.

 

STRING dirPadrao = "C:\Users\09689322\Desktop\Projetos PowerMill\" //alterar o diretório padrão de projetos

STRING $mName = folder("model")[0].Name
STRING LIST $List_dir = list_files('dirs', $dirPadrao)
INT $Felipe = INPUT CHOICE $List_dir "Selecione o diretório."

0 Likes
Accepted solutions (1)
1,968 Views
8 Replies
Replies (8)
Message 2 of 9

Y.Mahran
Contributor
Contributor

Hi @Felipe_Callegario,

 

If you want to access these sub folders then simply use

list_files('dirs+', $dirPadrao)

instead of

list_files('dirs', $dirPadrao)

 

 

 

And here is an example to show the difference between them, for the following directory:

Temp.png

 

 

 

This code:

STRING SearchPath = "C:\Users\hp\Desktop\TestFolder"
STRING LIST FoldersList = list_files("dirs", SearchPath)
FOREACH file in FoldersList {
PRINT $file
}

 

Will return only return this:

C:/Users/hp/Desktop/TestFolder/TestFolder1
C:/Users/hp/Desktop/TestFolder/TestFolder2
C:/Users/hp/Desktop/TestFolder/TestFolder3

 

 

 

 

 

While this one:

STRING SearchPath = "C:\Users\hp\Desktop\TestFolder"
STRING LIST FoldersList = list_files("dirs+", SearchPath)
FOREACH file in FoldersList {
PRINT $file
}

 

will include the sub folders:

C:/Users/hp/Desktop/TestFolder/TestFolder1
C:/Users/hp/Desktop/TestFolder/TestFolder1/a
C:/Users/hp/Desktop/TestFolder/TestFolder1/b
C:/Users/hp/Desktop/TestFolder/TestFolder2
C:/Users/hp/Desktop/TestFolder/TestFolder2/1
C:/Users/hp/Desktop/TestFolder/TestFolder2/2
C:/Users/hp/Desktop/TestFolder/TestFolder3
C:/Users/hp/Desktop/TestFolder/TestFolder3/c
C:/Users/hp/Desktop/TestFolder/TestFolder3/d

 

 

 

 

Hope that my reply is helpful to you.

0 Likes
Message 3 of 9

Felipe_Callegario
Advocate
Advocate

First of all I would like to thank you for your answer, but what I need is to be able to choose the folders for me to get to the folder where I want to save the projects.

0 Likes
Message 4 of 9

Y.Mahran
Contributor
Contributor
Accepted solution

Hi @Felipe_Callegario ,

 

It seems like you want to "Save As" the project according to the model name & current date (modelName_dd-mm-yyyy), into a certain folder. The following macro lists the folders in the project directory and asks you to choose the folder to "Save As" the project into.

 

 

 

 

 

 

Hope that this macro is helpful to you.

 

// Initializing some variables
RESET LOCALVARS 
STRING mainDirectory = dirname(project_pathname(0), "/")
STRING LIST foldersPathList = list_files("dirs", mainDirectory)


// looping over folders
BOOl matchFound = 0
WHILE (True) {
	// Asking the user to choose a folder to "Save As" the project into
	INT C = INPUT CHOICE $foldersPathList "Choose a folder: "
	STRING choosenFolderPath = foldersPathList[C]
	STRING choosenFolderName = basename(choosenFolderPath, "/")
	STRING queryMsg = "The choosen folder: " + choosenFolderName + crlf + "Yes = Confirm" + crlf + "No = Choose a Sub-Folder"
	$matchFound = Query $queryMsg
	
	// Asking the user whether to confirm the choosen folder or explore sub-folders
	// If the user confirms the choice, then, the macro "Save As" the project using the model name & current date
	IF ($matchFound) {
		OBJECT time = local_time(time())
		STRING currentDate = time.day + "-" + time.month + "-" + time.year
		ENTITY LIST myModel = folder("Model")[0]
		STRING projectSaveName = myModel.Name + "_" + currentDate
		CD $choosenFolderPath
		PROJECT SAVE AS $projectSaveName
		BREAK  
	} ELSE {
		$foldersPathList = list_files("dirs", choosenFolderPath)
		IF is_empty(foldersPathList) {
		  MESSAGE ERROR "There is no sub-folder in (" + choosenFolderName + ")"
		  MACRO ABORT
		}
	}
} 

 

 

 

Message 5 of 9

Felipe_Callegario
Advocate
Advocate

Excellent, thank you very much for your help.

0 Likes
Message 6 of 9

phocvet
Enthusiast
Enthusiast

Is there a way to list the files that have been run to export the nc program?

phucx6c_0-1669362438286.png

 

0 Likes
Message 7 of 9

nubrandao
Collaborator
Collaborator

Nice macro, how do i change the default directory?

the macro show everthing in c:\

 

i want to d:\projects

0 Likes
Message 8 of 9

nubrandao
Collaborator
Collaborator

how do i change directory to d:\Project

0 Likes
Message 9 of 9

Felipe_Callegario
Advocate
Advocate

Just today I saw your request, you must enter your directory replacing where I will leave it demarcated. "mainDirectory"

 

 

// Initializing some variables
RESET LOCALVARS 
STRING mainDirectory = dirname(project_pathname(0), "/")
STRING LIST foldersPathList = list_files("dirs", mainDirectory)
 
 
// looping over folders
BOOl matchFound = 0
WHILE (True) {
// Asking the user to choose a folder to "Save As" the project into
INT C = INPUT CHOICE $foldersPathList "Choose a folder: "
STRING choosenFolderPath = foldersPathList[C]
STRING choosenFolderName = basename(choosenFolderPath, "/")
STRING queryMsg = "The choosen folder: " + choosenFolderName + crlf + "Yes = Confirm" + crlf + "No = Choose a Sub-Folder"
$matchFound = Query $queryMsg
 
// Asking the user whether to confirm the choosen folder or explore sub-folders
// If the user confirms the choice, then, the macro "Save As" the project using the model name & current date
IF ($matchFound) {
OBJECT time = local_time(time())
STRING currentDate = time.day + "-" + time.month + "-" + time.year
ENTITY LIST myModel = folder("Model")[0]
STRING projectSaveName = myModel.Name + "_" + currentDate
CD $choosenFolderPath
PROJECT SAVE AS $projectSaveName
BREAK  
} ELSE {
$foldersPathList = list_files("dirs", choosenFolderPath)
IF is_empty(foldersPathList) {
  MESSAGE ERROR "There is no sub-folder in (" + choosenFolderName + ")"
  MACRO ABORT
}
}
0 Likes