Skip to main content
1-Visitor
January 17, 2017
Question

Windchill API's to create the new Representation by using the local PVZ file for an EPMDocument and WTPart

  • January 17, 2017
  • 2 replies
  • 6087 views

Hello All,

      I'm having a secanrio that, the PVZ file of the specific assembly was saved in my local drive, I want to upload that PVZ file to the specific EPMDocument under Representations\annations using the utility (using java program). On top of that we will create Interference Definitiion Detection to that Representation to identify the Interference between the parts.

       By using the program I could able to create the representaion i.e., Derived image, but PVZ content upload in not happening that means representation is creating without the PVZ file.

Following is the program that I'm trying . PLease suggest me what I'm missing in the program.

  Representation newRep = null;

 

String localFile = "C:\\Users\\59381047_1.pvz";

 

File contentFile = new File(localFile);

 

System.out.println(Dumobj.getName());

try{

DerivedImage newDerImage = DerivedImage.newDerivedImage("default");

//System.out.println ("#######Derived image111 :" + newDerImage );

newDerImage.setRepresentable((Representable)wtDocObject);

newDerImage.setDefaultRepresentation(new Boolean(true));

newDerImage.setDerivationType((DerivationType)DerivationType.PART);

newDerImage.setRepresentationType((RepresentationType)RepresentationType.PRODUCT_VIEW);

  //newDerImage.setDerivedFromReference(ObjectReference.newObjectReference((Persistable)wtDocObject));

  newDerImage.setDomainRef(DomainAdministeredHelper.getAdminDomainRef((DomainAdministered)wtDocObject));

  newDerImage.setDescription("description");

Ownership newOwnership = Ownership.newOwnership(SessionHelper.getPrincipal());

  newDerImage.setOwnership(newOwnership);

  newDerImage.setDerivedFrom(wtDocObject);

  newDerImage.setCADPartName("vvvv");

  newRep = (Representation)PersistenceHelper.manager.save ((Representation)newDerImage);

 

// ContentServerHelper.service.writeContentStream(null, localFile);

  newRep = (Representation)newDerImage;

 

System.out.println("**** Derived image :" + newRep.toString() );

wt.pom.Transaction trx = new wt.pom.Transaction();

java.io.FileInputStream is = new java.io.FileInputStream(contentFile);

trx.start();

 

ApplicationData newAppData = ApplicationData.newApplicationData(wtDocObject);

newAppData.setFileName( contentFile.getName() );

System.out.println("*** " + newAppData.getFileName() + " " + newAppData.getFileSize());

// newAppData.set

 

ReferenceFactory rf = new ReferenceFactory();

WTReference wtref = rf.getReference(wtDocObject);

String Obid = rf.getReferenceString(wtref);

 

newAppData.setRole(ContentRoleType.toContentRoleType("SECONDARY"));

 

newAppData = wt.content.ContentServerHelper.service.updateContent( newRep, newAppData, (java.io.InputStream) is);

 

PublishUtils.createThumbnailPropertiesFile(localFile, null);

 

PublishHelper.storeRepresentation(newAppData, wtDocObject, contentFile, true, true, null, null, true, Obid, null, 0, null);

// newRep = (Representation) ContentServerHelper.service.updateHolderFormat((FormatContentHolder) newRep);

System.out.println("*** New content file uploaded "  );

 

System.out.println("*** " + newAppData.getFileName() + " " + newAppData.getFileSize());

PersistenceHelper.manager.save(newAppData);

  newRep = (Representation)PersistenceHelper.manager.save ((Representation)newRep);

 

Publisher pub = new Publisher();

  boolean result = pub.doPublish(true, true, Obid,PublishUtils.getConfigSpecFor(wtDocObject),true, "name", "description" , Publisher.PART);

 

// PublishHelper.storeWTPartRepresentation(PublishJob.doPublishJob(.);, wtDocObject, contentFile);

// PublishHelper.storeWTPartRepresentation(paramPublishJob, paramWTPart, paramFile)

System.out.println("********"+result);

trx.commit();

is.close();

 

}catch(Exception exp){

exp.printStackTrace();

2 replies

cmouli1-VisitorAuthor
1-Visitor
January 19, 2017

Hello Guys,

          Can anyone of you please suggest me, the correct API to achieve the above functionality.

15-Moonstone
January 19, 2017

Hi Chandra,

here is a one-line solution

Copy your PVZ file in a folder. In my example, /tmp/test, I use a unix server.

Next,  call :

import com.ptc.wvs.server.ui.RepHelper
RepHelper.loadRepresentation("/tmp/test","VR:wt.part.WTPart:141141",false,"representation name","representation description",true,true,true);

Arguments are :

  1. The PVZ location. Only one file
  2. The object ref of your PDMLink object
  3. Well, always false.
  4. Rep name
  5. rep description
  6. boolean : true -> default rep
  7. boolean : true -> create thumbnail
  8. boolean : true -> Keep PVZ

tested with loadFiles/wvs/demodata/worldcar/worldcar.pvz on a part :

Sélection_149.png

Sélection_150.png

cmouli1-VisitorAuthor
1-Visitor
January 20, 2017

HI olivier fresse

      Thank you very mcuh, I could able to upload the representation for WTPart and EPMDocument by using the API that you provided.