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: 

Ilogic part name

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
947 Views, 2 Replies

Ilogic part name

Our files have the following name "J12345-01-001.

I want to split the name so it returns the value after the second -

Can anybody help with a simple code.

I can split it using the count method but sometimes the value in the middle (01) is longer than 2 digits so

this then causes errors.

 

 

2 REPLIES 2
Message 2 of 3
mcgyvr
in reply to: Anonymous


@Anonymous wrote:

Our files have the following name "J12345-01-001.

I want to split the name so it returns the value after the second -

Can anybody help with a simple code.

I can split it using the count method but sometimes the value in the middle (01) is longer than 2 digits so

this then causes errors.

 

 


Sounds like you should be using the "Strings.Right" method

https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.strings.right?view=netframework-4.8

A string containing a specified number of characters from the right side of a string.

Dim testString As String = "J12345-00001-002"
' Returns "002".
Dim subString As String = Right(testString, 3)


-------------------------------------------------------------------------------------------
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 3
Curtis_Waguespack
in reply to: Anonymous

Hi @Anonymous 

 

I typically use the Split function for something like this. Here is an example that splits the string using the dashes

sMyString = "12345-01-001"

'split the string into an array using the dash
sMyArray = sMyString.Split("-")

'use the members of the array in a message box
MsgBox("the first bit is this: " & vbLf & sMyArray (0) )
MsgBox("the middle bit is this: " & vbLf & sMyArray (1) ) 
MsgBox("the last bit is this: " & vbLf & sMyArray (2) )

 

Here's another example using a backslash as the split characther, and it shows how to use UBound to find the upper bounds of the array, which in the case of a file path will always be the file name:

sMyString = "C:\TEMP\Test\11111-01\11-111.ipt"

'split the string into an array using the dash
sMyArray = sMyString.Split("\")

'use the members of the array in a message box
MsgBox("the first bit is this: " & vbLf & sMyArray(0) )
MsgBox("the next bit is this: " & vbLf & sMyArray(1) ) 
MsgBox("the next bit after that is this: " & vbLf & sMyArray(2))

'get the upper bounds of the array
'in this case it would be the file name
i = UBound(sMyArray)
MsgBox("the file name is this: " & vbLf & sMyArray(i))

'change the string 
sMyString = "C:\TEMP\Test\111-1111\11111-01\111-1111\11111-01\11-111.ipt"
sMyArray = sMyString.Split("\")

'get the upper bounds of the array
'in this case it would be the file name
i = UBound(sMyArray)
MsgBox("Length of path changed, but we can still find the file name easily: " & vbLf & sMyArray(i))

Just a reminder, programming questions of this type are generally placed on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I'll as the forum moderators to move this thread to that forum for you.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report