Control the color of text with i-Logic

Control the color of text with i-Logic

Guthery1
Enthusiast Enthusiast
381 Views
3 Replies
Message 1 of 4

Control the color of text with i-Logic

Guthery1
Enthusiast
Enthusiast

Good morning/evening,

 

I'm trying to create a piece of text on a drawing with i-Logic.  I have functional code that lets me create the text, set the text height and even locate the text on the drawing where I want it to be, but I can't find how to update the color.  Here is my code so far:

 

oSheet = ThisDoc.Document.Sheets(1)
oGenNotes = oSheet.DrawingNotes.GeneralNotes
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Z1 = vbNewLine

sText = "JUST" & Z1 & "AN" & Z1 & "EXAMPLE"
sFormattedText = "<StyleOverride FontSize = '4'>" & sText & "</StyleOverride>"
oGenNotes.AddFitted(oTG.CreatePoint2d(25, 30), sFormattedText)

 

0 Likes
382 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @Guthery1.  First of all, there is no way to specify color of text within the 'FormattedText' portion of the code.  We can modify Font, Font Size, Bold, Italic, Underline, & Strikethrough with FormattedText though.  Second, you have not declared a variable to capture the new GeneralNote object that your code is creating with the GeneralNotes.AddFitted method.  If you had declared a variable for holding a GeneralNote, then set the value of that variable with that GeneralNotes.AddFitted method, then you could have modified the color of the text after it was created, using its GeneralNote.Color property.  And, the Color object is a 'transient' object (just used for temporarily transferring organized data), so you can create a new one from the TransientObjects object, using its TransientObjects.CreateColor method.  You can find the TransientObjects right under the main application (Application.TransientObjects ).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Guthery1
Enthusiast
Enthusiast

I'm going to need to try this out. I haven't used the GeneralNote functions because I didn't need too.  The original code is a bit old and needs to be updated for increased functionality.  Unfortunately, you never know what you need it to do until you need it to do something new.  I'll get back to this later this week.  Thanks.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

OK.  Here is a couple of code examples you can play around with in the mean time that may help.

This example creates a new GeneralNote on the active sheet of the active drawing, then changes its color to red.  It also shows how you can use the XML tag "<Br/>" for a line break within the text.

Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
If oDDoc Is Nothing Then
	MsgBox("iLogic rule '" & iLogicVb.RuleName & "' was aborted - no DrawingDocument found.", vbCritical, "iLogic")
	Return
End If
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oGNotes As Inventor.GeneralNotes = oSheet.DrawingNotes.GeneralNotes
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oNewGNote As Inventor.GeneralNote = Nothing
Dim oPoint As Point2d = oTG.CreatePoint2d(4, 5)
Dim sFText As String = "Some<Br/>Example<Br/>Text"
oNewGNote = oGNotes.AddFitted(oPoint, sFText)
oNewGNote.Color = oTO.CreateColor(255, 0, 0) 'red

 This example allows you to either manually pre-select or pick (when the rule runs) an existing note in your drawing, then writes its FormattedText to the iLogic Log window for you, so you can review how it is currently formatted.

Dim oPickedNote As DrawingNote = Nothing
Dim oSS As Inventor.SelectSet = ThisDoc.Document.SelectSet
If oSS.Count > 0 AndAlso (TypeOf oSS.Item(1) Is DrawingNote) Then
	oPickedNote = oSS.Item(1)
Else
	oPickedNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Pick a drawing note.")
End If
If oPickedNote Is Nothing Then Return
Logger.Info(vbCrLf & oPickedNote.FormattedText)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes