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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Re: How to retrieve Quantity attribute for WTPart Structure?

JM_10276355
10-Marble

Re: How to retrieve Quantity attribute for WTPart Structure?

As per this thread - same issue

 

Hi rkumar,

 

I too have the similar kind of need, where I need to fetch all the bom structure and get the custom attributes values that or on Usage link.

 

Is there any way if i can get both the Link and wtpart or wtpart master? Let me know 

 

Thanks

ACCEPTED SOLUTION

Accepted Solutions

Hi @JM_10276355 

 

the ibah is object that represents WTPart or EPMDocument, or other types. 

So put there the object for example WTPart.


IBAHolder ibaHolder = IBAValueHelper.service.refreshAttributeContainer((IBAHolder) ibah, null, null, null);
DefaultAttributeContainer dac = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();

StringBuilder values = new StringBuilder(); // it will be filled with values

if (dac != null)
{
AbstractValueView[] abstrAttrib = dac.getAttributeValues();
// search for atribute name
for (int i = 0; i < abstrAttrib .length; i++)
{
AttributeDefDefaultView attrDef = abstrAttrib [i].getDefinition();
String atrName = attrDef.getName();
if (atrName.equals(ibaParam)) // ibaParam is an internal name of attribute
{
values.append(retValue.length() == 0 ? "" : "@");
values.append(getValueView(avv[i]));// if attribute has more values
}
}
}

 

PetrH

View solution in original post

3 REPLIES 3

Hi @JM_10276355 

you can use something linke following code. 

It gives you UsageLink and  child WTPart

 

WTPart wtp = (WTPart) wtpObject; // source Parent from another search function
ConfigSpec localConfigSpec = ConfigHelper.service.getConfigSpecFor(wtp);
QueryResult qr = WTPartHelper.service.getUsesWTParts(wtp, localConfigSpec);
if (qr.size() != 0)
{
while (qr.hasMoreElements())
{
Persistable persistables[] = (Persistable[]) qr.nextElement();
WTPart subpart = null;
if (persistables[1] instanceof WTPart) // second place in array is WTPart
{
subpart = (WTPart) persistables[1];
}
WTPartUsageLink wtpLink = null;
if (persistables[0] instanceof WTPartUsageLink)
{
wtpLink = (WTPartUsageLink) persistables[0]; // first place in array is WTPartUsageLink
}
}

 

IBA attributes could be get by 

IBAHolder ibaHolder = IBAValueHelper.service.refreshAttributeContainer((IBAHolder) ibah, null, null, null);
DefaultAttributeContainer dac = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();

DefaultAttributeContainer  dac contains all IBA attributes of the object so you have to search which IBA attribute name you really want. 

 

Hope this can help

 

PetrH

Hi @HelesicPetr 

 

That was a quick input, thanks !! I also wanted to know how can we get the IBA from the WTPart we fetched from the above code, I mean to say where to pass the WTPart object so that IBA is defined on the WTPart which is to be retrieved.

 

 

Thanks

Hi @JM_10276355 

 

the ibah is object that represents WTPart or EPMDocument, or other types. 

So put there the object for example WTPart.


IBAHolder ibaHolder = IBAValueHelper.service.refreshAttributeContainer((IBAHolder) ibah, null, null, null);
DefaultAttributeContainer dac = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();

StringBuilder values = new StringBuilder(); // it will be filled with values

if (dac != null)
{
AbstractValueView[] abstrAttrib = dac.getAttributeValues();
// search for atribute name
for (int i = 0; i < abstrAttrib .length; i++)
{
AttributeDefDefaultView attrDef = abstrAttrib [i].getDefinition();
String atrName = attrDef.getName();
if (atrName.equals(ibaParam)) // ibaParam is an internal name of attribute
{
values.append(retValue.length() == 0 ? "" : "@");
values.append(getValueView(avv[i]));// if attribute has more values
}
}
}

 

PetrH

Announcements

Top Tags