Ilogic file name to populate Iproperties

Ilogic file name to populate Iproperties

Anonymous
Not applicable
3,695 Views
16 Replies
Message 1 of 17

Ilogic file name to populate Iproperties

Anonymous
Not applicable

Hello everyone,

 

I have read other problem similar with mine, but i have no idea how to change the code(total newbie)

I want to be able to populate the Iproperties starting from my filename.

The format of my file name is the same everytime: XXXXX-YYY-ZZZ-WWWWW-VVV_U_Name

I would like to have in Iproperties:

Part number = XXXXX-YYY-DRW-WWWWW-VVV, even if the ZZZ is CAD in file name every time

Stock number = XXXXX-YYY-ZZZ-WWWWW-VVV_U_Name

Description = Name

Revision = U

 

I already found something similar, but i am not capable of modifying the code: https://forums.autodesk.com/t5/inventor-customization/ilogic-to-trim-a-file-name-to-populate-iproper...

 

I would appreciate if someone is willing to help me.

 

PS: forgot to mention that number of characters can be different at least for the first part of the filename(XXXXX): XXXXX-YYY-ZZZ-WWWWW-VVV_U_Name

Sometimes YYY can have different number of characters

 

0 Likes
Accepted solutions (1)
3,696 Views
16 Replies
Replies (16)
Message 2 of 17

tonythm
Advocate
Advocate

Hi @Anonymous 

 

Please refer code below:

I use VBA code from excel file. You can use code Split, Right, left, Mid or Replace.

'iLogic code:

If iProperties.Value("Project", "Part Number")  IsNot  ThisDoc.FileName(False) Then
         iProperties.Value("Project", "Part Number") = ThisDoc.FileName(False)
End If
'VBA code:

Sub SetPartNumber()
    Dim oWkbk As Workbook
    Set oWkbk = ThisWorkbook
    Dim oSheet As Worksheet
    Set oSheet = oWkbk.ActiveSheet
    Dim oInv As Inventor.Application
    Set oInv = GetObject(, "Inventor.Application")
    Dim oDoc As Document
    Set oDoc = oInv.ActiveDocument
    Dim oPartNumber As Property
    Set oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
    Dim oDisplayName As String
    oDisplayName = Split(oDoc.DisplayName, ".")(0)
    oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = oDisplayName
    MsgBox "Done!"
    oWkbk.Save
End Sub

 

0 Likes
Message 3 of 17

Anonymous
Not applicable

Thank you for your reply, but as i said, i have no idea how to change, or modify any code:) I barely understand how it works, so that's why i need your help.

0 Likes
Message 4 of 17

tonythm
Advocate
Advocate

Hi @Anonymous 

Is this what you need?

iProperties.Value("Project", "Part Number") = Left(ThisDoc.FileName(False), 23)
iProperties.Value("Project", "Stock Number") = ThisDoc.FileName(False)
iProperties.Value("Project", "Description") = Right(ThisDoc.FileName(False), 4)
iProperties.Value("Project", "Revision Number") = Mid(ThisDoc.FileName(false),25,1)

 Capture.JPG

0 Likes
Message 5 of 17

Anonymous
Not applicable

Yes this is what the final result should look like.

 

But the problem is that the code needs to scan the entire string, and split where i have "_", because the number of character are not the same all the time.

For example Name, can be formed from 2 different words like "XXXXX-YYY-ZZZ-WWWWW-VVV_U_Metal Bracket"

In addition I will need the first characters from the string to be put in Project field : "XXXXX-YYY-ZZZ-WWWWW-VVV_U_Name"

Another thing that i need is "ZZZ" to be replaced everytime with "DRW"

Keep in mind that also "U" can be 1 or 1D1, 1D2 etc.

 

PS: your short code works if the number of characters are the same everytime. 

This string : "XXXXX-YYY-ZZZ-WWWWW-VVV_U_Name" cand be :  "XXXXXXX-YYYYY-ZZZ-WWWWW-VVV_UUU_Name name"

0 Likes
Message 6 of 17

JhoelForshav
Mentor
Mentor

@Anonymous 

 

Something like this?

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)
0 Likes
Message 7 of 17

Anonymous
Not applicable

Thank you very much; it's working:)

Is it possible to have first characters "XXXXX-YYY-ZZZ-WWWWW-VVV_U_Name" to be filled in Project filed.

 

Another idea i have now: if i have an assembly, and i fill the information in Project field, is it possible to copy this value on all parts form that assembly?

0 Likes
Message 8 of 17

JhoelForshav
Mentor
Mentor

I made the rule so it does what you asked both if you run it from an assembly or a part.

Hope it's what you're looking for 🙂

 

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
			iProperties.Value(opDoc.DisplayName, "Project", "Project") = iProperties.Value("Project", "Project")
		End If
	Next
End If
0 Likes
Message 9 of 17

Anonymous
Not applicable

If i run it in a separate part, it's working but when i run it on an assembly, i have an error(see the picture attached)

 

But i can add this line to your first solution and it works:

iProperties.Value("Project", "Project") = oFileNameSplit(0)

The problem is that not all the time the project field should be this:)(first characters from the filename) that's why i wanted to just define it in the main assembly, and the information from the project field to be propagated to all the sub-assemblies and parts-maybe for this i will need a different ilogic macro.

0 Likes
Message 10 of 17

JhoelForshav
Mentor
Mentor

@Anonymous 

Okej... Seems like using the document.Displayname was an unstable solution.

This should do what you want from assembly aswell though.

 

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
0 Likes
Message 11 of 17

Anonymous
Not applicable

I have just tried it. I will try to explain what is doing now:)

1. If i have an assembly with parts inside, it propagates what i am filling under project field of the assembly to all the parts(this is good), but is not changing anything else under Iproperties-not for assembly and neither for the parts

2. if I have as assembly with sub-assemblies and also parts, it propagates the project information only for the parts, not for the sub-assemblies and the parts inside those

 

Anyway, i want to thank you again for your help. I believe is not easy to make what i want in only one ilogic rule. But if it would be possible at least to copy the project info from the main assembly to the entire component list(even if there are sub-assy or parts)

0 Likes
Message 12 of 17

JhoelForshav
Mentor
Mentor

@Anonymous 

Sorry, I thought that was what you wanted...

I'll have another go at it 🙂

0 Likes
Message 13 of 17

Anonymous
Not applicable

It's doing what it should for sure:)

The only thing that i would love to have is the propagation of the Project field to all the sub-assemblies and parts that are in the main assembly 🙂

0 Likes
Message 14 of 17

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

Have a look at this:

Dim oDoc As Document = ThisDoc.Document
Try
	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)
Catch
	'Wrong format filename
End Try
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
	For Each opDoc As Document In oDoc.AllReferencedDocuments
		If opDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or _
			opDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
			Try
				If oDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(opDoc).Count > 0
					Dim oThisFileName As String = System.IO.Path.GetFileNameWithoutExtension(opDoc.FullDocumentName)
					Dim oThisFileNameSplit() As String = oThisFileName.Split("-")

					Dim oDesignProps As PropertySet = opDoc.PropertySets.Item("Design Tracking Properties")
					Dim oSumProps As PropertySet = opDoc.PropertySets.Item("Inventor Summary Information")
					oDesignProps.Item("Part Number").Value = oThisFileNameSplit(0) & "-" & oThisFileNameSplit(1) & "-" & "DRW" _
					& "-" & oThisFileNameSplit(3) & "-" & oThisFileNameSplit(4).Split("_")(0)

					oDesignProps.Item("Stock Number").Value = oThisFileName

					oDesignProps.Item("Description").Value = oThisFileNameSplit(4).Split("_")(2)

					oSumProps.Item("Revision Number").Value = oThisFileNameSplit(4).Split("_")(1)

					oDesignProps.Item("Project").Value = iProperties.Value("Project", "Project") 'From main assy

				End If
			Catch
				'Wrong format filename
			End Try
		End If
	Next
End If

 

If run from assembly

The assembly properties will update.

Also, all of the occurrences (on every level) will update their properties with respect to their filenames. The project property will be taken from assembly though.

 

If run from part

All properties (Including project) will update with respect to the filename.

0 Likes
Message 15 of 17

Anonymous
Not applicable

I tried this last one and i have those errors(see picture). This is happening if i run it in assembly and also if i run it on a simple part

 

0 Likes
Message 16 of 17

JhoelForshav
Mentor
Mentor

@Anonymous 

That's wierd...

Nothing wrong with the code on my end. It just doesn't seem right.

Have you tried restarting inventor?

0 Likes
Message 17 of 17

Anonymous
Not applicable

You are right:) i didn't even restart the Inventor. Thank you very much for your help! This is amazing and i would love to know to do this, because i am lazy person and i have plenty of good ideas:))