Jump to content
Developer Wiki and Function Reference Links Read more... ×
relume

How to get a list of databases and fields

Recommended Posts

Hello

 

I would like to create a custom dialog where  I can select in a pulldown-menu a list of all databases in the actual document. In a second pulldown-menu I woud like to show the corresponding database-fields. What I am missing in the vs function references are the appropriate vs functions to get/retrieve those lists. Do I have missed or overseen something?

 

many thanks in advance.

Share this post


Link to post

I do not think there is a direct way to extract those lists. You'll have to query each row in each WS to see if it is a database row and build a list from that.

 

Start with IsWSDatabaseRow(), and loop through your WS rows to build your list.

 

Since Python has some phenomenal list handling capabilities, you might consider writing your script with Python. I'm sure you can do the same in Pascal, but you'll have to code many things that Python already has built In. 

 

If you need further insight, wait for Pat Stanford's reply. He speaks Worksheet fluently.  :-)

 

Raymond

Share this post


Link to post

Hello Raymond

 

Thank you very much for your answer.

 

Yes I am scripting in python, but I have to rely on vs.functions in order to access VW information/data.

 

I do not use worksheets and in this sens I would like only to obtain a list of all databases (not the record instances) that are present in the VW document in order I can generate a generic dialog/script for which the user can select the appropriate database and database-field to operate on (in this case to label or rotate objects arrcording to an database-field value selected by the user at script runtime).

 

best regards

 

 

Share this post


Link to post

I assume by database, you mean record format.

 

Use NumRecords() and GetRecord():

http://developer.vectorworks.net/index.php/VS:NumRecords

http://developer.vectorworks.net/index.php/VS:GetRecord

 

Passing a nil handle will give you records attached to the entire document as opposed to a specific object.

 

When filling the dialog, you will need to check if the record is hidden and if it is a plug-in format if you want to filter those out.

 

-Josh

Share this post


Link to post

Hello Josh

 

Thank you very much - your tip did it. Although it is some bit strange that VectorWorks does not document this special case with the nil handle to access the databases/records attached to the document itself.

 

The following python script snippet shows how it works. Maybe it helps others ...

 

 

import vs

vHandle = ""
vRecordsNum = vs.NumRecords(vHandle)
vs.AlrtDialog("Databases : " + str(vRecordsNum))

for vRecordID in range(1, vRecordsNum+1):
	vRecordHandle = vs.GetRecord(vHandle, vRecordID)
	vRecordName = vs.GetName(vRecordHandle)
	vMessage = "Database : " + str(vRecordID) + " : " + vRecordName + " : " +str(vRecordHandle)
	vs.AlrtDialog(vMessage)
	
	vFieldsNum = vs.NumFields(vRecordHandle)
	vFieldsName = vRecordName + " : "	
	for vFieldID in range(1, vFieldsNum+1):
		vFieldsName = vFieldsName + vs.GetFldName(vRecordHandle, vFieldID) + ", "
	vs.AlrtDialog(vFieldsName)
	

 

Share this post


Link to post

Hello

 

I try to clone/merge databases (record format) by python scripting. So far I can copy database definitions by vs.GetFldName, vs.GetFldType, vs.GetFldFlag but I have not seen any possibility to get the default field value (fieldValue), that can be set by vs.NewField(recName, fieldName, fieldValue, fType, fFlag). Is there any known workaround to get this default field value?

 

Many thanks in advance,

 

 

Share this post


Link to post

Not on a machine where I can access VW right now, but I seem to remember that if you pass the GetField command either a Nil handle or a handle to the record definition then you get the default values back.

Share this post


Link to post

Hello Pat

 

Thank you very much for answering.

 

I had a flawed reasoning so the command vs.GetRField(object_handle, record_name, field_name) works correct, when passing a record handle to it. Although is somewhat tautologous as in this way a handle to the record and the name to the same record has to be given.

 

So the code would be by referencing the code snippet above:

 

import vs

vHandle = ""
vRecordsNum = vs.NumRecords(vHandle)
vs.AlrtDialog("Databases : " + str(vRecordsNum))

for vRecordID in range(1, vRecordsNum+1):
	vRecordHandle = vs.GetRecord(vHandle, vRecordID)
	vRecordName = vs.GetName(vRecordHandle)
	
    vFieldsNum = vs.NumFields(vRecordHandle)
    for vFieldID in range(1, vFieldsNum+1):
		vFieldName = vs.GetFldName(vRecordHandle, vFieldID)
		vFieldType = vs.GetFldType(vRecordHandle, vFieldID)
		vFieldFlag = vs.GetFldFlag(vRecordHandle, vFieldID)
		vFieldValue = vs.GetRField(vRecordHandle, vRecordName, vFieldName)

		vMessage = "Record : " + vRecordName + " Field : " + str(vFieldID) + " : " + vFieldName + " : " + str(vFieldType) + " : " + str(vFieldFlag) + " : " + vFieldValue
		vs.AlrtDialog(vMessage)
    

best regards,

 

André

 

 

Edited by relume

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

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.

×