Trim last two characters in sheet Name

Trim last two characters in sheet Name

CCarreiras
Mentor Mentor
1,273 Views
4 Replies
Message 1 of 5

Trim last two characters in sheet Name

CCarreiras
Mentor
Mentor

Hi!

WIth this code, i get the drawing Sheet Name and place it in the titleblock.

 

This works very well, but I would like to tweak a little bit:

 

In the Titleblock, now appears something like:

"WhateverSheetName_A_:1"

"WhateverSheetName_B_:2"

:1, :2, :3 and so on are the automatic sheets numbering

But i'd like to remove it and show the sheetnames in the titleblock as:

"WhateverSheetName_A_"

"WhateverSheetName_B_"

Basically The goal is, to remove the last two digits from the Sheet Name


I created a new Variable: SheetNTrim as a string and tried to trim the last two digits. I tryied with Remove function, but i got syntax issues, can someone help me on this?

Thanks.

 

SyntaxEditor Code Snippet

Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("My_TitleBlock") Dim oSheet As Sheet Dim oSheets As Sheets = oDrawDoc.Sheets For Each oSheet In oSheets ' Check to see if the sheet already has a title block and delete it if it does. If Not oSheet.TitleBlock Is Nothing Then oSheet.TitleBlock.Delete() End If ' This title block definition contains one prompted string input. An array ' must be input that contains the strings for the prompted strings. Dim sPromptStrings(0) As String 'start counting by 0 !!! sPromptStrings(0) = oSheet.Name ' Add an instance of the title block definition to the sheet. Dim oTitleBlock As TitleBlock
oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings) Next

 

 

 

CCarreiras

EESignature

0 Likes
Accepted solutions (2)
1,274 Views
4 Replies
Replies (4)
Message 2 of 5

CCarreiras
Mentor
Mentor
Accepted solution

Ok, i finnally get it:

 

SyntaxEditor Code Snippet

oSheet.Name.Remove(len(oSheet.Name)-2)

Thanks. 

CCarreiras

EESignature

0 Likes
Message 3 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @CCarreiras,

 

Just a note that if your Sheet number exceeds 9, then the solution you posted will give you an unexpected result.

Example:

"WhateverSheetName_A_:10"

 

would give a result such as:

"WhateverSheetName_A_0"

 

This version will handle that situation, by looking for the colon in the sheet name.

 

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

 

Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim oTitleBlockDef As TitleBlockDefinition

 oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("My_TitleBlock")

Dim oSheet As Sheet
Dim oSheets As Sheets = oDrawDoc.Sheets

For Each oSheet In oSheets
	' Check to see if the sheet already has a title block and delete it if it does.
	If Not oSheet.TitleBlock Is Nothing Then
	oSheet.TitleBlock.Delete()
	End If
	
	' This title block definition contains one prompted string input. An array
	' must be input that contains the strings for the prompted strings.
	oName = oSheet.Name
	oChrPosition = oName.LastindexOf(":") 'index starts counting by 0
	
	Dim sPromptStrings(0) As String 'start counting by 0 !!!
	sPromptStrings(0) = Left(oName,oChrPosition)	
	
	' Add an instance of the title block definition to the sheet.
	Dim oTitleBlock As TitleBlock

	oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
Next

 

EESignature

0 Likes
Message 4 of 5

CCarreiras
Mentor
Mentor
Accepted solution

HI @Curtis_Waguespack

 

Yes, i figure it out at the end, and i used a similar approach:

is more "clean"...dont need to create new variables.

 

SyntaxEditor Code Snippet

sPromptStrings(0) = Left(oSheet.Name,(InStrRev(oSheet.Name, ":", - 1)-1))

 I guess it will work well, what do you think?

Thank you for your help.

CCarreiras

EESignature

Message 5 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @CCarreiras

 

Yep, using InStrRev to locate the colon character will work as well.

 

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

 

EESignature

0 Likes