General Note - Change Color

General Note - Change Color

a81383
Enthusiast Enthusiast
982 Views
3 Replies
Message 1 of 4

General Note - Change Color

a81383
Enthusiast
Enthusiast

Hello,

I'm trying to change the color of my newly created note in the following code. But it will not change,. I've tried numerous separate approaches and it really seems like the code should work but the black text remains.

 

	Dim oDwgDoc As Document = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = oDwgDoc.Sheets.Item(1)
	
	Dim oGeneralNotes As GeneralNotes = oSheet.DrawingNotes.GeneralNotes
	
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	oFontSize1 = 1 * 2.54 '2.54 coverts to inches
	
	oText1 = "OBSOLETE"

	Dim oBorder As Border = oSheet.Border

	Dim oTitleBlock As TitleBlock = oSheet.TitleBlock

	Dim oPlacementPoint1 As Point2d
		xrev2 = oBorder.RangeBox.MinPoint.X + 3
		yrev2 = oBorder.RangeBox.MaxPoint.Y - 1
		oPlacementPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(xrev2, yrev2)
	
	Dim sFormattedText As String = "<StyleOverride FontSize ='" & oFontSize1 & "'>" & oText1 & "</StyleOverride>"
	
	oGeneralNote = oGeneralNotes.AddFitted(oPlacementPoint1, sFormattedText)
	oGeneralNote.Rotation = -0.785398
	
	Dim red As Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'Red
	oGeneralNote.Color = red

 

0 Likes
Accepted solutions (1)
983 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @a81383.  I think that you may simply be missing one minor step in your process.  After you create the new Color object, try setting its property named 'ColorSourceType', which has a ColorSourceTypeEnum type value, to the 'kOverrideColorSource' variation of that Enum.  Then set that Color as the value of the Color property of the GeneralNote

Below is a quickie iLogic rule example I just made to test changing the color of a GeneralNote using its Color property, and it worked just fine for me.  But I am using Inventor 2024 version, and not sure which version you may be using, or if it makes any difference.  There are also other ways to change its color, but this is the most direct way.

Dim oDN As DrawingNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Pick Drawing General Note.")
If oDN Is Nothing OrElse (TypeOf oDN Is Inventor.GeneralNote = False) Then Return
Dim oGN As Inventor.GeneralNote = oDN
Dim oRed As Inventor.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0, 1)
oRed.ColorSourceType = ColorSourceTypeEnum.kOverrideColorSource
oGN.Color = oRed

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor

Another way to change the color of a drawing annotation is to change which 'Style' it is using.  When you do this, you do not want to do it like oObject.Style.Color = oMyColor...instead either have a Style already prepared, or create a new Style, then set that other Style as the value of oObject.Style.  Doing it with oObject.Style.Color will change the Style itself, not just that one object, and changing the Style itself may effect all other annotations in the drawing that are also using that same Style.  In this case, we are talking about a GeneralNote, and it has a property named 'TextStyle' which has a TextStyle object as its value.

Below is an example of doing it that way.

Dim oDN As DrawingNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Pick Drawing General Note.")
If oDN Is Nothing OrElse (TypeOf oDN Is Inventor.GeneralNote = False) Then Return
Dim oGN As Inventor.GeneralNote = oDN
Dim oSheet As Inventor.Sheet = oGN.Parent
Dim oDDoc As DrawingDocument = oSheet.Parent

Dim oOrigStyle As Inventor.TextStyle = oGN.TextStyle
Dim oOtherStyle As Inventor.TextStyle = Nothing
Try
	oOtherStyle = oDDoc.StylesManager.TextStyles.Item("BlueTextStyle")
Catch
	oOtherStyle = oOrigStyle.Copy("BlueTextStyle")
End Try
oOtherStyle.Color = ThisApplication.TransientObjects.CreateColor(0, 0, 255, 1) 'Blue
oGN.TextStyle = oOtherStyle
oSheet.Update

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

a81383
Enthusiast
Enthusiast

@WCrihfield, thank you very much for your responses. I set my oGeneralNote variable " As GeneralNotes" before creating the note itself. So, I would have never thought of setting it as an Inventor.GeneralNote before changing colors, but that's what did it. Out of curiosity I'll take a look at the changing the style as well.

 

Dim oGN As Inventor.GeneralNote = oGeneralNote

 

Thank you again!

0 Likes