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

We are happy to announce the new Windchill Customization board! Learn more.

API to Programatically Export Product/Library Templates

StuartHarvey
6-Contributor

API to Programatically Export Product/Library Templates

I need to build a couple of development boxes. I would like to build empty systems with the same products, folders, lifecycles, etc. as the productions boxes. I was thinking that if I could programatically export templates of each of the products it would be easy to rebuild the system framework using loadfiles.



What API is there to export Product/Library Templates.



Stuart

6 REPLIES 6

Stuart,

There is an API for this, but I cannot recall where. With Eclipse you can search API for export. Alternatively follow the action OOTB to reverse and follow it that way to the API. You'll still need a loadfile to load the templates and establish the instances.






Sent from my Verizon Wireless 4G LTE Smartphone

Hi Stuart,

Were you able to find that API that would automatically export Product/Library Templates?


I am currently in search for such APIs and its methods. It would be really helpful, if you could give some information about it


Thanks in Advance.


Thanks,

Ganesh.


It works with following method:

/**
* Saves the context template to disk
*
* @param template
* @param basePath
* @param filename
*/
public static void saveContainerTemplateToDisk(WTContainerTemplateMaster template, Path basePath, String filename) throws WTException {

  DefaultWTContainerTemplate containerTemplate = template.getContainerTemplate();
   Path filePath = basePath.resolve(filename);
   logger.debug("filePath = " + filePath);
   File file = filePath.toFile();

   InputStream inputStream = null;
   OutputStream outputStream = null;
   QueryResult queryResult;
  try {

  queryResult = ContentHelper.service.getContentsByRole(containerTemplate, ContentRoleType.BUSINESS_JAR);
  if (queryResult.size() == 1) {

  ContentItem contentItem = (ContentItem) queryResult.nextElement();
  if (contentItem instanceof ApplicationData) {

   if (!file.getParentFile().exists()) {

  file.getParentFile().mkdirs();
   }

   if (file.exists()) {

  file.delete();
   }

  ApplicationData applicationData = (ApplicationData) contentItem;
   Streamed streamed = (Streamed) applicationData.getStreamData().getObject();
   inputStream = streamed.retrieveStream();
   outputStream = new FileOutputStream(file);
  int read;
  byte[] bytes = new byte[1024];
  while ((read = inputStream.read(bytes)) != -1) {

  outputStream.write(bytes, 0, read);
   }

  }

  }

  } catch (WTException e) {

   throw new WTException(e);
   } catch (FileNotFoundException e) {

  e.printStackTrace();
   } catch (IOException e) {

  e.printStackTrace();
   } finally {

   if (inputStream != null) {

   try {

  inputStream.close();
   } catch (IOException e) {

  e.printStackTrace();
   }

  }

   if (outputStream != null) {

   try {

  outputStream.close();
   } catch (IOException e) {

  e.printStackTrace();
   }

  }

  }

}

Hi Bjorn,

Thanks for your quick response.

If I am understanding it correctly, the code that you have shared writes a Template to the Disk.

What I wanted is, that I need to extract the configurations of a Existing product and save it or export it as a Template. And I cant seem to find the API which will extract the configurations of this existing product to a template. Please let me know if you have any information about this.

Thanks in advance.

Regards,

Ganesh.

I haven't done it. But perhaps you can have a look in the class

com.ptc.netmarkets.product.NmProductCommands

Method:

saveProductAsInternalTemplate

Hi Bjorn,

Thanks for the Tip

I will look into this method.

Regards,

Ganesh.

Top Tags