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.

How to get the WTPart from its related EPMDocument?

SaravananSubram
1-Newbie

How to get the WTPart from its related EPMDocument?

Hi All,


I can get all epmdocument which are linked with WTPart by following code:


Here "part" is variable.


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


But, Is there any way to get WTPart from its EPMDocument?. If possible, please provide sample code.


Regards


Saravanan

11 REPLIES 11

You could try:



wt.fc.QueryResult queryResult =
wt.part.WTPartHelper.service.getDescribesWTParts((wt.epm.EPMDocument)pri
maryBusinessObject);



Thanks,

Dax


You can also try below methods from *
com.ptc.windchill.cadx.common.util.AssociateUtilities* class

To get Active (owner link) part:
*WTPart activePart = AssociateUtilities.getActiveAssociatedPart(epmDoc);*

or to get all associated objects including WTParts,
*Object[] allAssocObjs = AssociateUtilities.getAssociatedObjects(epmDoc);*


Regards,
Avinash <">http://avinashkor.cabanova.com>

<">http://www.linkedin.com/in/avinashkor>



On Mon, Sep 19, 2011 at 8:36 PM, Williams, Dax (GE Healthcare) <
-> wrote:

> You could try:****
>
> ** **
>
>
> wt.fc.QueryResult queryResult = wt.part.WTPartHelper.service.getDescribesWTParts((wt.epm.EPMDocument)primaryBusinessObject);
> ****
>
> ** **
>
> Thanks,****
>
> Dax****
>
> ** **
>
> *From:* Saravanan Subramanian [

Dear Avinash,


Excellent!!!. Your code is working fine.


Thanks


Saravanan

Thanks a lot Avinash. It’s working cool.

Yours Sincerely,
Samuel Shanthana Raja
Consultant-PLM/PDM Practice |BWIR|Chennai|India.
0091 44 43909300 Extn: 311| Email: samuelshanthanaraja.ramdoss@bwir.com<">mailto:samuelshanthanaraja.ramdoss@bwir.com>

Pleasure in the job puts perfection in the work.- Aristotle


I have used:

import com.ptc.windchill.cadx.common.util.AssociateUtilities;
import com.ptc.windchill.cadx.common.util.ObjectDependencyUtility;


WTPart wtpList[] = ObjectDependencyUtility.getAssociated((EPMDocument)epmdoc);


if( wtpList != null ) {
System.out.println( "\tAssociated EPMDoc length (wtpList.length): " + wtpList.length+"\n");


for (int y = 0; y < wtpList.length; y++ ) {
WTPart wtpAssoc = null;
wtpAssoc = (WTPart)wtpList[y];
System.out.println( "Found Existing WTPart Number Association to ("+y+"):");
System.out.println( "WTPart Number: "+ wtpAssoc.getNumber() + ", WTPart Name: " + wtpAssoc.getName());
System.out.println( "WTPart Version: " + wtpAssoc.getVersionIdentifier().getValue() + "."+wtpAssoc.getIterationIdentifier().getValue()+"\n");
}
}

that way yo get active & passive wtpart associations.

L Jett

cswaner
5-Regular Member
(To:SaravananSubram)

All,


I know this is an old thread, however, I am trying to expand on it a little. I am specifically trying to get the associated WTPart(s) from the EPMDoc (primaryBusinessObject) and then set the LC state of the WTParts accordingly.


This is what I tried:


//get the object that is described by the epm document


java.lang.Object wtpart = com.ptc.windchill.cadx.common.util.AssociateUtilities.getAssociatedObjects((wt.epm.EPMDocument)primaryBusinessObject);while (wtpart.hasMoreElements()){



//set the state of the described object to RELEASED


wt.lifecycle.LifeCycleHelper.service.setLifeCycleState(((wt.lifecycle.LifeCycleManaged)wtpart.nextElement()),wt.lifecycle.State.toState("RELEASED"),true);}


When I Check Syntax I get errors:


D:\ptc\Windchill_10.1\Windchill\temp\WfExpression2985721454.java:30: cannot find symbol

symbol : method hasMoreElements()

location: class java.lang.Objectwhile (wtpart.hasMoreElements()){ ^D:\ptc\Windchill_10.1\Windchill\temp\WfExpression2985721454.java:33: cannot find symbol

symbol : method nextElement()location: class java.lang.Objectwt.lifecycle.LifeCycleHelper.service.setLifeCycleState(((wt.lifecycle.LifeCycleManaged)wtpart.nextElement()),wt.lifecycle.State.toState("RELEASED"),true); ^D:\ptc\Windchill_10.1\Windchill\codebase\wt\lifecycle\State.class: warning: Cannot find annotation method 'supportedAPI()' in type 'com.ptc.windchill.annotations.metadata.GenAsEnumeratedType'


Thanks in advance for any advise.


PLM Solution Architect


java.lang.Object is the highest level object in the java programming
language. You need to cast it to whatever the javadoc states. Likely some
type of map object is acceptable, but it likely returns WTHashMap or some
derived class of a mappable list/collection.

On Mon, Mar 30, 2015 at 9:31 AM, Cameron Swaner <->
wrote:

> All,
>
> I know this is an old thread, however, I am trying to expand on it a
> little. I am specifically trying to get the associated WTPart(s) from the
> EPMDoc (primaryBusinessObject) and then set the LC state of the WTParts
> accordingly.
>
> This is what I tried:
>
> //get the object that is described by the epm document
>
> java.lang.Object wtpart =
> com.ptc.windchill.cadx.common.util.AssociateUtilities.getAssociatedObjects((wt.epm.EPMDocument)primaryBusinessObject); while
> (wtpart.hasMoreElements()){
>
>
> //set the state of the described object to RELEASED
>
>
> wt.lifecycle.LifeCycleHelper.service.setLifeCycleState(((wt.lifecycle.LifeCycleManaged)wtpart.nextElement()),wt.lifecycle.State.toState("RELEASED"),true);}
> When I Check Syntax I get errors:
> D:\ptc\Windchill_10.1\Windchill\temp\WfExpression2985721454.java:30:
> cannot find symbol
> symbol : method hasMoreElements()
> location: class java.lang.Objectwhile (wtpart.hasMoreElements()){
> ^D:\ptc\Windchill_10.1\Windchill\temp\WfExpression2985721454.java:33:
> cannot find symbol
> symbol : method nextElement()location: class
> java.lang.Objectwt.lifecycle.LifeCycleHelper.service.setLifeCycleState(((wt.lifecycle.LifeCycleManaged)wtpart.nextElement()),wt.lifecycle.State.toState("RELEASED"),true);
>
>
> ^D:\ptc\Windchill_10.1\Windchill\codebase\wt\lifecycle\State.class:
> warning: Cannot find annotation method 'supportedAPI()' in type
> 'com.ptc.windchill.annotations.metadata.GenAsEnumeratedType'
> Thanks in advance for any advise.
> *Cameron Swaner*
> PLM Solution Architect
> PTC Solutions Expert
>
cswaner
5-Regular Member
(To:SaravananSubram)

David, Thank you for your response. Can you provide a specific example or code that will help me fix this?Thanks,Cam

Sent from Outlook




On Mon, Mar 30, 2015 at 8:15 AM -0700, "DeMay, David" <ddemay@npss-inc.com> wrote:
java.lang.Object is the highest level object in the java programming
language. You need to cast it to whatever the javadoc states. Likely some
type of map object is acceptable, but it likely returns WTHashMap or some
derived class of a mappable list/collection.

On Mon, Mar 30, 2015 at 9:31 AM, Cameron Swaner <->
wrote:

> All,
>
> I know this is an old thread, however, I am trying to expand on it a
> little. I am specifically trying to get the associated WTPart(s) from the
> EPMDoc (primaryBusinessObject) and then set the LC state of the WTParts
> accordingly.
>
> This is what I tried:
>
> //get the object that is described by the epm document
>
> java.lang.Object wtpart =
> com.ptc.windchill.cadx.common.util.AssociateUtilities.getAssociatedObjects((wt.epm.EPMDocument)primaryBusinessObject); while
> (wtpart.hasMoreElements()){
>
>
> //set the state of the described object to RELEASED
>
>
> wt.lifecycle.LifeCycleHelper.service.setLifeCycleState(((wt.lifecycle.LifeCycleManaged)wtpart.nextElement()),wt.lifecycle.State.toState("RELEASED"),true);}
> When I Check Syntax I get errors:
> D:\ptc\Windchill_10.1\Windchill\temp\WfExpression2985721454.java:30:
> cannot find symbol
> symbol : method hasMoreElements()
> location: class java.lang.Objectwhile (wtpart.hasMoreElements()){
> ^D:\ptc\Windchill_10.1\Windchill\temp\WfExpression2985721454.java:33:
> cannot find symbol
> symbol : method nextElement()location: class
> java.lang.Objectwt.lifecycle.LifeCycleHelper.service.setLifeCycleState(((wt.lifecycle.LifeCycleManaged)wtpart.nextElement()),wt.lifecycle.State.toState("RELEASED"),true);
>
>
> ^D:\ptc\Windchill_10.1\Windchill\codebase\wt\lifecycle\State.class:
> warning: Cannot find annotation method 'supportedAPI()' in type
> 'com.ptc.windchill.annotations.metadata.GenAsEnumeratedType'
> Thanks in advance for any advise.
> *Cameron Swaner*
> PLM Solution Architect
> PTC Solutions Expert
>

If you have epm document then you can get the WTPart related to document below API



QueryResult qr= PersistenceHelper.manager.navigate(epmdocument, EPMBuildRule.BUILD_TARGET_ROLE, EPMBuildRule.class,true);



Iterate the QureyResult to get the WTPart

Is there a way by which we can get the related ID, just like this 

   "ID": "OR:wt.part.WTPartDescribeLink:2221723", - when we do a get call for DescribedBy on part

There are numerous ways to get the desired results. When selecting the Windchill APIs, please make sure that the APIs need not be revisited when upgrading to the next build and the method is generalized in a way that it can be reused. Alos add exceptions handled and logger statement to verify the collected objects. Following is another elegant method:



//Initiate the collection result

Collection result = null;

WTCollection seeds = new WTArrayList();

seeds.add(epmDocument);

//Set the config spec

EPMDocConfigSpec configSpec = new EPMDocConfigSpec();

configSpec.setLatestActive();

//Set the navigation criteria

NavigationCriteria nc = NavigationCriteria.newNavigationCriteria();

List<epmdocconfigspec> configpecs = new ArrayList<epmdocconfigspec>();

configpecs.add(configSpec);

nc.setConfigSpecs(configpecs);

CollectedResult ccr = null;

ccr = CadCollector.newInstance(seeds, nc).associatedParts(GatherAssociatedParts.ALL).collect();

result = ccr.getCollectedObjects();

Iterator items = result.iterator();

while (items.hasNext()) {

Object item = items.next();

//Check for WTPart

if (item instanceof WTPart) {

WTPart collectedPart = (WTPart) item;

//Check if the WTPart needs to be set to the new state



//Set the State

}

}



Hope this helps



Thanks and Best Regards



Swamy Senthil
Principal Solutions Architect, Swasen Inc
swamy.senthil@swasen.com(Email) <">mailto:swamy.senthil@swasen.com(Email)> ; 909 800 8423 <tel:909%20800%208423> (M); 866 908 6561 <tel:866%20908%206561> (F);





_____

Top Tags