- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Control the color of text with i-Logic
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)