Inventor Customization

Reply
Contributor
nick
Posts: 23
Registered: ‎12-18-2012
Message 1 of 6 (412 Views)
Accepted Solution

part number from file name

412 Views, 5 Replies
02-13-2013 06:44 AM

Hi all,


I name my files with our part numbers and the revision number. Our part numbers are 6 to 9 digits long and sometimes start with a zero! My iLogic rule, while simple, drops the first zero if its there. See the "FirstNumbers" below: (I tried to add the CStr(), but now I see that it just changes it to text after it drops the zero!)

 

Any suggestions?

 

ThisFile = ThisDoc.FileName(False) 'without extension
FirstNumbers = CStr(Val(ThisFile)) 'sets the first numbers from the file name to text
PartNumber = iProperties.Value("Project", "Part Number") 'reads part number from file
'check to see if the part number is the same as the file name's numbers If String.Compare(FirstNumbers, PartNumber, True) = 0 Then 'do nothing Else
'set the Part Number to the file name's numbers iProperties.Value("Project", "Part Number") = FirstNumbers
'let's me know that something has been done MessageBox.Show("Part Number has been set to " & FirstNumbers, "Part Number from File Name") End If

If a space is always present, you can use the split method:

 

Split("060321 Rev2.iam", " ")(0) ' Will return 060321

Method Split(string, separator) return an array of string:

     element 0 => 060321

     element 1 => Rev2.iam

 

So element 0 will return your part number.

 

Pascal

Valued Contributor
planglais
Posts: 61
Registered: ‎03-10-2011
Message 2 of 6 (408 Views)

Re: part number from file name

02-13-2013 07:14 AM in reply to: nick

Hi nick,

 

Why you don't simply compare PartNumber with ThisFile ?

 

or here's two suggestions to format your ThisFile variable:

 

FirstNumbers = String.Format("{0:000000000}" ,Val(ThisFile)) ' Always return 9 digits with leading 0
FirstNumbers = String.Format(ThisFile, "{c}") ' Return
Contributor
nick
Posts: 23
Registered: ‎12-18-2012
Message 3 of 6 (405 Views)

Re: part number from file name

02-13-2013 07:40 AM in reply to: planglais

planglais,

 

Thanks for the quick reply! I can't change the length of the part numbers, as they are tied into our inventory system - otherwise the "String" example would work fine.

Here are some examples of file names I have to work with:

 

060321 Rev2.iam

990101500 Rev1.ipt

0512135.ipt

625121 90-32dn.iam

201301 - Rev3.ipt

 

(Set the first numbers to the part number.)

 

 

Contributor
nick
Posts: 23
Registered: ‎12-18-2012
Message 4 of 6 (402 Views)

Re: part number from file name

02-13-2013 07:41 AM in reply to: nick

It seems there is always a space after the part number. Is there a way to get a string to the left of a space?

Valued Contributor
planglais
Posts: 61
Registered: ‎03-10-2011
Message 5 of 6 (397 Views)

Re: part number from file name

02-13-2013 07:49 AM in reply to: nick

If a space is always present, you can use the split method:

 

Split("060321 Rev2.iam", " ")(0)  ' Will return 060321

Method Split(string, separator) return an array of string:

     element 0 => 060321

     element 1 => Rev2.iam

 

So element 0 will return your part number.

 

Pascal

Contributor
nick
Posts: 23
Registered: ‎12-18-2012
Message 6 of 6 (393 Views)

Re: part number from file name

02-13-2013 07:53 AM in reply to: planglais

Thanks Pascal! Works like a charm :smileyhappy:

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.