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.

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

cmouli
1-Newbie

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

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();

5 REPLIES 5
cmouli
1-Newbie
(To:cmouli)

Hello Guys,

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

olivierfresse
13-Aquamarine
(To:cmouli)

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

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.

SYang
14-Alexandrite
(To:olivierfresse)

No timeout control for thumbnail creation (7. boolean : true -> create thumbnail) will cause a problem? Some of my particular CAD data gets stuck at Generating Thumbnail phase and loadRepresentation job will never end. If I can create Thumbnail separately after loading the PVZ file (7. boolean : false) , it would be more suitable for my case. See CS216138.

# Thumbnail generation

Generator tng = new Generator();

  String thumbNail = tng.generateThumbNail(dir, strFile, false);

olivierfresse
13-Aquamarine
(To:SYang)

The RepHelper create the thumbnail from the PVZ, and I've never seen an issue with that ?

Top Tags