Inventor Customization

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

part number from file name

385 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
Valued Contributor
planglais
Posts: 58
Registered: ‎03-10-2011
Message 2 of 6 (381 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: 20
Registered: ‎12-18-2012
Message 3 of 6 (378 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: 20
Registered: ‎12-18-2012
Message 4 of 6 (375 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: 58
Registered: ‎03-10-2011
Message 5 of 6 (370 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: 20
Registered: ‎12-18-2012
Message 6 of 6 (366 Views)

Re: part number from file name

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

Thanks Pascal! Works like a charm :smileyhappy:

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube