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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How can I use the Windchill API's to upload EPMDocument content files?


How can I use the Windchill API's to upload EPMDocument content files?


I was able to create the EPMDocument, but I can not register the content file(**.mi or **.drw) with Windchill API's.
Below is the source code.
How can I use the Windchill API's to upload EPMDocument content files?




private static void createEPMDocument(String s, String name, String cadName) {
  try {
   // Set owner application
   // Set Authoring Application (required in EPMAuthoringAppType.rbInfo)
   EPMAuthoringAppType at = EPMAuthoringAppType.toEPMAuthoringAppType("COCRDRAFT");
   // Set EPMDocumentType (required in EPMDocumentType.rbInfo)
   EPMDocumentType dt = EPMDocumentType.toEPMDocumentType("CADCOMPONENT");
   EPMDocument epmDoc = EPMDocument.newEPMDocument(null, name, at, dt, cadName);
   epmDoc.setDescription("Created by");
   // epmDoc.setInstance(true); //need family table

   QueryResult qr = new QueryResult();
   QuerySpec qs = new QuerySpec(wt.pdmlink.PDMLinkProduct.class);
   SearchCondition sc = new SearchCondition(wt.pdmlink.PDMLinkProduct.class, wt.pdmlink.PDMLinkProduct.NAME,
     SearchCondition.EQUAL, s, false);
   qr = wt.fc.PersistenceHelper.manager.find(qs);
   FolderHelper.assignLocation(epmDoc, "/Default",
     WTContainerRef.newWTContainerRef((PDMLinkProduct) qr.nextElement()));;


  } catch (WTException | WTPropertyVetoException e) {



Below is some code to update a WTDocument.

In fact this code does more thatn you need as it replaces the primary content, you can get rid of the cleanup part.


It's the same code for an EPMdocument, as it is a primary content holder.

But this not so easy and not recommanded at all, as described here :


EPMDocument are very special beasts because of all the CAD dependency management.

I don't know what's the CAD system you use, but if it's Creo, you'll have to manage family table, assemblies , dependencies between drawing, formarts,... and so many complex tasks.


Anyway, the code :


// some ; missing int the import, groovy console :-)
wt.container.batch.BatchContainer import wt.container.batch.BatchContainerFactory import wt.container.batch.TransactionContainer import wt.content.ApplicationData import wt.content.ContentHelper import wt.content.ContentHolder import wt.content.ContentItem import wt.content.ContentServerHelper import wt.content.FormatContentHolder import wt.doc.WTDocument import wt.fc.PersistenceHelper import wt.pom.Transaction import wt.util.WTException Transaction trx = new Transaction(); WTDocument aDocument; File fic; try { trx.start(); ContentHolder holderDocument = ContentHelper.service.getContents(aDocument); ContentItem primaryContent = ContentHelper.getPrimary((FormatContentHolder) holderDocument); ApplicationData newAppData = ApplicationData.newApplicationData((ContentHolder) aDocument); newAppData.setFileName(fic.getName()); // Cleanup TransactionContainer transactionContainer = BatchContainerFactory.instantiateTransactionContainer(); BatchContainer contentBatchContainer = BatchContainerFactory.instantiateGeneralBatchContainer(transactionContainer, "contents"); transactionContainer.clearAll(); if (PersistenceHelper.isPersistent(aDocument)) { aDocument = (WTDocument) ContentHelper.service.getContents(aDocument); java.util.Vector vector = ContentHelper.getContentList(aDocument); if (vector != null) { contentBatchContainer.populate(vector.elements()); } Enumeration enumContents = vector.elements(); while (enumContents.hasMoreElements()) contentBatchContainer.remove(enumContents.nextElement()); } aDocument = (WTDocument) ContentHelper.service.contentUpdateUpload(aDocument, transactionContainer); ContentServerHelper.service.updatePrimary((FormatContentHolder) aDocument, newAppData, new FileInputStream(fic)); trx.commit(); trx = null; } catch (Exception u) { throw new WTException(u.getMessage()); } finally { if (trx != null) { trx.rollback(); } }


Thank you for your kind explanation.
I made it and understood the risk well.