Reference to Sheet Property Sheet Number

Reference to Sheet Property Sheet Number

j.pavlicek
Collaborator Collaborator
404 Views
4 Replies
Message 1 of 5

Reference to Sheet Property Sheet Number

j.pavlicek
Collaborator
Collaborator

Is there way how to reference Sheet property Sheet Number which is available as <Sheet Number> in Text Editor?

jpavlicek_0-1651230462046.png

 

Or is then only way to iterate over items in Sheets Object and test each Sheet for value in ExcludeFromCount property?

 

Thank you for your advice.



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
405 Views
4 Replies
Replies (4)
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @j.pavlicek.  The sheet number is always at the end of the sheet name, even if you move the order of the sheets around or rename them, that integer at the end of the sheet name stays in descending order.  So technically you could just use a simple String.Split tool and get the last sub string, after the ":" character.  That will always be the sheet number.  Of course this assumes your sheet names don't have more than one ":" character in them.

oDDoc = ThisDrawing.Document
oSheet = oDDoc.ActiveSheet
oSheetNum = oSheet.Name.Split(":")(1)
MsgBox("oSheetNum = " & oSheetNum,,"")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Actually, there is a way to extract the 'visible' value of that SheetNumber derived property, but it is not as easy as you are likely hoping for.  Basically if your title block contains a single text box that only contains that one derived property, then we can search within the sketch of the title block definition' on each sheet, until we find the TextBox that contains that property.  Then, even though neither the TextBox.Text, nor the TextBox.FormattedText will give you that numerical value you are looking for, you can still get it by using a method from the TitleBlock object called GetResultText, which wants a TextBox as input, and gives you the resulting 'visible' value of that TextBox, after its contents have been computed.  I just tested this on one of my drawings and it works.  But in my TitleBlock, the TextBox is set to display a phrase which includes "Sheet" 'SheetNumber' " OF " 'NumberOfSheets', so the result I get contains the word "SHEET", then the SheetNumber numerical value, then the word " OF ", then the numerical value of NumberOfSheets, so I would have to extract it from that String to get the number I wanted.  But still it has always been the same as the digit after the sheet name.  But I don't do too many fancy things with my drawing sheets like some others might do.

 

By the way...here is the link to the online help page for dealing with FormattedText, and here is the link to the online help page for the Enum that is uses for 'derived properties.  But you could probably just check the TextBox.Text to see if it 'Contains' that "<Sheet number>" text when searching for the TextBox.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Here is a bit of example iLogic code you can use to investigate and play to help you further develop a solution that works the way you want it to.  This was part of a larger project I had to assign attributes to the TextBoxes, once I had positively identified them, to make further processing by other tools later on a bit easier.  It probably wouldn't take too much effort to create a custom Function for extracting the needed data, once you have adapted it to your scenario.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	oASheet = oDDoc.ActiveSheet
	Dim oTB As TitleBlock = Nothing
	Dim oTBDef As TitleBlockDefinition = Nothing
	If oASheet.TitleBlock Is Nothing Then
		Exit Sub 'or Continue For if in a Loop
	Else
		oTB = oASheet.TitleBlock
		oTBDef = oTB.Definition
	End If
	Dim oSketchCopy As DrawingSketch = Nothing
	oTBDef.Edit(oSketchCopy)
	oTBoxs = oSketchCopy.TextBoxes
	If oTBoxs.Count = 0 Then Exit Sub
	For Each oTBox As Inventor.TextBox In oTBoxs
		Dim oResultText As String = ""
		Try
			oResultText = oTB.GetResultText(oTBox)
		Catch
			MsgBox("GetResultText method failed.",,"")
		End Try
		MsgBox("Current TextBox Contents:" & vbCrLf & _
		"TextBox.Text = " & oTBox.Text & vbCrLf & _
		"TextBox.FormattedText = " & oTBox.FormattedText & vbCrLf & _
		"oResultText = " & oResultText,,"")
	Next
	oTBDef.ExitEdit(False) 'False = don't save changes
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes