Jump to content

How to read the value of a field (linked to databank) of a symbol

Recommended Posts


I am kind of new on Python but not on Vectorworks.


I have a custom symbol that contains 2 text labels: one contains a number like "2,43", the other is always the same text not attached to the database.


I need to get read that "2,43"  


and later do the contrary: be able to write into the field in the symbol another number.


some ideas?


Edited by avictorgm

Share this post

Link to post

Your easiest approach is to link the text to a record field (see the help guide for Link Text to Record).  Then, you can write a simple script using vs.SetRField and vs.GetRField to write and read the data.

Share this post

Link to post

Thanks for the answer,


Yes, it´s already done:

I have a group of symbols already linked between the database and the field Deckenlast.


I have found this on the web from Makro, but gave me back "0", "0" and   " ", " " 


Some help?


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

import vs

hpio = vs.FSActLayer().                                                # this MUST give back the first element of the active layer, BUT I think is NOT. 
hrecdef = vs.GetParametricRecord(hpio).  
recname = vs.GetName(hrecdef)  # Name of PIO in InfoPalette
hrec = vs.GetObject(recname)
fld = vs.GetFldName(hrec, 10).         #. I AM NOT SURE ABOUT THIS 10   

vs.AlrtDialog(vs.GetTypeN(hrecdef))  # 48. answer "0"
vs.AlrtDialog(vs.GetTypeN(hrec))  # 47. answer "0"


vs.AlrtDialog('Recordname:' + recname).   #. answer " "
vs.AlrtDialog('Default:' + vs.GetRField(hrec, recname, fld)).  #. answer " "

# ©MaKro - June 2018 😉


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

read symbol.png

Vectorscript Symbol read.vwx

Share this post

Link to post

The example you have is for a plug-in object.  If you're just dealing with linked-record symbols, the script can be a little simpler.


# This gets a "handle" — a runtime object ID — to the first selected object on the active layer.

hObject = vs.FSActLayer


You mentioned a group of symbols — that makes this a little more difficult, as you need to get a handle to the symbols in your first selected object.  You can either get the first object in the group with vs.FInGroup(hObject) and then iterate through the group, use one of the ForEachObject routines to iterate through every object meeting your specifications, or use the "waldo" technique (there should be some posts in the archive on this) to find your place in the document.  If you don't mean a literal group of symbols, then cary on.


# Get the value of the field.  You didn't mention the name of the record, so there is a placeholder

fieldDataS =  vs.GetRField( hObject, YOUR_RECORD_NAME, 'Deckenlast' )


# This always returns a string, so you need to convert it to a number 

ok, fieldData = vs.ValidNumStr( fieldDataS )

if not ok

     fieldData = 0


ValidNumStr deals well with units and separator preferences, so is going to be the most robust option versus vs.Str2Num or eval().  You may want to write your own function .

def Num2Str( x )

    ok, n = vs.ValisNumStr( x )

    if not ok:

        n = 0

    return n


vs.SetRfield also requires a formatted string argument — use vs.Str2NumF for this

Share this post

Link to post

@JBenghiat Joshua,  Can you please also comments on the idea of not using the actual parameter records in the dialog box and rather copying the original value into a variable to use in the dialog box and then writing the value back to the parameter record after the OK button is clicked.


I seem to remember that this was considered best practice, but don't have time to find the appropriate threads right now.

Share this post

Link to post

Do you mean for AlrtDialog?  You should be fine entering any data here, and in fact the arguments don't need to be strings, like Message() in VS.


Or are you thinking of the fact that PParamName doesn't update after SetRField( ParamName )?  As we're dealing with symbols and records, that doesn't even apply here.

Share this post

Link to post

At the end


I GOT IT!!!!


Took me a little, but after this a whole world of possibilities has opened to me!

import vs
#Vistor Garzon 2020 based on the work of
# ©MaKro - June 2018 ;-)

H1 = vs.FSActLayer()
H2 = vs.ActSymDef(H1)

recname = vs.GetName(H2)  # Name of PIO in InfoPalette
Rec_Name = vs.GetObject(recname) 
fld = vs.GetRField(H1,'loads-roof','Deckenlast')

##### vs.GetRField(h,'DatabankName','FieldName')




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...