Skip to main content
1-Visitor
March 19, 2018
Question

API query to retrieve document from product/folder

  • March 19, 2018
  • 1 reply
  • 3137 views

Hello,
I need a way to retrieve an existing WTDocument given an organization, a product, folder path and document name, using windchill API (Java code, no InfoEngine tasks), assuming there is only one document with that name in the folder (but could be more in different locations).

Could anyone give me a hand? Thank you!

1 reply

1-Visitor
March 21, 2018

You could implement something similar to https://community.ptc.com/t5/Windchill-Questions/Download-representation-and-annotation-of-a-WTDocument-in/td-p/150204

 

You would just need to modify to search for a WTDocument versus EPMDocument and add your additional where clauses.  Also, you would need to access the primary versus the secondary content with something similar to the code below.

public static void downloadFile (ApplicationData appData, String dlLoc, String fileName) 
{ System.out.println("start download file()"); System.out.println("=========="); try { File file = new File(dlLoc +"\\"+ fileName); System.out.println("temp path: "+ file); String filePath = file.getCanonicalPath(); InputStream istream =ContentServerHelper.service.findContentStream(appData); OutputStream ostream = new FileOutputStream(filePath); ContentServerHelper.service.writeContentStream(appData,filePath); istream.close(); ostream.close(); System.out.println("end downloadFile"); } catch (Exception e)
{ System.out.println("Exception occured,downloadFile"+ e); } } public static ApplicationData findPrimary(EPMDocument EPMDoc) throws WTException, PropertyVetoException
{ System.out.println("Starting findPrimary"); System.out.println("=========="); ApplicationData primaryNotFound = null; FormatContentHolder documentWithContents= (EPMDocument) ContentHelper.service.getContents(EPMDoc); @SuppressWarnings("unchecked") Vector<ContentItem> vector=ContentHelper.getContentList(documentWithContents); vector.addElement(ContentHelper.getPrimary(documentWithContents)); for (int i=0; i<vector.size(); i++) { if (vector.elementAt(i) instanceof ApplicationData) { ApplicationData appData = (ApplicationData)vector.elementAt(i); if(appData.getFileName().equals("{$CAD_NAME}")) { System.out.println("found primary content"); appData.setFileName(EPMDoc.getCADName()); System.out.println("Renamed file: " + appData.getFileName()); System.out.println("pass back to createZipList"); return appData; } }
} return primaryNotFound;
}