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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Translate the entire conversation x

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

hotpepper
4-Participant

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

Hi,

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?

Thanks,

 

-----

private static void createEPMDocument(String s, String name, String cadName) {
  try {
   // Set owner application
   EPMContextHelper.setApplication(EPMApplicationType.toEPMApplicationType("EPM"));
   // 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 TPWCreateEPMDocument.java");
   // 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);
   qs.appendSearchCondition(sc);
   qr = wt.fc.PersistenceHelper.manager.find(qs);
   FolderHelper.assignLocation(epmDoc, "/Default",
     WTContainerRef.newWTContainerRef((PDMLinkProduct) qr.nextElement()));

 

   PersistenceHelper.manager.save(epmDoc);

 

  } catch (WTException | WTPropertyVetoException e) {
   e.printStackTrace();
  }
 }

-----

2 REPLIES 2

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 : 

 

https://www.ptc.com/en/support/article?n=CS107408&language=en&posno=2&q=EPMDocument.newEPMDocument&ProductFamily=Windchill%7CWPA&source=search

 

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 :-)
import
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.

Announcements
Top Tags