Changing Text Style when adding text with Ilogic

Changing Text Style when adding text with Ilogic

Thomas.Long
Advocate Advocate
1,441 Views
1 Reply
Message 1 of 2

Changing Text Style when adding text with Ilogic

Thomas.Long
Advocate
Advocate

I have a modified code for adding text to a drawing through ilogic. The only problem is that I want to be able to change text styles with it. That way some notes can be larger when necessary. I can go through and set the text style in the text style manager I think, but for some reason when I tell it to add text it adds it with the standard no matter what style I pass to it.

 

Thank you all in advance and below is the code.

 

'Creates Text at the specified point (using the drawing scale, not view scale)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Function CreateText (oDrawingDoc As DrawingDocument, oText As String, OffsetDistanceX As Double, OffsetDistanceY As Double, Alignment As String, Style As String)


'Declaring Variables
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oSheet As Sheet
	Dim oTG As TransientGeometry
	Dim oPoint1 As Point2d
	Dim TextPoint As Point2d
	Dim TextWidth As Double
	Dim oStylesMgr As DrawingStylesManager
	Dim oTextStyle As TextStyle
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'Setting Text Style
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oStylesMgr = oDrawingDoc.StylesManager
	oTextStyle = oStylesMgr.TextStyles.Item(Style)

'Set the sheet and create the geometry for insertion
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oSheet = oDrawingDoc.Sheets.Item(1)
	oTG = ThisApplication.TransientGeometry

	TextPoint = oTG.CreatePoint2d(OffsetDistanceX, OffsetDistanceY)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	

'Creating category for text
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oGeneralNotes As GeneralNotes
	oGeneralNotes = oSheet.DrawingNotes.GeneralNotes
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	
	
'Creating text
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oGeneralNote As GeneralNote
	oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(5, 5), oText)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'Get the Lengths of the Text
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	TextWidth = oGeneralNote.Width
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


'This will align the text as specified
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	If Alignment = "Left" 
		TextPoint.x = OffsetDistanceX
	Else If Alignment = "Center" 
		TextPoint.x = OffsetDistanceX - TextWidth/2
	Else If Alignment = "Right" 
		TextPoint.x = OffsetDistanceX - TextWidth
	End If
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'This will place the text at the OffsetDistance Vertically
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	TextPoint.y = OffsetDistanceY 
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	
	
'Moving text to specified position
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oGeneralNote.Position = TextPoint
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
End Function
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
0 Likes
1,442 Views
1 Reply
Reply (1)
Message 2 of 2

Thomas.Long
Advocate
Advocate

Apologies, I half fixed it. It is correctly setting the text style to the created note now.

 

However when I use the large text instead of the normal text it doesn't seem to be stretching the width of the enlarged text so the text ends up being multiple lines long. Is it incorrectly getting the text width when I enlarge the text size too much?

 

'Creates Text at the specified point (using the drawing scale, not view scale)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Function CreateText (oDrawingDoc As DrawingDocument, oText As String, OffsetDistanceX As Double, OffsetDistanceY As Double, Alignment As String, Style As String)


'Declaring Variables
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oSheet As Sheet
	Dim oTG As TransientGeometry
	Dim oPoint1 As Point2d
	Dim TextPoint As Point2d
	Dim TextWidth As Double
	Dim oStylesMgr As DrawingStylesManager
	Dim oTextStyle As TextStyle
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'Setting Text Style
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oStylesMgr = oDrawingDoc.StylesManager
	oTextStyle = oStylesMgr.TextStyles.Item(Style)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


'Set the sheet and create the geometry for insertion
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oSheet = oDrawingDoc.Sheets.Item(1)
	oTG = ThisApplication.TransientGeometry

	TextPoint = oTG.CreatePoint2d(OffsetDistanceX, OffsetDistanceY)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	

'Creating category for text
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oGeneralNotes As GeneralNotes
	oGeneralNotes = oSheet.DrawingNotes.GeneralNotes
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	
	
'Creating text
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oGeneralNote As GeneralNote
	oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(5, 5), oText)
	oGeneralNote.TextStyle = oTextStyle
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'Get the Lengths of the Text
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	TextWidth = oGeneralNote.Width
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


'This will align the text as specified
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	If Alignment = "Left" 
		TextPoint.x = OffsetDistanceX
	Else If Alignment = "Center" 
		TextPoint.x = OffsetDistanceX - TextWidth/2
	Else If Alignment = "Right" 
		TextPoint.x = OffsetDistanceX - TextWidth
	End If
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'This will place the text at the OffsetDistance Vertically
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	TextPoint.y = OffsetDistanceY 
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	
	
'Moving text to specified position
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oGeneralNote.Position = TextPoint
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
End Function
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
0 Likes