Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

part number from file name

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
FireBallFab
746 Views, 5 Replies

part number from file name

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
5 REPLIES 5
Message 2 of 6
planglais75
in reply to: FireBallFab

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
Message 3 of 6
FireBallFab
in reply to: planglais75

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.)

 

 

Message 4 of 6
FireBallFab
in reply to: FireBallFab

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?

Message 5 of 6
planglais75
in reply to: FireBallFab

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

Message 6 of 6
FireBallFab
in reply to: planglais75

Thanks Pascal! Works like a charm 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report