Get the position of Autodesk Inventor Drawing title block attributes

Get the position of Autodesk Inventor Drawing title block attributes

Rupali_Abhale
Explorer Explorer
507 Views
4 Replies
Message 1 of 5

Get the position of Autodesk Inventor Drawing title block attributes

Rupali_Abhale
Explorer
Explorer

Hello Team,

I want to create custom note nearby Title block attributes whose values are not as per requirement. Please let us know how to get the position of attributes to place note.

Regards,

Rupali

0 Likes
508 Views
4 Replies
Replies (4)
Message 2 of 5

AlexFielder
Advisor
Advisor

So you want to create a kind of QA process for when properties aren't as expected? It's an interesting idea certainly.

I was curious, so I knocked up this rule:

Sub Main()
	oDocument = ThisApplication.ActiveDocument
	Dim oSheets As Sheets
	Dim oPar As UserParameter

	For i = 1 To oDocument.Sheets.Count
		oDocument.Sheets(i).Activate
		oSheet = oDocument.Sheets(i)
		Dim oTitleBlock As TitleBlock = oDocument.Sheets(i).TitleBlock
		For Each oTextBox As Inventor.TextBox In oTitleBlock.Definition.Sketch.TextBoxes
			If oTextBox.Text <> "" Then
				CompareTextToExpected(oTextBox, oTitleBlock.GetResultText(oTextBox))
			End If
		Next
	Next
End Sub

Public oDocument As DrawingDocument = Nothing
Public oSheet As Sheet = Nothing

Function CompareTextToExpected(byval textBox as Inventor.TextBox, byval textBoxContents as string) as Boolean
	select case textBox.Text
		Case "<TITLE>" :
			if not textBoxContents = "your expected string" then MarkTextBoxContentsAsIncorrect(textBox, "Text doesn't match expected Title")
		case "<PART NUMBER>" :
			if not textBoxContents = "your expected string" then MarkTextBoxContentsAsIncorrect(textBox, "Text doesn't match expected Part Number")
	end select
End Function

Sub MarkTextBoxContentsAsIncorrect(byval textbox as Inventor.TextBox, byval ErrorText as string)
	Call CreateText(textbox.Origin, ErrorText)
End Sub

Sub CreateText (byval textlocation as point2d, byval QAText As String)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim TextPoint As Point2d = oTG.CreatePoint2d(textLocation.X, textlocation.Y)
	
	Dim oGeneralNotes As GeneralNotes
	oGeneralNotes = oSheet.DrawingNotes.GeneralNotes
	
	Dim oGeneralNote As GeneralNote
	oGeneralNote = oGeneralNotes.AddFitted(TextPoint, QAText)
End Sub

You can test this just by creating a new blank drawing from the ISO drawing template.

When you run it you get the following output:

2019-03-08 13_33_46-Autodesk Inventor Professional 2019 - [Drawing1].png

Which proves the code is sound, but the text should be positioned over the title block, whereas the current position matches the position of the textboxes within the titleblock itself:

2019-03-08 13_35_29-Autodesk Inventor Professional 2019 - [Drawing1].png

I believe I can apply a transformation to a point2d to get the correct location so am investigating that now.

🙂

0 Likes
Message 3 of 5

AlexFielder
Advisor
Advisor

That was easy (for once):

Sub Main()
	oDocument = ThisApplication.ActiveDocument
	Dim oSheets As Sheets
	Dim oPar As UserParameter

	For i = 1 To oDocument.Sheets.Count
		oDocument.Sheets(i).Activate
		oSheet = oDocument.Sheets(i)
		oTitleBlock = oDocument.Sheets(i).TitleBlock
		For Each oTextBox As Inventor.TextBox In oTitleBlock.Definition.Sketch.TextBoxes
			If oTextBox.Text <> "" Then
				CompareTextToExpected(oTextBox, oTitleBlock.GetResultText(oTextBox))
			End If
		Next
	Next
End Sub

Public oDocument As DrawingDocument = Nothing
Public oSheet As Sheet = Nothing
Public oTitleBlock As TitleBlock = Nothing

Function CompareTextToExpected(byval textBox as Inventor.TextBox, byval textBoxContents as string) as Boolean
	select case textBox.Text
		Case "<TITLE>" :
			if not textBoxContents = "your expected string" then MarkTextBoxContentsAsIncorrect(textBox, "Text doesn't match expected Title")
		case "<PART NUMBER>" :
			if not textBoxContents = "your expected string" then MarkTextBoxContentsAsIncorrect(textBox, "Text doesn't match expected Part Number")
	end select
End Function

Sub MarkTextBoxContentsAsIncorrect(byval textbox as Inventor.TextBox, byval ErrorText as string)
	Call CreateText(textbox.Origin, ErrorText)
End Sub

Sub CreateText(ByVal textlocation As Point2d, ByVal QAText As String)
	Call textlocation.transformby(oTitleBlock.Transformation)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim TextPoint As Point2d = oTG.CreatePoint2d(textLocation.X, textlocation.Y)
	
	Dim oGeneralNotes As GeneralNotes
	oGeneralNotes = oSheet.DrawingNotes.GeneralNotes
	
	Dim oGeneralNote As GeneralNote
	oGeneralNote = oGeneralNotes.AddFitted(TextPoint, QAText)
End Sub

🙂

0 Likes
Message 4 of 5

Rupali_Abhale
Explorer
Explorer
Hello AlexFielder,
Thanks for your valuable reply and appreciate your efforts. As per code we can get the origin of text box where we are adding error code using general note. It will add error note at the centre of textbox which will override the textbox content may not be proper visible to end user so to avoid this can we place text outside of textbox but neared to it so that end user can map error note to that textbox content only.
Can you please provide best solution for same?
0 Likes
Message 5 of 5

AlexFielder
Advisor
Advisor

My second post provided a solution that puts text in the same location as any textbox decreed in-code.

 

Anything more than that is getting to be a proprietary (£££) solution. If that's what you would like then please pm me.

 

If you attempt to use what I have shared, and get stuck then I recommend you share your results/error messages then I and others here will I'm sure help where/if we can.

0 Likes