Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
I . . I'm a windchill starter user and i have skills in JAVA , now i'm trying to construct a Expression in Workflow Template Administrator and i need to get the PDF (Representation File) from a EPM Document received in a Promotion Request and copy that to a specific folder ...
I get this piece of code from internet but i get errors showed in bottom...
try{
QueryResult theQueryResult = MaturityHelper.service.getPromotionTargets(thePromotionNotice);
Versioned theVersioned = null ;
if (theQueryResult != null){
while(theQueryResult.hasMoreElements()){
theVersioned = (Versioned)theQueryResult.nextElement();
if (theVersioned instanceof EPMDocument) { ... }
}
}
catch(...){}
//primaryBusinessObject
QueryResult theQueryResult;
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;
try{
theQueryResult = MaturityHelper.service.getPromotionTargets(pn);
Versioned theVersioned = null ;
if (theQueryResult != null){
while(theQueryResult.hasMoreElements()){
theVersioned = (Versioned)theQueryResult.nextElement();
if (theVersioned instanceof EPMDocument) {
System.out.println("IS A EPM DOCUMENT");
//É Preciso procurar o PDF AGORA.....
System.out.println("NOW GET THE PDF DOCUMENT");
// . . .
}else{
System.out.println("THIS IS NOT AN EPM");
}
}
}
}catch(Exception e){
System.out.println("ERROR EXPORTING PDF: " + e.getMessage());
errorMsg = "ERROR EXPORTING PDF Promotion Request: " + e.getMessage();
}
Five errors reported in check Syntax..
1) WfExpression45853891.java:36: cannot find symbol
symbol : class QueryResult
location: class wt.workflow.expr.WfExpression45853891
QueryResult theQueryResult;
^
2) WfExpression45853891.java:39: package MaturityHelper does not exist
theQueryResult = MaturityHelper.service.getPromotionTargets(pn);
^
3) WfExpression45853891.java:40: cannot find symbol
symbol : class Versioned
location: class wt.workflow.expr.WfExpression45853891
Versioned theVersioned = null ;
^
4) WfExpression45853891.java:43: cannot find symbol
symbol : class Versioned
location: class wt.workflow.expr.WfExpression45853891
theVersioned = (Versioned)theQueryResult.nextElement();
^
5) WfExpression45853891.java:44: cannot find symbol
symbol : class EPMDocument
location: class wt.workflow.expr.WfExpression45853891
if (theVersioned instanceof EPMDocument) {
I need help here because and dont know all structure of Windchill API classes
Solved! Go to Solution.
Windchill needs FQN in expression robots for workflow templates. Use following to resolve your errors.
1) wt.fc.QueryResult
2) wt.maturity.MaturityHelper
3) wt.vc.Versioned
4) wt.vc.Versioned
5) wt.epm.EPMDocument
For Windchill JavaDoc, use following link on your 9.1 Windchill server (dont know for 10)
https://myserver.mycompany.com/Windchill/wt/clients/library/api/index.html
Windchill needs FQN in expression robots for workflow templates. Use following to resolve your errors.
1) wt.fc.QueryResult
2) wt.maturity.MaturityHelper
3) wt.vc.Versioned
4) wt.vc.Versioned
5) wt.epm.EPMDocument
For Windchill JavaDoc, use following link on your 9.1 Windchill server (dont know for 10)
https://myserver.mycompany.com/Windchill/wt/clients/library/api/index.html
Thank you Yogesh Bagul ! it's solved ..
But now i'm with dificult .. i need to know if the object in PBO is a DRW (Creo Drawing)
i have this:
if (theVersioned instanceof wt.epm.EPMDocument) {
System.out.println("IS A EPM DOCUMENT");
myDoc = (wt.epm.EPMDocument)theVersioned;
System.out.println("TYPE OF DOC: " + myDoc.getDocType());
}
But i get CADDRAWING , so i can compare this with
if(myDoc.getDocType().toString().equals("CADDRAWING") ){
..
}
Or exist other way to do this ?
Other question is how can i get the representations of CADDRAWING ?
Because i want the list of Representations, verify if exist any representation in PDF format and after that copy the file to a share in other server. .
Regards !
I guess your validation for CADDRAWING is good enough. To get representations from EPMDocument, look at wt.content.ApplicationData class. You can check and then stream representation file to file share.
In windchill 10 the java doc is available in <WT_HOME>\codebase\wt\clients\library\api\Index.html
I Already found that, but i'm having problems understanding the logic of programming here..
Yogesh, i'm using this way:
wt.fc.QueryResult theQueryResult;
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;
wt.content._ContentHolder cHolder;
try{
theQueryResult = wt.maturity.MaturityHelper.service.getPromotionTargets(pn);
wt.vc.Versioned theVersioned = null ;
wt.epm.EPMDocument myDoc;
if (theQueryResult != null){
while(theQueryResult.hasMoreElements()){
theVersioned = (wt.vc.Versioned)theQueryResult.nextElement();
if (theVersioned instanceof wt.epm.EPMDocument) {
System.out.println("IS A EPM DOCUMENT");
myDoc = (wt.epm.EPMDocument)theVersioned;
if(myDoc.getDocType().toString().equals("CADDRAWING")){
System.out.println("===== DRAWING ===== ");
System.out.println("NOW GET THE PDF DOCUMENT");
cHolder =(wt.content.ContentHolder)primaryBusinessObject;
System.out.println( "downloadPrimary: name = " + myDoc.getName() );
System.out.println( "downloadPrimary: number = " + myDoc.getNumber() );
System.out.println("theContent to appData");
wt.content.ApplicationData appData = wt.content.ApplicationData.newApplicationData((wt.content.ContentHolder)cHolder);
System.out.println( "primary file name = " + appData.getFileName());
}
}else{
System.out.println("THIS IS NOT A EPM");
}
}
}
result="Approved";
} catch (wt.maturity.MaturityException me){
errorMsg=me.getMessage();
result="Rejected";
}
And, what I get is : "primary file name = null"
what is wrong ?
Already Solved my Problem! Thanks to all of you!
This is my final code, it's lot of parts from another sites and forums but it worked for me..
that's it:
wt.fc.QueryResult theQueryResult;
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;
wt.content._ContentHolder cHolder;
try{
theQueryResult = wt.maturity.MaturityHelper.service.getPromotionTargets(pn);
wt.vc.Versioned theVersioned = null ;
wt.epm.EPMDocument myDoc;
if (theQueryResult != null){
int queCnt = 0;
while(theQueryResult.hasMoreElements()){
theVersioned = (wt.vc.Versioned)theQueryResult.nextElement();
if (theVersioned instanceof wt.epm.EPMDocument) {
System.out.println("IS A EPM DOCUMENT");
myDoc = (wt.epm.EPMDocument)theVersioned;
if(myDoc.getDocType().toString().equals("CADDRAWING")){
//GET THE PDF:
wt.lifecycle.LifeCycleManaged LMObject = (wt.lifecycle.LifeCycleManaged)myDoc;
String StStg = (String)LMObject.getLifeCycleState().toString();
if (StStg.compareTo("RELEASED") == 0) {
System.out.println( "\nEPMDoc - Number: " + myDoc.getNumber() + " - Name: " + myDoc.getName()+ " - CadName: " + myDoc.getCADName() );
System.out.println( "EPMDocument " + myDoc.getNumber() + " -Version: " + myDoc.getVersionIdentifier().getValue() + " - Iteration:"+myDoc.getIterationIdentifier().getValue());
System.out.println( "Life Cycle State: "+StStg);
try {
wt.representation.Representation defaultRep=wt.representation.RepresentationHelper.service.getDefaultRepresentation(myDoc);
wt.content.ContentHolder holder=wt.content.ContentHelper.service.getContents(defaultRep);
Vector contents=wt.content.ContentHelper.getContentListAll(holder);
wt.content.ApplicationData data=null;
for (int i=0;i<contents.size();i++)
{
if (contents.get(i) instanceof wt.content.ApplicationData)
{
data=(wt.content.ApplicationData)contents.get(i);
System.out.println("Avaliando o " + data.getFileName());
if (data!=null && data.getFileName().endsWith("pdf"))
{
System.out.println("Vou copiar este: " + data.getFileName() + " pois ele é PDF");
String path = "D:"+"\\pdf\\"+data.getFileName();
System.out.println("Vai copiar o : " + data.getFileName() + " para " + path);
wt.content.ContentServerHelper.service.writeContentStream(data, path);
System.out.println("Copiado : " + data.getFileName() + " para " + path);
break;
}
}
}
}catch(Exception exception){
errorMsg = "NOVO ERRO " + exception.getMessage();
}
queCnt++;
}
}
}else{
System.out.println("THIS IS NOT A EPM");
}
}
}
result="Approved";
} catch (wt.maturity.MaturityException me){
errorMsg=me.getMessage();
result="Rejected";
}
I didn't follow it that closely, but I have a couple thoughts.
Checking QueryResult == null doesn't hurt and is certainly cautious, I just can't think of any instance that will return a null QueryResult, just an empty one.
Windchill's Content stuff can be a little confusing at first. Your Representation IS the ContentHolder, so I would say defaultRep = (Representation)ContentHelper.service.getContents(defaultRep).
Most importantly, I wouldn't put this stuff directly in an expression robot/transition. Place it inside of another class and make a single call to that from your wf expression. Doing so will allow you to easily change the contents of the method if you ever need to. Off the top of my head, you may want to change logging statements and the File path, or you may come up with another solution for handling exceptions. Your wf expression can hold a try catch and route, but the other stuff should be external.
So Matthew, how can i create a package or classe mine ? like ext.pv.extraction ?
And how can i put the path to a line in my.xconf ?
Regards, and thank you for you help..
PV
Just create your class in some package under <wc.home>/codebase. I put my wf related stuff all under something like ext.wfexpr.*. The "wfexpr" is my indicator that the class is used in a workflow and I can't refactor signatures. That's my way of doing it anyways. As far as I know, xconfs are only for deploying properties, so you don't need to enter anything in an xconf. We're on 9.1, so maybe things have changed? BTW, the signatures for methods I use in wfexpressions usually look like "WTObject method(WTObject primaryBusinessObject, ObjectReference self)" That generally takes casting and any additional work outside of the expression and puts it in my class, giving the class a lot of flexibility. "self" will either be the executing activity or expression.