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 check if downstream view of the WT part exists?

Dina_S
5-Regular Member

How to check if downstream view of the WT part exists?

Hi All,

I want to create a "Manufacturing" view for the part included in the Change task, but I want to do it only if it doesn't exist.

Now I use this code without checking. And I want to add something like " if Manufacturing view for obj ==null then" 

 

wt.fc.QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore((wt.change2.ChangeOrderIfc) primaryBusinessObject);

while(qr.hasMoreElements())

{

  wt.fc.WTObject  obj =(wt.fc.WTObject) qr.nextElement();

   if(obj instanceof wt.part.WTPart)

      {

       wt.part.WTPart prt = (wt.part.WTPart) obj;

       wt.part.WTPart ManufPart = (wt.part.WTPart)

       ManufPart = (wt.vc.views.ViewManageable)obj, "Manufacturing")

       wt.vc.views.ViewHelper.service.newBranchForView((wt.vc.views.ViewManageable)obj, "Manufacturing");

 

      ManufPart = (wt.part.WTPart)wt.fc.PersistenceHelper.manager.store(ManufPart);

       }

  }

1 ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
21-Topaz II
(To:Dina_S)

Hi @Dina_S 

It is easy.

Filter the results based on your view

 

QueryResult qrUstr = PersistenceHelper.manager.navigate(part,EquivalenceLink.DOWNSTREAM_ROLE,wt.associativity.EquivalenceLink.class, true);

		WTPart dwWTP = null;
		while (qrUstr.hasMoreElements())
		{
			dwWTP = (WTPart) qrUstr.nextElement();
			if (dwWTP.getViewName().equalsIgnoreCase("manufacturing"))
			{
				System.out.print(dwWTP.getNumber()); // use it as you need. 
			}
		}

 

PetrH

 

View solution in original post

5 REPLIES 5
Dina_S
5-Regular Member
(To:Dina_S)

I have found this

https://www.ptc.com/en/support/article/cs47538?language=en&posno=4&q=ViewHelper.service.newBranchForView&source=search

 

wt.fc.PersistenceHelper.manager.navigate(reference.getObject(),wt.associativity.EquivalenceLink.DOWNSTREAM_ROLE, wt.associativity.EquivalenceLink.class);

 

I need help finding out how to use this. I need only the "Manufacturing view" part, not the "Service view" one. And I don't know how to check the assigned view for the object. I would really appreciate it if someone could help me.

 

So I tried this and it doesn't work like I want:

 

wt.fc.QueryResult AllDownPart = wt.fc.PersistenceHelper.manager.navigate(obj,

wt.associativity.EquivalenceLink.DOWNSTREAM_ROLE, wt.associativity.EquivalenceLink.class,true);

 

if(AllDownPart != null){

HelesicPetr
21-Topaz II
(To:Dina_S)

Hi @Dina_S 

It is easy.

Filter the results based on your view

 

QueryResult qrUstr = PersistenceHelper.manager.navigate(part,EquivalenceLink.DOWNSTREAM_ROLE,wt.associativity.EquivalenceLink.class, true);

		WTPart dwWTP = null;
		while (qrUstr.hasMoreElements())
		{
			dwWTP = (WTPart) qrUstr.nextElement();
			if (dwWTP.getViewName().equalsIgnoreCase("manufacturing"))
			{
				System.out.print(dwWTP.getNumber()); // use it as you need. 
			}
		}

 

PetrH

 

Dina_S
5-Regular Member
(To:HelesicPetr)

Thank you for the clue.

Dina_S
5-Regular Member
(To:HelesicPetr)

It is also important not to forget to create an Equivalence link.
The object is taken from Change Notice.
Below full working code without checking procedures:

 

wt.fc.QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore((wt.change2.ChangeOrderIfc) primaryBusinessObject);
	//qr changeable before= vector all Deign part for Manufacturing
while(qr.hasMoreElements())
{
   wt.fc.WTObject  obj =(wt.fc.WTObject) qr.nextElement();
   //obj =one design part from implementation tasks
   if(obj instanceof wt.part.WTPart)
	{
	   wt.part.WTPart prt = (wt.part.WTPart) obj;
	   wt.fc.QueryResult AllDown = wt.fc.PersistenceHelper.manager.navigate(prt, wt.associativity.EquivalenceLink.DOWNSTREAM_ROLE, wt.associativity.EquivalenceLink.class,true);
	//all downstream parts

	   wt.part.WTPart ManuPart= null;
	// empty part for Manufacturing

	  wt.part.WTPart dwWTP = null;
   // empty part for checking if Manufacturing

	 while (AllDown.hasMoreElements())
		{
			dwWTP = (wt.part.WTPart) AllDown.nextElement();
			if (dwWTP.getViewName().equalsIgnoreCase("Manufacturing"))
			{
				System.out.print(dwWTP.getNumber()); 
				ManuPart = dwWTP;
			}
	    }
	if(ManuPart==null)
	   {
	  ManuPart = (wt.part.WTPart)wt.vc.views.ViewHelper.service.newBranchForView((wt.vc.views.ViewManageable)prt, "Manufacturing");
	  ManuPart = (wt.part.WTPart)wt.fc.PersistenceHelper.manager.store(ManuPart);
	  //create equivelencelink between these 2 parts
		wt.associativity.EquivalenceLink link1 = wt.associativity.EquivalenceLink.newEquivalenceLink(prt,ManuPart);
		link1.setIsConsumable(true);
		link1.setUpstreamContextRef(prt.getView());
		link1.setDownstreamContextRef(ManuPart.getView());
		link1 = (wt.associativity.EquivalenceLink) wt.fc.PersistenceHelper.manager.save(link1);
		}
 
	}
}

 

Dina_S
5-Regular Member
(To:Dina_S)

 I also found that it is important not to forget to create EquivalenceLink :).

 

Top Tags