Changing the name of the ipt file in the assembly with the Inventor api

Changing the name of the ipt file in the assembly with the Inventor api

hayattangercekler2
Advocate Advocate
700 Views
4 Replies
Message 1 of 5

Changing the name of the ipt file in the assembly with the Inventor api

hayattangercekler2
Advocate
Advocate

I use the commands to change the name of the ipt file in the assembly with the Inventor api and change it. The ipt file name that I see while the assembly is open has changed. Afterwards, when I open the ipt file in the assembly file, its name is still the same as in its initial state. How can I make this name change?

 

hayattangercekler2_0-1671425344446.png   hayattangercekler2_1-1671425393911.png

 

0 Likes
Accepted solutions (1)
701 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

I'm not sure if I understand you correctly. (I don't know what "the commands" are and also it's unclear which file you mean with "the ipt file".) But you can change the display name of occurrences in an assembly to their default name by setting the name to an empty string. This iLogic rule will set the first occurrence in the assembly to its default value.

Dim doc As AssemblyDocument = ThisDoc.Document
Dim occ = doc.ComponentDefinition.Occurrences.Item(1)
occ.Name = String.Empty

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

hayattangercekler2
Advocate
Advocate

my code ;

   AssemblyComponentDefinition oAsmCompDef = startDoc.ComponentDefinition;


            var iptFile = oAsmCompDef.Occurrences.ItemByName[$"{iptName}:1"];
            if (iptFile != null)
            {
                iptFile.Name =  iptName + "__" + Guid.NewGuid().ToString().Split("-")[0];
            }
            startDoc.Save2(true);

 

I also implemented the same code in this way. Yes, the name of the ipt in the assembly file changes, but when I open the ipt, it remains the same as the old file name. I create a few of these files and put them in a different assembly file. They all stay the same length, not different lengths there. At this length, the last time I changed the length belongs to the assembly.

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 5

hayattangercekler2
Advocate
Advocate

Thank you. It's working.

0 Likes