Jump to content

Easy Text with color SOLVED!!

Recommended Posts

import vs
X1 = -3000
Y1 = -1500
vs.MoveTo(X1,Y1+18.5) #Move the pointer to
vs.PenSize(10) #outside line of the box

def Texto():

    vs.TextJust(1) #Left    1, Center    2, Right    3
    vs.TextVerticalAlign(3) #Leading / space,     Constant Single space    2 ,1 1/2     3 , Double space    4
    #colorIndex = vs.RGBToColorIndex(1, 45, 23)
    #vs.TextBack(colorIndex) # using Color Index values
#vs.OpacityN(100, 100) #vs.OpacityN(fillOpacity symbol include, penOpacity)
#      1 = 0,03
#    X = 0,025 * X
#   8 = 0,20
#    24 = 0,6
    vs.PenPat(1) # Change for the document
    vs.FillBack(7) # Change background color for the document but not of the text
    vs.PenFore(120,0,0) #Change text color of fixed text to Purple 
    #vs.FillFore(0,0,255) # Blue
h = vs.CreateText(str("Motor ") + str(X1) + str(", ") + str(Y1))
#    -1 = linienart
#    0 = linea invisible o vacia / Leer
#    1 = solid
#    2 = ?
#     3 = muster / estampado
#    4 =  ?
#    5 = ?

# 0 = empty
# 1 = solid
# 2 = 
# x = count number in the table of examples
# 21 = small squares


I have tried many options to change the attributes of  the static text to purple text and back color red.

I got half, the text color.


I can even change the color of the background of the document.


But somehow the pattern of the background stays in empty option for the text.


What small line of text am I missing?

Edited by avictorgm

Share this post

Link to post

@avictorgm ,

   After a light investigation, it appears that "vs.CreateText()" does not use the document FILL PATTERN, nor does, "vs.CreateText()" return a handle. You will have to set the FILL attribute after you create the text.


So, change:

h = vs.CreateText(str("Motor ") + str(X1) + str(", ") + str(Y1))


vs.CreateText(str("Motor ") + str(X1) + str(", ") + str(Y1))


Then use:

h = vs.LNewObj()   # if you want to save the handle to the text object
vs.SetFPat(h, 1)


Or use:

vs.SetFPat(vs.LNewObj(), 1)   # if you don't need to save the handle to the text object


Also, all calls using color values use LONGINTS and need to be in the 0-65535. Multiply color values in the 0-255 range by 257 to convert them to the LONGINT range.


Lastly, you need to pass the color values as a TUPLE, and not three Longint values.


    vs.PenBack((0, 65535, 0))    # GREEN





Share this post

Link to post

@MullinRJ    ⬅️ GENIUS

Thank you so much.

You just save my day!

vs.CreateText(str("Motor ") + str(X1) + str(", ") + str(Y1))
h = vs.LNewObj()   # if you want to save the handle to the text object
vs.SetFPat(h, 1)
vs.PenBack((0, 36535, 0)) #RED


Share this post

Link to post

If I use   -->  vs.FillBack(4) #number of color on the list of vectorworks = Blue

before this      vs.CreateText(...


works perfect


Thank you again @MullinRJ

Share this post

Link to post

You're very welcome. 


A word of caution; using color calls like "vs.FillBack(4)" with a single argument that represents a palette position may produce unexpected results: in different files, on different systems, or after VW software updates, as palette definitions may vary under these conditions. Using these calls with three explicit color values should always produce the repeatable results.


All the best,


  • Like 1

Share this post

Link to post
On 11/15/2018 at 2:13 AM, MullinRJ said:

... it appears that "vs.CreateText()" does not use the document FILL PATTERN, ...


Hi @avictorgm , when I wrote my earlier replies, I was not at my best. I completely forgot about the VW Preference "Create text without fill". The Python call "vs.CreateText()" will create text with the document fill color and pattern IF the "Create text without fill" PREF is disabled, but if the preference is set, then the text background fill color and pattern are ignored, as if the  document fill pattern were set to NONE. So, you could do as I suggested above, and force the fill after creating the text, OR, you could toggle the preference OFF before creating your text, and restore its setting after your text is created.


Something like this:

CreateTextWOFillPref = vs.GetPref(8)		# save pref setting (boolean)
vs.SetPref(8, False)				# disable pref setting
vs.CreateText(str("Motor ") + str(X1) + str(", ") + str(Y1))
vs.SetPref(8, CreateTextWOFillPref)		# restore pref setting

This code snippet will create TEXT using the document fill color and pattern and ignore the VW preference to "Create text without fill".


If your code is working as you like it, there is absolutely no need to change anything. I am just trying to provide a more comprehensive answer.


All the best,





  • Like 1

Share this post

Link to post
8 hours ago, avictorgm said:

So, whatever I do with the script, there´s no difference in the settings


Correct. The first approach we discussed ignores the VW Preference entirely and forces a Fill Color and Pattern after the text is created. The second approach changes the preference to allow the current document Fill attribute to be applied when the text is created, then restores the preference to its original state. So either way you go, that VW Preference remains unchanged after the script has run.



Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114


© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

  • Create New...