Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I'm still quite a newbie at iLogic and looks like I have run into a problem trying to figure this out.
I would appreciate any help.
I have used the code below to successfully split the filename when saved - into 2 parts - for iProperties 1) Part Number and 2) Description.
Format is "Part Number - Description" with the space-dash-space, separating the two and this has worked well for me when testing.
Working code below - found here: https://forums.autodesk.com/t5/inventor-forum/file-name-split-into-part-number-description-vendor/td...
Dim FileName, PartNumber, Description As String
Dim UnderPos As Long
FileName = ThisDoc.FileName(False)
'Search the "-" position in string
UnderPos = InStrRev(FileName, "-", - 1)
If UnderPos = 0 Then
MessageBox.Show("No dash character found in filename - please use format: 'DTR/DOC number - Description' with space-dash-space. Rename filename in Vault to change Part number and/or Description.", "Rule for naming files")
Return
End If
PartNumber = Left(FileName, UnderPos - 2)
'MessageBox.Show(PartNumber, "Part Number")
iProperties.Value("Project", "Part Number") = PartNumber
Description = Left(FileName, Len(FileName))
Description = Right(Description, Len(Description) - (UnderPos+1))
'MessageBox.Show(Description, "Description")
iProperties.Value("Project", "Description") = Description
I place this as an iTrigger - "after save" just to avoid the first save Inventor does on new file. I did look at other code for this also, but really can't get around the "first save" that Inventor does, as "save as" dialog always appears for first save - but would be nice if this could also somehow be fixed, and run always as global trigger for ipt/iam and dwg files 😁 Where there is a will - there is a way.
So, I now have 2 main issues
-------------------------------
1) if I use more than one dash eg. "Part Number - Descrip-tion" for filename, it fails putting iProperty Part Name as "Part Number - Descrip" and Description as "tion"
2) I would like to optionally have the Revision number added as filename "Part Number_A - Description" - is there a way to do this, so if _A (or eg. _B) is part of the filename, iLogic will then add the value "A" to Rev. Number also.
To sum it up the format is:
Filename "Part Number_A - Description" to be saved into iProperties
1) ("Project", "Part Number")
2) sometimes if _A/_B/_C etc. appear also ("Project", "Revison Number")
3) and ("Project", "Description")
and working for ipts/iams and dwgs 🤔
Further, I looked at some other code as below, but would be nice with a modified code to fix the 2 issues i have 😉
Other code below - found here: https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-file-name-to-populate-iproperties/...
Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
Dim oFileName As String = ThisDoc.FileName(False)
Dim oFileNameSplit() As String = oFileName.Split("-")
iProperties.Value("Project", "Part Number") = oFileNameSplit(0) & "-" & oFileNameSplit(1) & "-" & "DRW" _
& "-" & oFileNameSplit(3) & "-" & oFileNameSplit(4).Split("_")(0)
iProperties.Value("Project", "Stock Number") = oFileName
iProperties.Value("Project", "Description") = oFileNameSplit(4).Split("_")(2)
iProperties.Value("Project", "Revision Number") = oFileNameSplit(4).Split("_")(1)
iProperties.Value("Project", "Project") = oFileNameSplit(0)
ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
For Each opDoc As Document In oDoc.ReferencedDocuments
If opDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
opDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value = iProperties.Value("Project", "Project")
End If
Next
End If
Hope someone can help 😉
Solved! Go to Solution.