File name split into part number, description, vendor

File name split into part number, description, vendor

stefan.godfroid
Participant Participant
1,659 Views
17 Replies
Message 1 of 18

File name split into part number, description, vendor

stefan.godfroid
Participant
Participant

Hey

 

I am new here.

 

We have 2 types of file names:

 

Type 1: (parts and assembly's)
Our files have the following name: "xxxx-yy-z_name"
How can I split this name into Part_number and Discription (Iproperties)?
Part_Number: "xxxx-yy-z"
Description: "name"

 

Type 2: (purchased parts and assembly's)
"Festo_dfm-16-50-ppv-a"
Splitting into:
Vendor: Festo
Part number: dfm-16-50-ppv-a

 

 

How do you do that in I-logic?

 

Yours sincerely

 

Stefan

0 Likes
Accepted solutions (1)
1,660 Views
17 Replies
Replies (17)
Message 2 of 18

mcgyvr
Consultant
Consultant

 

This should do it for Type 1..

I'll update it to to both requirements in a minute.. 

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 underscore character found", "ILogic")
Return
End If

PartNumber = Left(FileName, UnderPos - 1)
MessageBox.Show(PartNumber, "Part Number")
iProperties.Value("Project", "Part Number") = PartNumber


Description = Left(FileName, Len(FileName))
Description = Right(Description, Len(Description) - UnderPos)
MessageBox.Show(Description, "Description")
iProperties.Value("Project", "Description") = Description

  



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 18

mcgyvr
Consultant
Consultant

Ok this should cover both your needs..

Dim FileName, PartNumber, Description, Vendor 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 underscore character found", "ILogic")
Return
End If

Dim oDoc As Document = ThisApplication.ActiveDocument
oStruct = oDoc.ComponentDefinition.BOMStructure
MessageBox.Show(oStruct, "Title")

If oStruct = 51973 Then
Vendor = Left(FileName, UnderPos - 1)
MessageBox.Show(Vendor, "Vendor")
iProperties.Value("Project", "Vendor") = Vendor
PartNumber = Left(FileName, Len(FileName))
PartNumber = Right(PartNumber, Len(PartNumber) - UnderPos)
MessageBox.Show(PartNumber, "Part Number")
iProperties.Value("Project", "Part Number") = PartNumber
Else
PartNumber = Left(FileName, UnderPos - 1)
MessageBox.Show(PartNumber, "Part Number")
iProperties.Value("Project", "Part Number") = PartNumber
Description = Left(FileName, Len(FileName))
Description = Right(Description, Len(Description) - UnderPos)
MessageBox.Show(Description, "Description")
iProperties.Value("Project", "Description") = Description
End If


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 4 of 18

stefan.godfroid
Participant
Participant

Thank you for the response
What event can I start the rule?

0 Likes
Message 5 of 18

mcgyvr
Consultant
Consultant

@stefan.godfroid wrote:

Thank you for the response
What event can I start the rule?


Before save would be good.. 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 6 of 18

stefan.godfroid
Participant
Participant

The rule does not work.
I used the rule from your first answer as a test.
If I give a name xxxx-yy-z_name then I get the error "No underscore character found". However, I have _ in the filename.
The iproperties are also not filled in correctly. Only under part number is the file name.

0 Likes
Message 7 of 18

stefan.godfroid
Participant
Participant

Now it works!  (your first solution).  I replaced your _ with mine _.  It is the same, i know but I think the reason is that I'm working with an azerty keyboard.

And second, i used the trigger event "after save document".

 

Now i'm going to test your second solution.  So it works with purchased parts.

0 Likes
Message 8 of 18

salariua
Mentor
Mentor

I am a bit late to the party but I only have one speed .... really slow.

 

have given your problem a try and wrote a code which you can run from the assembly and it should change all parts ... but I haven't test it that much really.

 

so run this from your assembly and it should change all components.

 

'define the active assembly
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument 

Dim oFullFileName As String
Dim oDoc As Inventor.Document
Dim oPropSet As PropertySet


For Each oDoc In oAsmDoc.AllReferencedDocuments
	oPropSet = oDoc.PropertySets.Item("Design Tracking Properties")
	
	oFullFileName = oDoc.FullFileName
	'find the postion of the last backslash in the path
	FNamePos = InStrRev(oFullFileName, "\", -1)   
	'get the file name with the file extension
	Name = Right(oFullFileName, Len(oFullFileName) - FNamePos)
	'get the file name (without extension)
	ShortName = Left(Name, Len(Name) - 4)
	
	If oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
		VendorPos = InStrRev(ShortName, "_", -1)
		Vendor = Left(ShortName, (VendorPos-1))
		PartNumber = Right(ShortName, (Len(ShortName)-VendorPos))

		oPropSet.Item("Vendor").Value = Vendor
		oPropSet.Item("Part Number").Value = PartNumber
	Else 
		PartNumberPos = InStrRev(ShortName, "_", -1)
		PartNumber = Left(ShortName, (PartNumberPos-1))
		Description = Right(ShortName, (Len(ShortName)-PartNumberPos))

		oPropSet.Item("Description").Value = Description
		oPropSet.Item("Part Number").Value = PartNumber
		
	End If

Next
Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 9 of 18

stefan.godfroid
Participant
Participant

I'm going to use your first solution.  The solution with the purchased part i'm nog going to use it.  But thanks al lot!

 

I have a second question.

 

Our files have the following name: "xxxx-yy-z_name"
And we have populated the filename in to:
Part_Number: "xxxx-yy-z"
Description: "name"

 

Now i want to populate "XXXX" and YY of the filename (or part number) into 2 custom properties lets say "Nr" and "Pos"

 

I want to have:

Part_Number: "xxxx-yy-z"  (ipropertie)
Description: "name"          (ipropertie)

Nr: "xxxx"                         (custom propertie)

Pos:  "yy"                          (custom propertie)

 

How can we do that?

 

 

0 Likes
Message 10 of 18

mcgyvr
Consultant
Consultant

@stefan.godfroid wrote:

I'm going to use your first solution.  The solution with the purchased part i'm nog going to use it.  But thanks al lot!

 

I have a second question.

 

Our files have the following name: "xxxx-yy-z_name"
And we have populated the filename in to:
Part_Number: "xxxx-yy-z"
Description: "name"

 

Now i want to populate "XXXX" and YY of the filename (or part number) into 2 custom properties lets say "Nr" and "Pos"

 

I want to have:

Part_Number: "xxxx-yy-z"  (ipropertie)
Description: "name"          (ipropertie)

Nr: "xxxx"                         (custom propertie)

Pos:  "yy"                          (custom propertie)

 

How can we do that?

 

 


@stefan.godfroid

Before we spend time on that are you going to have more requests like these? 

Its best to just tell us everything at one time.. So we don't have to rewrite code over again..

 

Have you tried to understand the code written above to see if you can accomplish this by yourself?

salariua left the comments in the code he provided.. comments start with ' 

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 11 of 18

stefan.godfroid
Participant
Participant

My knowledge for I-logic is still very minimal.
Therefore the question.
Already, I'm learning.

Apart from my last question, there will be no other questions.

0 Likes
Message 12 of 18

mcgyvr
Consultant
Consultant

@stefan.godfroid

One last thing.. Will it always be xxxx-yy-z_name

So always 4 digits in the x or will it ever be xxxxx-yyy-zzz_name or similar

Will the x parts always be 4 digits and y parts always 2 and z always 1 then name?

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 13 of 18

stefan.godfroid
Participant
Participant

Yes,  allways 4 digits XXXX and  2 digits YY.

 

0 Likes
Message 14 of 18

mcgyvr
Consultant
Consultant
Accepted solution

@stefan.godfroid wrote:

Yes,  allways 4 digits XXXX and  2 digits YY.

 


@stefan.godfroid.

How about this..

as simple to understand as I could make it.. should work

'Split xxxx-yy-z_name
'into the following
'part Number: xxxx-yy-z
'description:name
'Custom NR:xxxx
'Custom POS:yy

''define your strings
Dim FileName, PartNumber, Description, NR, oPOS, POS As String
'get the filename to start it all
FileName = ThisDoc.FileName(False)

'assign all our variables a value
'select the first 9 digits starting from the LEFT of the filename and set the partnumber variable to that
PartNumber = Left(FileName, 9)

'select the first 4 digits starting from the RIGHT of the filename and set the description variable to that
Description = Right(Filename, 4)

'select the first 4 digits starting from the LEFT of the filename and set the NR variable to that
NR = Left(FileName, 4)

'select the first 4 digits starting from the RIGHT of the part number and set the oPOS variable to that.. doing this to get rid of the z
oPOS = Right(PartNumber, 4)

'select the first 2 digits starting from the LEFT of the oPOS variable and set the POS variable to that
POS = Left(oPOS, 2)



'now lets set all of our iproperties


'set the part number iproperty to the partnumber variable we just created
iProperties.Value("Project", "Part Number") = PartNumber

'set the description iproperty to the description variable we just created
iProperties.Value("Project", "Description") = Description

'set the custom NR iproperty to the NR variable we just created
iProperties.Value("Custom", "NR") = NR

'set the custom POS iproperty to teh POS variable we just created
iProperties.Value("Custom", "POS") = POS


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 15 of 18

stefan.godfroid
Participant
Participant

Thanks!  I test it tomorow! 

0 Likes
Message 16 of 18

stefan.godfroid
Participant
Participant

It works great.

Now i have another question.

 

I have a custom parameter "TEKENINGCODE".  

When the "TEKENINGCODE"= K.  Then we have to split the filename in to 2 pieces.  Everything before "_" must be filled in the custom parameter "FABRIKANT".  And every thing after "_" must be filled in into the parameter "Part number".

 

And in other cases, then the parameters must be filled like the original I-logic code as mentioned above.

 

Can it be done?

0 Likes
Message 17 of 18

mcgyvr
Consultant
Consultant

@stefan.godfroid wrote:

It works great.

Now i have another question.

 

I have a custom parameter "TEKENINGCODE".  

When the "TEKENINGCODE"= K.  Then we have to split the filename in to 2 pieces.  Everything before "_" must be filled in the custom parameter "FABRIKANT".  And every thing after "_" must be filled in into the parameter "Part number".

 

And in other cases, then the parameters must be filled like the original I-logic code as mentioned above.

 

Can it be done?


Is this what you are asking about?

''define your strings
Dim FileName, PartNumber, Description, NR, oPOS, POS, FABRIKANT As String

'If TEKENINGCODE is K then do the following..
If iProperties.Value("Custom", "TEKENINGCODE") = "K" Then
	'get the filename to start it all
	FileName = ThisDoc.FileName(False)

	'assign all our variables a value
	'select the first 9 digits starting from the LEFT of the filename and set the partnumber variable to that
	PartNumber = Left(FileName, 9)

	'select the first 4 digits starting from the RIGHT of the filename and set the description variable to that
	FABRIKANT = Right(FileName, 4)

	'set the custom POS iproperty to teh POS variable we just created
	iProperties.Value("Custom", "FABRIKANT") = FABRIKANT

'If TEKENINGCODE is not K then do the following..
Else

		'Split xxxx-yy-z_name
		'into the following
		'part Number: xxxx-yy-z
		'description:name
		'Custom NR:xxxx
		'Custom POS:yy

	'get the filename to start it all
	FileName = ThisDoc.FileName(False)

	'assign all our variables a value
	'select the first 9 digits starting from the LEFT of the filename and set the partnumber variable to that
	PartNumber = Left(FileName, 9)

	'select the first 4 digits starting from the RIGHT of the filename and set the description variable to that
	Description = Right(FileName, 4)

	'select the first 4 digits starting from the LEFT of the filename and set the NR variable to that
	NR = Left(FileName, 4)

	'select the first 4 digits starting from the RIGHT of the part number and set the oPOS variable to that.. doing this to get rid of the z
	oPOS = Right(PartNumber, 4)

	'select the first 2 digits starting from the LEFT of the oPOS variable and set the POS variable to that
	POS = Left(oPOS, 2)



	'now lets set all of our iproperties


	'set the part number iproperty to the partnumber variable we just created
	iProperties.Value("Project", "Part Number") = PartNumber

	'set the description iproperty to the description variable we just created
	iProperties.Value("Project", "Description") = Description

	'set the custom NR iproperty to the NR variable we just created
	iProperties.Value("Custom", "NR") = NR

	'set the custom POS iproperty to teh POS variable we just created
	iProperties.Value("Custom", "POS") = POS

End If


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 18 of 18

stefan.godfroid
Participant
Participant

Oops, sorry to mention:
In case the user parameter TEKENINGCODE = K:
The filename can than be different: The number of characters in the name can be arbitrary. It can eg XXXX_YYYYYY or XXXXXX_YYYYY or XXX_YY-YYYY-YYYY etc ...

0 Likes