have a look at this rule. It will change the display name of the occurrence in the assembly and the part.
AssemblyComponentDefinition oAsmCompDef = startDoc.ComponentDefinition;
// This will not get you the ipt file. Just the Occurrence
// wich is a refrence to the file!
var iptFile = oAsmCompDef.Occurrences.ItemByName[$"{iptName}:1"];
var occurrence = iptFile;
if (occurrence != null)
{
var newDisplayName = iptName + "__" + Guid.NewGuid().ToString().Split('-')[0];
Document refDoc = occurrence.ReferencedDocumentDescriptor.ReferencedDocument as Document;
refDoc.DisplayName = newDisplayName;
occurrence.Name = newDisplayName;
}
startDoc.Save2(true);
This will not change the file name. If that is what you want it will get more complicated. In that case, you should save the refDoc with the new name and replace the occurrence in the assembly with the newly created file. Have a look at the method
occurrence.Replace(string FileName, bool ReplaceAll)
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com