如何通过API在windchill中创建部件之间的链接

时间:2013-06-15 07:17:44

标签: java ptc-windchill

如何通过API在windchill中创建零件和文档之间的链接。 我试过以下代码。

WTPartDescribeLink wl=WTPartDescribeLink.newWTPartDescribeLink(part1, Doc1);
PersistenceHelper.manager.save(wl);

但它不起作用。:( :(

2 个答案:

答案 0 :(得分:1)

在创建文档和部分之前,您无需签出文档和部分。 (如果你这样做,只会为添加链接生成新的迭代 - 在许多情况下这可能是不可接受的。)

相反,尝试在服务器端插入创建的链接,如下所示:

PersistentObjectManager.getPom().insert(WTCollection, null, null);

PersistenceServerHelper.manager.insert(WTCollection);

在客户端,使用RemoteMethodServer调用服务器端代码:

RemoteMethodServer.getDefault().invoke(...);

答案 1 :(得分:0)

您需要查看WTDocumentWTPart个对象,然后在必须通过之后获取工作副本。

以下是创建WTPartDescribeLink

的工作代码
import wt.doc.WTDocument;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.folder.Folder;
import wt.part.WTPart;
import wt.part.WTPartDescribeLink;
import wt.pds.StatementSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
import wt.vc.wip.CheckoutLink;
import wt.vc.wip.WorkInProgressHelper;

public class PartDesc {

    public static void main(String args[]) throws WTException, WTPropertyVetoException
    {
        WTPart part=null;
        WTDocument doc=null;
        String number="0000000025";
        String docnumber="0000000027";
        QuerySpec qspec=new QuerySpec(WTPart.class);
        qspec.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.LIKE,number),new int[]{0,1});
        QueryResult qr=PersistenceHelper.manager.find((StatementSpec)qspec);
        while(qr.hasMoreElements())
        {
            part=(WTPart) qr.nextElement();
        }
        System.out.println("Part found");

        QuerySpec qspec1=new QuerySpec(WTDocument.class);
        qspec1.appendWhere(new SearchCondition(WTDocument.class,WTDocument.NUMBER,SearchCondition.LIKE,docnumber),new int[]{0,1});
        QueryResult qr1=PersistenceHelper.manager.find((StatementSpec)qspec1);
        while(qr1.hasMoreElements())
        {
            doc=(WTDocument) qr1.nextElement();
        }
        System.out.println("Document found");

          //Checkout and getting Working copy of object
        Folder checkoutFolder = WorkInProgressHelper.service.getCheckoutFolder();
        CheckoutLink col = WorkInProgressHelper.service.checkout(doc,checkoutFolder,"");
        doc = (WTDocument)col.getWorkingCopy();


        Folder checkoutFolder1 = WorkInProgressHelper.service.getCheckoutFolder();
        CheckoutLink col1 = WorkInProgressHelper.service.checkout(part,checkoutFolder,"");
        part = (WTPart)col1.getWorkingCopy();

        //Creating Link between part and doc
        WTPartDescribeLink link=WTPartDescribeLink.newWTPartDescribeLink(part, doc);
        PersistenceHelper.manager.save(link);
        System.out.println("link created ");

        doc = (WTDocument)WorkInProgressHelper.service.checkin(doc,"");
        part = (WTPart)WorkInProgressHelper.service.checkin(part,"");
    }

}