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

Dealing with Reference Designators (code snippet)

Aquamarine

Dealing with Reference Designators (code snippet)

Reading

private String getRefDesignator(WTPartUsageLink link)

{

...

QueryResult
result=OccurrenceHelper.service.getUsesOccurrences(link);

while (result.hasMoreElements())

{

Object o=result.nextElement();

if (o instanceof PartUsesOccurrence)

{

PartUsesOccurrence puo=(PartUsesOccurrence)o;

list.add(puo.getName());

}

}

...

Writing

private void createRefDesignators(WTPartUsageLink link, String
designators) throws WTException, WTPropertyVetoException

{

StringTokenizer st=new StringTokenizer(designators,",");

while (st.hasMoreTokens())

{

String refDesignator=st.nextToken();

PartUsesOccurrence
occurrence=PartUsesOccurrence.newPartUsesOccurrence(link);

occurrence.setName(refDesignator);


OccurrenceHelper.service.saveUsesOccurrenceAndData(occurrence,null);

}

}



Sorting

The ref designators require a custom sort so instead of "C1,C10,C11..."
we get "C1,C2,C3 ...".



public int compare(Object obj, Object obj1)

{

String s1=(String)obj;

String s2=(String)obj1;

try {



boolean b1=false;

boolean b2=false;

String s1a=";

String s2a=";

int l= (s1.length() > s2.length() ? s1.length() :
s2.length());

for(int i=0;i<l;i++)<br/>
{

if ((!b1)&&(Character.isDigit(s1.charAt(i))))

{

b1=true;

s1a=s1.substring(0,i);

}

if ((!b2)&&(Character.isDigit(s2.charAt(i))))

{

b2=true;

s2a=s2.substring(0,i);

}

if ((b1)&&(b2))

break;

}

if (!(s1a.equals(s2a)))

return s1a.compareTo(s2a);

Integer s1n=new Integer(s1.substring(s1a.length()));

Integer s2n=new Integer(s2.substring(s2a.length()));

return s1n.compareTo(s2n);

}

catch (Exception e)

{

return s1.compareTo(s2);

}

}

1 REPLY 1
Highlighted

Re: Dealing with Reference Designators (code snippet)

Hi,

you should rather have a look to the Windchill interface wt.part.ReferenceDesignatorSet.

For example: getting all sorted occurence names from the value of the ReferenceDesignator:

ReferenceDesignatorSet refDesSet = new DefaultReferenceDesignatorSet()refDesSet.initialize(refDesignator); final List<String> listOfReferenceDesignator = refDesSet.getExpandedReferenceDesignators();

It really makes sense to use the Windchill implementation because the format for the reference designators can be modifed with WTPreference (at least with WT11.0)

Announcements