cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

check if EPMDoc has owner link to WTPart using API

SimonLucas
1-Newbie

check if EPMDoc has owner link to WTPart using API

Hi,

currently putting together a custom data utility, and as part of the this I need to check if an EPMDocument has 'owner' link to a WTPart, or alternatively find the EPMDocument which has 'owner' link .

I have tried the following:

  • to get all associated objects from the WTPart:
    • QueryResult cadDocs = WTPartHelper.service.getDescribedByDocuments(part)
  • to get active associated part from a EPMDoc:
    • AssociatedUtilities.getActiveAssociatedPart(cadDoc)
  • then tried to compare to see if the returned WTPart matched my starting WTPart.
    • if (AssociatedUtilities.getActiveAssociatedPart(cadDoc).equals(part)){......

However this does not always return the result I expect. If I have 2 EPMDocs associated, and 1 has 'owner' link then great - it works. If I then change that association of the first EPMDoc so that it has link 'content' rather than 'owner' and the second EPMDoc has link 'contributing content', then it return the second EPMDoc. If I then modify the association again to return the first EPMDoc to link type 'owner', it still returns the second EPMDoc which has link type 'contributing content'.

Hopefully that all makes sense?

If so, any ideas what I may be doing wrong?

the entire method I have been using to check for each associated EPMDOc is:

private EPMDocument getCadDoc(WTPart part) throws WTException {
EPMDocument cadDoc = null;

QueryResult cadDocs = WTPartHelper.service
.getDescribedByDocuments(part);

while (cadDocs.hasMoreElements()) {
WTObject obj = (WTObject) cadDocs.nextElement();
if (obj instanceof EPMDocument) {
cadDoc = (EPMDocument) obj;
if (AssociateUtilities.getActiveAssociatedPart(cadDoc).equals(
part)) {
break;
} else {
cadDoc = null;
}
}
cadDoc = null;
}
return cadDoc;

}

Using WC 10.1 M040.

Cheers




1 ACCEPTED SOLUTION

Accepted Solutions
LoriSood
22-Sapphire II
(To:SimonLucas)

Simon,

It doesn't look like the APIs used for association are officially supported for customization. Because of that, anything you try is not guaranteed to work and cannot be supported by PTC tech support. With that said, I found this incomplete code snippet that may be helpful. I've not tested it out so, again, no guarantees....

//Get WTPart instance associated with EPMDocument

WTPart part=...;

//Get EPMDocument instance associated with WTPart
EPMDocument epm=...;

AssociationType assoctype = null;
String association = null;
WTArrayList epmDocArray = new WTArrayList();
epmDocArray.add((EPMDocument) epm);
ResultGraph assocResultGraph = AutoAssociateHelper.getAssociatedResultGraph(epmDocArray, true);
Map datum = AutoAssociateHelper.getAssociatedLinkToObjectsMap(assocResultGraph, epmDocArray,false);
Iterator iterator = datum.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
Object obj = datum.get(key);
if (key instanceof BinaryLink && obj.equals(part)) {
BinaryLink bLink = (BinaryLink) key;
assoctype = AssociationType.getAssociationType(bLink);
if assoctype.equals(AssociationType.ACTIVE) {
<DO WHAT YOU NEED TO DO>
}
}
}
Good luck!

View solution in original post

1 REPLY 1
LoriSood
22-Sapphire II
(To:SimonLucas)

Simon,

It doesn't look like the APIs used for association are officially supported for customization. Because of that, anything you try is not guaranteed to work and cannot be supported by PTC tech support. With that said, I found this incomplete code snippet that may be helpful. I've not tested it out so, again, no guarantees....

//Get WTPart instance associated with EPMDocument

WTPart part=...;

//Get EPMDocument instance associated with WTPart
EPMDocument epm=...;

AssociationType assoctype = null;
String association = null;
WTArrayList epmDocArray = new WTArrayList();
epmDocArray.add((EPMDocument) epm);
ResultGraph assocResultGraph = AutoAssociateHelper.getAssociatedResultGraph(epmDocArray, true);
Map datum = AutoAssociateHelper.getAssociatedLinkToObjectsMap(assocResultGraph, epmDocArray,false);
Iterator iterator = datum.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
Object obj = datum.get(key);
if (key instanceof BinaryLink && obj.equals(part)) {
BinaryLink bLink = (BinaryLink) key;
assoctype = AssociationType.getAssociationType(bLink);
if assoctype.equals(AssociationType.ACTIVE) {
<DO WHAT YOU NEED TO DO>
}
}
}
Good luck!

Top Tags