Automatic setting filename to partnumber

Automatic setting filename to partnumber

Anonymous
Not applicable
6,562 Views
12 Replies
Message 1 of 13

Automatic setting filename to partnumber

Anonymous
Not applicable

At work we are using a system to name our part as p.e. ABGO_100 where the ABGO stands for the project. Now I want to find a way to link the filename to the partnumber (because I often use ctrl-c and ctrl-v and then rename in explorer to generate more parts. And it's also in de library parts that I use. Is there a way to do as shown in my example:

First part: save as ABGO_100.ipt partnumber automatic ABGO_100
In explorer ctrl-c ctrl-v: ABGO_100 copy.ipt
Rename: ABGO_101.ipt partnumber automatic ABGO_101

This would save me (and the company ofcourse) a lot of time.

Thx in advance,

Beli

6,563 Views
12 Replies
Replies (12)
Message 2 of 13

Mark.Lancaster
Consultant
Consultant

@Anonymous

 

If I understand your requirements and assuming you don't use Vault.  Use the Inventor Design Assistant to rename your files as needed and/or to update part numbers.  Part numbers can also be updated through the Assembly BOM interface.  As a side note, the design assistant is not really user friendly so be patience with it..  Smiley Wink

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 13

ThomasB44
Mentor
Mentor

Hi @Anonymous,

I'm not a great fan of Design assistant, so in most of case, I copy and paste parts or assembly inside Inventor.

Then I use the "save and replace" command to quickly copy some design.

 

If your wish is to always have the part number equal to the filename you could run this kind rule in your top level assembly. This rule will set ALL sub files part number equal to the related file name. So at the end of your copy and paste task, you could run it only one time.

 

SyntaxEditor Code Snippet

'Check if it is an assembly
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("This is NOT an assembly document !", "iLogic",MessageBoxButtons.OK,MessageBoxIcon.Error)
    Return
End If

'Create variables
Dim FullFileName, FileName, PartNumber As String
Dim FNamePos As Long
'set a reference to the assembly component definintion
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Inventor.Document
Dim asmDef As AssemblyComponentDefinition
asmDef = asmDoc.ComponentDefinition

'Prevent message
If MsgBox("This will update the part number equal to file name in all sub files" _
& vbNewLine & "Do you wish to Continue ?", vbYesNo + vbQuestion, "iLogic") = vbNo Then Return

'Store referenced documents properties
For Each oDoc In asmDoc.AllReferencedDocuments
    FullFileName = oDoc.FullFileName 'With extension
    'Find last "\" position in full filename path string   
    FNamePos = InStrRev(FullFileName, "\", - 1)
    'Extract FileName 
    FileName = Mid(FullFileName, FNamePos + 1, Len(FullFileName) - FNamePos)
    PartNumber = Left(FileName,Len(FileName) - 4) 'Without extension
    iProperties.Value(FileName, "Project", "Part number") = PartNumber
Next

 

You could also have an external rule, set with an event trigger to each of your parts, but I think it will be less friendly to use.

 

 


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

Message 4 of 13

Anonymous
Not applicable

not completely what I was looking for but tested this method and I'm going to use it. Thank you! 🙂 

0 Likes
Message 5 of 13

Anonymous
Not applicable

@Anonymous wrote:

not completely what I was looking for but tested this method and I'm going to use it. Thank you! 🙂 


'SAVE COPY AS' Would do both at once since UNFORTUNATELY, Part Number=File Name upon creation... which i still find insanely frustrating and pointless. 

0 Likes
Message 6 of 13

NachoShaw
Advisor
Advisor

From a top level assembly, you could write a bit of code to (if i understand correctly):

 

select part from assembly

open invisible

get part number

change from ABCD_100 to ABCD_101

save as new part number (automatically updating the Part number field)

optionally add new part into assembly

if thats what you need, i can write up a bit of code for that

 

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 7 of 13

Anonymous
Not applicable

@ThomasB44  Thank you very much, that is what i am looking for.

Message 8 of 13

geralJD3XV
Participant
Participant

Hi,

 

Is there a way to do the opposite? Change the file name to be equal to the part number?

Thanks

0 Likes
Message 9 of 13

A.Acheson
Mentor
Mentor

The original code has allready found the filename so make it equal to the partnumber. 

 

An easier method to get the filename is using the system.IO functions see source documentation here

 

Dim FileName as String = System.IO.GetFileNameWithoutExtension (oDoc.FullFileName)
iProperties.Value(FileName, "Project", "Part number") = FileName

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 10 of 13

geralJD3XV
Participant
Participant

Thank you for the help. I tried what you said but it didn´t work.

Can you help me figure out what i am doing wrong here?

 

'Check if it is an assembly
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("This is NOT an assembly document !", "iLogic",MessageBoxButtons.OK,MessageBoxIcon.Error)
    Return
End If

'Create variables
Dim FullFileName, FileName, PartNumber As String
Dim FNamePos As Long
'set a reference to the assembly component definintion
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Inventor.Document
Dim asmDef As AssemblyComponentDefinition
asmDef = asmDoc.ComponentDefinition

'Prevent message
If MsgBox("This will update the part number equal to file name in all sub files" _
& vbNewLine & "Do you wish to Continue ?", vbYesNo + vbQuestion, "iLogic") = vbNo Then Return

'Store referenced documents properties
For Each oDoc In asmDoc.AllReferencedDocuments
    FullFileName = oDoc.FullFileName 'With extension
    'Find last "\" position in full filename path string   
    FNamePos = InStrRev(FullFileName, "\", - 1)
    'Extract FileName 
    FileName = PartNumber
   
    iProperties.Value(FileName, "Project", "Part number") = FileName
Next

 

0 Likes
Message 11 of 13

A.Acheson
Mentor
Mentor

@geralJD3XV @Sorry I had a brain freeze yesterday. Changing the filename to be the part number is a much bigger task depending if you have subassemblies and parts in your assembly. You will need to perform a save as/replace file references. I suggest posting this as a separate post as it is a separate topic than the original and it will be complicated. Here is a working post that is renaming the files by creating a brand new set of files using save as then for the reference documents performing a replace reference. Exactly how you would do this manually. The only tweak you will need is to change the filename to be the partnumber of the file before it is saved.

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 12 of 13

RudolfVanDerSpuy
Contributor
Contributor

Hi there:

I have exactly the same problem.  I also tried to restructure the ilogic  code and arrived at the exact same point and it does not work. The fact that one can use Design Assistant to do the renaming , by copying the part number and naming the file name accordingly means that there are no obvious conflicts. It is however the typical pain in the neck job using DA and I am sure that ilogic can resolve the issue. @A.Acheson  suggested a new post. @geralJD3XV  Have you had any joy?

0 Likes
Message 13 of 13

RudolfVanDerSpuy
Contributor
Contributor

Good day. If you have not resolved your problem in this regard: I have a piece of iLogic code that can help with this. 

0 Likes