Support Forum

[Frage] set text color for Text2D [Gelöst]


Hi there!
I need to assign a color to the Text2D element, so when I run my script the text show in a specific color in the drawing.
this is surprisingly lacking in TextProperty.
any aIdea?

Anhänge (1)

Typ: image/jpeg
25-mal heruntergeladen
Größe: 37,70 KiB

Lösung anzeigen Lösung verbergen

There are two nodes for the CommonProperties: NodeFormat and NodeFormatPalette.

Unfortunately, neither of them works with NodeText2D.

But you can expand the NodeText2D with an Input.

Therefore you have to modify NodeText2D.py and NodeText2D.pypsub in directory
C:\ProgramData\Nemetschek\Allplan\2025\Etc\VisualScripts\NodeLib\Classic Library\Layout.

I have done this for you (see Node2DFormat.zip)
With this modified NodeText2D you can create Text with Colors (see text_with_format.png)

Anhänge (3)

Typ: image/png
45-mal heruntergeladen
Größe: 75,64 KiB
Typ: application/zip
121-mal heruntergeladen
Größe: 2,92 KiB
Typ: image/png
42-mal heruntergeladen
Größe: 138,85 KiB
1 - 10 (12)

The Text2D element is a normal ModelElement2d.
That means, it has CommonProperties, where the Color is defined.
In the NodeText2D the current set common properties are used:

    def create_text(self, text, text_prop, ref_point):

        com_prop = AllplanBaseElements.CommonProperties()
        com_prop.GetGlobalProperties()

        location = AllplanGeo.Point2D(ref_point)
        
        return AllplanBasisElements.TextElement(com_prop, text_prop, str(text), location)

If you want to have another one, try to add CommonProperties with some Node.

Or use the color formatting inside the text:
%C{n|text%C} with n...Color-Number and text ... the text with this color.

thanks for the response,

since I need the color to be changed with a pattern (eg. 5 different colors for 5 different text) i cannot use the formatting inside the text.

with CommonProperties i need some more explanation.

is there a way to add color to TextProperty.py or any other way?

There are two nodes for the CommonProperties: NodeFormat and NodeFormatPalette.

Unfortunately, neither of them works with NodeText2D.

But you can expand the NodeText2D with an Input.

Therefore you have to modify NodeText2D.py and NodeText2D.pypsub in directory
C:\ProgramData\Nemetschek\Allplan\2025\Etc\VisualScripts\NodeLib\Classic Library\Layout.

I have done this for you (see Node2DFormat.zip)
With this modified NodeText2D you can create Text with Colors (see text_with_format.png)

Anhänge (3)

Typ: image/png
45-mal heruntergeladen
Größe: 75,64 KiB
Typ: application/zip
121-mal heruntergeladen
Größe: 2,92 KiB
Typ: image/png
42-mal heruntergeladen
Größe: 138,85 KiB

you are amazing

^I have the same problem with FillingPallete, I need the Filling color also change with a list, according to the text color (see first image please). although I cannot connect a list with the desired colors to FirstColor in FillingPallete

Anhänge (1)

Typ: image/jpeg
27-mal heruntergeladen
Größe: 67,52 KiB

I have created a new new NodeSolidFilling2D (derived from NodeFilling2D).
This Node has an input Color instead of FillingProperties.
Together with NodeColorInput you can easily create a solid filling.

The file Std_Visualscripts.zip has to unpack to STD\VisualScripts.

Anhänge (2)

Typ: image/png
18-mal heruntergeladen
Größe: 90,30 KiB
Typ: application/zip
109-mal heruntergeladen
Größe: 3,08 KiB

thanks.
but it seems like it cannot take a list as input paramater.

Anhänge (1)

Typ: image/jpeg
18-mal heruntergeladen
Größe: 122,64 KiB

Try this one, please.

Anhänge (1)

Typ: application/zip
122-mal heruntergeladen
Größe: 849,00 B

its functioning perfectly. thanks again.
is there a way taht run this .pyp I made in the layout mode (not drawing mode) in allplan?

Anhänge (2)

Typ: image/jpeg
13-mal heruntergeladen
Größe: 43,98 KiB
Typ: image/jpeg
13-mal heruntergeladen
Größe: 102,09 KiB
1 - 10 (12)