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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

How to change the Type of a Part

iwebb
2-Guest

How to change the Type of a Part

We have several Soft Types of WTPart,two of which are called 'Furnished' and 'Drawn'. They have exactly the same attribute definitions.


Users have created a few 'Furnished' type Parts that should have been type 'Drawn' (and vice versa).


How can I change the Type of selected parts?

4 REPLIES 4

Ian,

We have the same problem here. So much so that in order to preserve my
santity I created a command line tool to change them.

What you need to do is edit two columns in the dB for each Part iteration
you are changing.

Typed objects have their ?type? determined by two columns from the
appropriate table WTTYPEDEFINITION table
ida2a2 and BRANCHIDITERATIONINFO

select ida2a2, BRANCHIDITERATIONINFO from WTTYPEDEFINITION where
name='<the target=" type=" name=">';

update the WTParts' setting IDA2TYPEDEFINITIONREFERENCE from WTPart
table = ida2a2 from WTTYPEDEFINITION

update the WTParts' setting BRANCHIDA2TYPEDEFINITIONREFE from WTPart =
BRANCHIDITERATIONINFO from WTTYPEDEFINITION

that's really all you need to know.

FYI, My tool keys of the master.The second image below outputs the sql
command used to do the update. Note that it does key of the master. This
insures that all iterations get re-typed and requires the least amount to
dB connections.

If the attribute are the same you need not worry about them. They will be
fine.


works like this


the results







David Graham
Windchill Developer/Administrator
CAx Administrator


Emhart Glass Manufacturing Inc.
Emhart Glass Research Center
123 Great Pond Drive | Windsor, CT 06095 | USA
Telephone +1 (203) 376-3144 | Telefax +1 (860) 298 7397
Mobile +1 (203) 376-3144 |

David,


You obvioulsy know your way around the DB. I would also like to be able to reassign soft types, but this level of database tinkering scares me too much. I presume there is no supported method of doing this, hence your creative solution.


Darren

ssenthil
1-Newbie
(To:iwebb)

On R9.1, We developed a handy utility for changing the type and the snippet
of the code is



import com.ptc.core.foundation.type.server.impl.TypeHelper;

import com.ptc.core.meta.common.TypeIdentifier;



public static WTObject doRetype(WTObject wtobject, String otype) throws
Exception {

TypeIdentifier typeidentifier =
TypeHelper.getTypeIdentifier(otype);

String oldType =
TypeHelper.getLocalizedTypeString((WTObject) wtobject, java.util.Locale.US);

String newType =
TypeHelper.getLocalizedTypeString(typeidentifier, java.util.Locale.US);

wtobject = (WTObject) TypeHelper.setType(wtobject,
typeidentifier);

wtobject = (WTObject)
wt.fc.PersistenceHelper.manager.save(wtobject);

return wtobject;

}



Please give it a try and let us know your feedback.



Thank you and have a great time.

Best Regards

Swamy Senthil

Principal Solutions Architect, Swasen Inc

swamy.senthil@swasen.com(Email); 909 800 8423(M); 973 324 2729(W); 866
908 6561(F);




Darren, hi

There is an OOTB utility that is used to generate the sql command but all
it does is generate the sql command on a per iteration and at the end of
the day all it does is edit the same two columns that I mentioned in my
mail.

As Swamy pointed out there is an API to do this, TypeHelper,
setType(Persistable thePersistable, TypeIdentifier theTypeIdentifier) that
can set an objects type. There are no Javadocs on the class however
decompling the class reveals that it actually does following:

((Typed)thePersistable).setTypeDefinitionReference(TypedUtility.getTypeDefinitionReference(
theTypeIdentifier.getTypename()));

At the dB level the bottom line is the two columns I mentioned are the
ones that determine the objects type.

My guess is thePersistable is an iteration not the master so to use the
API safely you would need to get all iterations of the master, set each
iterations type, add each iteration to a WTCollection and then save the
WTCollection. This would ensure that all or none of the iteration have
their types changed. This is precisely why I key of the master in my
code.

If you need help with this let me know.

David Graham
Windchill Developer/Administrator
CAx Administrator


Emhart Glass Manufacturing Inc.
Emhart Glass Research Center
123 Great Pond Drive | Windsor, CT 06095 | USA
Telephone +1 (203) 376-3144 | Telefax +1 (860) 298 7397
Mobile +1 (203) 376-3144 |
Top Tags