Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi,
I already found this article https://community.ptc.com/t5/Windchill/How-to-copy-Representation-of-CAD-Document-to-WTPart/m-p/305726 and I used a few parts of it, but I can't get it to work.
So we want to copy a representation from an EPMDocument to a WTPart and this by code.
String epmdocnumber = "11107160";
String part = "11107160-B";
// OID zoeken van epmdocnumber
LatestConfigSpec lcs = null;
QuerySpec qs = new QuerySpec(EPMDocument.class);
SearchCondition scNumber = new SearchCondition(EPMDocument.class, "master>number", SearchCondition.EQUAL, epmdocnumber);
qs.appendWhere(scNumber, new int[]{0});
lcs = new LatestConfigSpec();
lcs.appendSearchCriteria(qs);
QueryResult qr = PersistenceHelper.manager.find(qs);
if (lcs != null) {
qr = lcs.process(qr);
}
EPMDocument epmDoc = null;
if (qr.size() > 0) {
epmDoc = (EPMDocument)qr.nextElement();
}
// OID zoeken van wtpart
lcs = null;
qs = new QuerySpec(WTPart.class);
scNumber = new SearchCondition(WTPart.class, "master>number", SearchCondition.EQUAL, part);
qs.appendWhere(scNumber, new int[]{0});
lcs = new LatestConfigSpec();
lcs.appendSearchCriteria(qs);
qr = PersistenceHelper.manager.find(qs);
if (lcs != null) {
qr = lcs.process(qr);
}
WTPart wtpart = null;
if (qr.size() > 0) {
wtpart = (WTPart)qr.nextElement();
}
%><%=epmDoc%><br><%
%><%=wtpart%><br><%
Representation rep_pub = PublishUtils.getRepresentation(epmDoc);
%><%=rep_pub%><br><%
RepresentationHelper.service.storeRepresentation(rep_pub, wtpart, "test", "test", rep_pub.getRepresentationType());
PersistenceHelper.manager.refresh(wtpart);
I created/edited the above code and it doesn't work somehow.
I get this error:
"The domain of persistent objects cannot be changed using "DomainAdministered.setAdminDomain"."
I don't know how to solve this. Can somebody help me with this?
Thanks in advance