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: 

How to Get Prefix of Drawing Name?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
BeKirra
182 Views, 4 Replies

How to Get Prefix of Drawing Name?

For example, a drawing file name = ABCDE12345-111-222.idw/dwg.

How to get the prefix "ABCDE" from the file name in iLogic?

Thanks in advance.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
4 REPLIES 4
Message 2 of 5
Andrii_Humeniuk
in reply to: BeKirra

Hi @BeKirra . If in your case the prefix is the first 5 characters, then try this code:

Dim oDoc As Document = ThisDoc.Document
Dim sPrefix As String = IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName).Substring(0, 5)
MessageBox.Show(sPrefix)

If your name has a different number of letters, you can use this code (it finds the first number):

Public Sub Main()
	Dim oDoc As Document = ThisDoc.Document	
	Dim sName As String = IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName)
	Dim i As Integer = GetFirstNumber(sName)
	MessageBox.Show(sName.Substring(0, i))
End Sub

Private Function GetFirstNumber(ByVal sName As String) As Integer
	For i As Integer = 0 To sName.Length - 1	
		If IsNumeric(sName.Chars(i)) Then Return i
	Next i
	Return sName.Length
End Function

 

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 5
BeKirra
in reply to: Andrii_Humeniuk


@Andrii_Humeniuk wrote:

Hi @BeKirra . If in your case the prefix is the first 5 characters, then try this code:


Sorry, I should give more details.

The number of characters in the drawing name varies through our sales, projects and company standard drawings.

However, the naming format is the same.

"Letters + Numbers" (e.g. LETTERS1234567)

 

It would definitely help if iLogic code can detect and get all characters before numbers.

Thanks. 🙂

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 4 of 5
Curtis_Waguespack
in reply to: BeKirra

@BeKirra 

 

Maybe something like this example.

 

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

 

 

sName = "ABCDE12345-111-222.idw"
sArray = Split(sName, "-") 'split string using dash
sPrefix = sArray(0) 'get first string in array

'assemble string using only letters in string
Dim LeffterPrefix As New System.Text.StringBuilder
For Each chr As Char In sPrefix
	If Char.IsLetter(Chr) Then
		LeffterPrefix.Append(Chr)
	End If
Next

'convert stringbuilder to string
sPrefix = LeffterPrefix.ToString

MsgBox(sPrefix,, sName)

 

Message 5 of 5
BeKirra
in reply to: Curtis_Waguespack

Thanks to @Andrii_Humeniuk 

I insert your 2nd code to mine as a module. but it doesn't work.

The message is about the "Public sub" function.

It may be caused by the variable name conflict.

I need to dig into it.

 

It works when saving your code as an file.

 

Also thanks to @Curtis_Waguespack 

Your code works straightforward.

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report