cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Create a folder automatically Windchill 10.1

ptc-4995365
1-Newbie

Create a folder automatically Windchill 10.1

Hi,



There is a way to automatically create a folder in a product if this isn't exist?, by customization or configuration.



Thanks for the info that can provide me

3 REPLIES 3

Are you talking about a load file? That can be done. Customization sure, that should be easy. There is an API for that. What is the trigger for creating a folder?

The below code snippet helps your requirement...little modification is
required.


public static void creatDirectory(String array[], WTContainerRef
containerRef){


String path = ((WTContainer)
containerRef.getObject()).getDefaultCabinet().getFolderPath();

if(array != null){
int len = array.length;

Folder folder = null;

for(int i = 0; i < len; i++){

try {

folder = FolderHelper.service.getFolder(path, containerRef);

path = path + '/' + array[i];

QueryResult result = FolderHelper.service.findSubFolders(folder);


if(!checkFolder(result,array[i])){

FolderHelper.service.createSubFolder(path, containerRef);
}


} catch (WTException e) {

e.printStackTrace();

} } } }


public static boolean checkFolder(QueryResult result, String str){

if(result == null){
return false;
}
while(result.hasMoreElements()){

Object object = result.nextElement();

if(object instanceof SubFolder){

SubFolder subfolder = (SubFolder)object;

if(subfolder.getName().equals(str)){

return true;

}

}
else{
return false;
}

}

return false;
}




Antonio:


The trigger is a process for upload a bunch of documents, already a customization, but if this process does not find the folder throws the document in the root folder, i'm looking for a way to improve it.



Gangadharan:


thanks for the answer, i will try your script

Top Tags