Jump to content
Developer Wiki and Function Reference Links ×

How to get a list of databases and fields


relume

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.

Link to comment

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

Link to comment

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

 

 

  • Like 1
Link to comment

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

Link to comment

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)
	

 

Link to comment
  • 1 year later...

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,

 

 

Link to comment

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
Link to comment

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.

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

×
×
  • Create New...