FIeld text is stopping title block loading into drawing

FIeld text is stopping title block loading into drawing

Chris.Truelove
Contributor Contributor
1,100 Views
4 Replies
Message 1 of 5

FIeld text is stopping title block loading into drawing

Chris.Truelove
Contributor
Contributor

Hi,

I hope someone can help with this.

I have setup a number of custom borders for the company that I am now working for ranging through A4 - A0 also with A4 portrait and A3 portrait. I am using three different title blocks depending on which sheet size is required. I have used ilogic in conjunction with a form to place the sheet size, border and title block as required. This has all been working well until I was also asked to an extra text box if information that is specific to each sheet in each drawing. The drawings can have up to 20+ sheets and cover elevation drawings to fabrication details. 

I have tried using iProperties but this is limited in that they do not lend them selves to adding many different entries for one drawing. I am currently playing with filed text but this only seems to work if the title block is selected directly for the model tree to the side of the page and causes the title block to not load and produces an error;

 

Error in rule: A3_Border, in document: Standard.idw

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

when using ilogic to place the title block.

from what I have seem after searching the site I do not appear to be alone with this problem but the responces that have been put forward either just don't run or don't allow me to edit the text. none of them have been able to remove the error shown above.

 

Can anyone help.

 

Chris

0 Likes
1,101 Views
4 Replies
Replies (4)
Message 2 of 5

Chris.Truelove
Contributor
Contributor

Further to my request for help above.

I have taken a different tack with this problem and have gone down a root of adding a sketch to each drawing sheet that places a test box in the correct position dependant on the title block and sheet size that is being used.

The code also counts the number of characters used and tells you if you have exceeded a set amount. I cannot find a way to control the size of the text box so that the text can be made to use two lines if required. The code is listed below and it is triggered using a form.

 

I have a couple of questions;

1; I would like to know if there is a way to overwrite the text that has been place in the text box rather than delete the sketch and recreate a new one?

2; Can ilogic be used to control the size / shape of the text box?

 

Public Sub Main SketchTextAdd()
    ' a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
		oDrawDoc = ThisApplication.ActiveDocument
    
    ' Create a new sketch on the active sheet.
    Dim oSketch As DrawingSketch
		oSketch = oDrawDoc.ActiveSheet.Sketches.Add
    
    ' Open the sketch for edit so the text boxes can be created.
    ' This is only required for drawing sketches, not part.
    oSketch.Edit
    
	'Identify border type
	Dim oBorder = ActiveSheet.Border
	
    Dim oTG As TransientGeometry
    	oTG = ThisApplication.TransientGeometry
	
    ' Create text with simple string as input.  Since this doesn't use
    ' any text overrides, it will default to the active text style.
	
	Dim sText As String
    sText = InputBox("Enter new Title Text", "Secondary Title ", "")
	iProperties.Value("Custom", "Second Title "& ActiveSheet.Name) = sText
	
	
   	Dim oTextBox As Inventor.TextBox
		If oBorder = "Altrad_MB_A3" Then
	    	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22.7, 2.75), sText)
		Else If oBorder = "Altrad_MB_A4" Then
	    	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(10.39, 2.7425), sText)
		Else If oBorder = "Altrad_MB_A4_P" Then
	    	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(11.15, 6.195), sText)
		Else If oBorder = "Altrad_MB_A3_P" Then
 		   	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(10.39, 2.745), sText)
		Else If oBorder = "Altrad_MB_A2" Then
	    	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(48.35, 8.695), sText)
		Else If oBorder = "Altrad_MB_A1" Then
 		   	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(73.05, 8.695), sText)
		Else If oBorder = "Altrad_MB_A0" Then
	    	oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(107.85, 8.695), sText)
 	   End If
		currentLength = Len(sText)
		If currentLength > 60 Then 
			MessageBox.Show("The title currently exceeds the 60 character limit." & vbLf & _sText & "Total count = " & currentLength & " characters", "iLogic")
		End If
    oSketch.ExitEdit
End Sub

 

I hope someone can help with this. 

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

As for your first question...the answer is yes.  When you get the TextBox object, it has a 'Text' property you can use, and a 'FormattedText' property that you can use.  Using the TextBox property is fairly straight forward.  It is a simple means to get, edit, or set what text is shown within the TextBox.  However, using the FormattedText property is not so straight forward.  This is expecting a 'fully formatted' string, which uses XML tags to set specifications.  Here is a link that will help slightly with that.

 

As for your second question...the answer is yes.  But it's likely not as simple as you're hoping for.  If you create the TextBox using "TexBoxes.AddByRectangle()" you can control the size of the rectangle that defines the text box.  But that doesn't guarantee the text inside that textbox will be either tightly fitted to that textbox or that it won't go outside the bounds of the textbox.  On the other hand, if you use the "TexBoxes.AddFitted()" as you did, it will ensure the text inside the texbot stays fitted to the texbox, but then the texbox will also grow or shrink with the size of the text within.

 

You can control the size of the text somewhat by specifying the TextStyle and/or how you specify things like StyleOverride etc within the FormattedText property.  And the TextBox object does have the "FittedTextHeight" and "FittedTextWidth" properties which you can check, before/after edits and compare with the size of the TextBox, to see if the text within is exceeding the size of the textbox, too.  There are also "Origin", "Origin Sketch Point", "Height", & "Width" properties for the TextBox.  The "Origin", "Height", & "Width" properties are Read/Write, meaning you can set them.  There is also a "BoundaryGeometry" property, which is ReadOnly, but could probably be used to capture the geometry, so it can be manipulated by other means.  You just can't create a rectangle, then set that rectangle as the value of that property, due to it's being ReadOnly.

 

Controlling the size of a string (or paragraph) of text, when the contents of that text may vary, can be really complex, due to the nature of many of the fonts used.  There are some fonts that are much predictably sized than others.  There are several aspects to fonts, which can complicate trying to control its 'actual size'.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

Chris.Truelove
Contributor
Contributor

Hi Thanks for your reply,

I'm not the worlds best programmer as you may well have noticed. Could you please show some examples of code that would do what you are suggesting?

 

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

For reference...

This conversation is continued in this other post:

https://forums.autodesk.com/t5/inventor-customization/having-trouble-changing-text-font-size-in-a-dr... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes