如何通过 API 在 Windchill 中创建部件和文档之间的链接。我已经尝试了以下代码。
WTPartDescribeLink wl=WTPartDescribeLink.newWTPartDescribeLink(part1, Doc1);
PersistenceHelper.manager.save(wl);
但它不工作。:(:(
如何通过 API 在 Windchill 中创建部件和文档之间的链接。我已经尝试了以下代码。
WTPartDescribeLink wl=WTPartDescribeLink.newWTPartDescribeLink(part1, Doc1);
PersistenceHelper.manager.save(wl);
但它不工作。:(:(
在创建它们之间的链接之前,您无需检查文档和部件。(如果您这样做,则仅会为添加链接生成新的迭代 - 这在许多情况下可能是不可接受的)。
相反,尝试在服务器端插入创建的链接,如下所示:
PersistentObjectManager.getPom().insert(WTCollection, null, null);
或者
PersistenceServerHelper.manager.insert(WTCollection);
在客户端,使用 RemoteMethodServer 调用服务器端代码:
RemoteMethodServer.getDefault().invoke(...);
您需要检查WTDocument
,WTPart
对象并获取工作副本,然后您必须通过。
下面是创建一个工作代码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,"");
}
}