Hi ,
Is there a macro that runs through the assembly tree and adds a custom property (like PartNo) to the parts and assembly in a way that a subassembly parts ( or subassembly ) take prefix number of a subassembly that they belong to (upper assembly)? Is that possible?
And how can you follow the feature tree with the numbers.I tried to repair a Traverse Assembly at Component Level Example macro and works fine with top level components but not the parts in subassembly (except the numbers do not follow the assembly tree).
What I would like IS :
Top Assy->01-2016
Sub Assy->01-2016-001
SubAssyPart->01-2016-001-001
SubAssyPart->01-2016-001-002
SubAssyAssy->01-2016-001-003
SubAssyAssyPart->01-2016-001-003-001
Part->01-2016-002
Part->01-2016-003
Thank you in advance fo any answer.
If you want to traverse a feature tree in order, check out the macro called "Traverse features in order using recursion" in our Macro Library. (Requires a free membership.) Use IComponent2::GetModelDoc2 to get the underling IModelDoc2 object for a component so that you can access its custom properties. Then use ICustomPropertyManager to add custom properties. See the API Help for examples.
As for getting the prefix, you'll need to extract it using string manipulation from IComponent2::Name2. You might be able to split the component name using Split() with a hyphen for the delimiter, then append the first two elements of the returned array together using a hyphen to get the actual value you want.
Keith
SolidWorks API Training and Services