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.
Than you for your fast answer. I am on holidays that's why my late reply. Yes I will try this way.To bad that GetChildren does not read this way or at least an option with this command would be nice.
I am anyhow quite new in API.And have another question for you.When I have an Assy or Part open how can I save it as drawing via make drawing from assembly/part?
If you don't need to traverse the components in order, then you could use IAssemblyDoc::GetComponents. I have another macro in our Macro Library called "Run code on every part in assembly" that shows how do modify the custom properties of each part component using this method. (You can adjust it easily to work on both part and assembly components.) But if you need to traverse the components in the order presented in the feature tree, use the macro I mentioned in my last post.
As for your second question, you need to create the new drawing with ISldWorks::NewDocument and then save it via IModelDocExtension::SaveAs.
If you have new, unrelated questions, please post them in a new thread and we will help you there. Please also kindly mark my answer as correct if it solved your problem. Thanks!