Quantcast
Channel: PTC Community: Message List - Windchill
Viewing all articles
Browse latest Browse all 8876

Re: Download representation and annotation of a WTDocument in Windchill using java or webject?

$
0
0

I can place code to download representation for epmdoc. I am not sure if it's the same for wtdoc


package ext;

import java.io.*;
import java.util.*;
import java.rmi.RemoteException;

import wt.util.*;
import wt.content.*;
import wt.epm.*;
import wt.fc.*;
import wt.query.*;
import wt.content.*;
import wt.representation.*;

import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.httpgw.GatewayAuthenticator;

public class dlRep_main
implements RemoteAccess, Serializable
{
private static void extractContent(EPMDocument EPMDoc, String dlLoc, String conType)
{
  try {
   Representation defaultRep=RepresentationHelper.service.getDefaultRepresentation(EPMDoc);

   if(defaultRep != null)
   {
    ContentHolder holder=ContentHelper.service.getContents(defaultRep);
    Vector contents=ContentHelper.getContentListAll(holder);
    ApplicationData data=null;

    for (int i=0;i<contents.size();i++)
    {
     if (contents.get(i) instanceof ApplicationData)
     {
      data=(ApplicationData)contents.get(i);

      if (data!=null && data.getFileName().endsWith(conType))
      {
       String path = dlLoc+"\\"+data.getFileName();
       ContentServerHelper.service.writeContentStream(data, path);
       System.out.println("Download Step Executed.\n");
       break;
      }
     }
    }
   }
  }
  catch(Exception exception)
  {
   exception.printStackTrace();
  }
}

public static void getEPMDoc(String dlLoc, String drwNo, String conType)
{
  try
  {
   QuerySpec qs = new QuerySpec(EPMDocument.class);
   qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NUMBER,SearchCondition.LIKE, drwNo));
   qs.appendAnd();
   qs.appendWhere(new SearchCondition(EPMDocument.class, "iterationInfo.latest", "TRUE"));
   System.out.println("Now Querying for Doc Using:\n " + qs.toString());

   final QueryResult qr = PersistenceHelper.manager.find(qs);

   while (qr.hasMoreElements()) {
    EPMDocument epmm = (EPMDocument)qr.nextElement();

    if (epmm.getNumber().endsWith(".DRW")) {
     System.out.println( "\nEPMDoc - Number: " + epmm.getNumber() + " - Name: " + epmm.getName()+ " - CadName: " + epmm.getCADName() );
     System.out.println( "Version: " + epmm.getVersionIdentifier().getValue() + " - Iteration:"+epmm.getIterationIdentifier().getValue()+" - Life Cycle State: "+epmm.getLifeCycleState().toString());
     extractContent(epmm, dlLoc, conType);
    }
   }
  }
  catch(Exception exception)
  {
   exception.printStackTrace();
  }
}

public static void main(String args[])
{
  if(args.length < 2)
  {
   System.out.println("Usage: windchill dlRep_Main <path-where-file-should be saved> <number search string> <content type>");
   System.exit(0);
  } else
  {
   try
   {
    RemoteMethodServer rms = RemoteMethodServer.getDefault();
    GatewayAuthenticator auth = new GatewayAuthenticator();
    auth.setRemoteUser("wcadmin");
    rms.setAuthenticator(auth);

    String dlLoc = args[0];
    String drwNo = args[1];
    String conType = args[2];

    Class aclass[] = new Class[3];
    aclass[0] = java.lang.String.class;
    aclass[1] = java.lang.String.class;
    aclass[2] = java.lang.String.class;

    Object aobj[] = { dlLoc, drwNo, conType };

    rms.invoke("getEPMDoc", "ext.dlRep_main", null, aclass, aobj);
    System.exit(0);
   }
   catch(Exception exception)
   {
    exception.printStackTrace();
   }
  }
}
}


Viewing all articles
Browse latest Browse all 8876

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>