Jump to content
Vsevolod

Get data from a Worksheet with Python script?

Recommended Posts

I've been trying to get data from a worksheet by Python script. Here is the basic code:

 

def FindTable():
    hLayer = vs.GetParent( vs.FObject() )
    vs.EnableDrawingWorksheetPalette(True, None)

    while hLayer != None:
        h = vs.FInLayer( hLayer )
        while h != None:
            # worksheet?
            if vs.GetTypeN(h) == 56:
                rows, cols = vs.GetWSRowColumnCount(h)
                cellnum = vs.GetCellStr(h,1,1)
                vs.AlrtDialog( vs.Concat('Cell 1 ',cellnum,' Name: ',vs.GetName(h),' visible: ',vs.AreWorksheetGridLinesVisible(h),' rows=', rows, ' cols=', cols) )
            
            h = vs.NextObj( h )
        hLayer = vs.NextLayer( hLayer )


    return 0

 

It doesn't work and returns 0 rows and columns. I guess "Worksheet container" type is not good and these APIs  don't work but the cycle returns only handle with type 56 even without any 'if' condition.

Maybe "Worksheet" type is what I'm looking for?  types and IDs  But how can I obtain it?

Share this post


Link to post

 

Vsevolod,

The object on the drawing layer is a WORKSHEET IMAGE (type 56). You need a handle to the WORKSHEET (type 18), which is a resource.

 

Add this line:

hWS = vs.GetWSFromImage(h)        # handle to WS resource

and use hWS in your subsequent calls. 

def FindTable():
	hLayer = vs.GetParent( vs.FObject() )
	vs.EnableDrawingWorksheetPalette(True, None)
	while hLayer != None:
		h = vs.FInLayer( hLayer )
		while h != None:
			# worksheet?
			if vs.GetTypeN(h) == 56:
				hWS = vs.GetWSFromImage(h)		# handle to WS resource
				rows, cols = vs.GetWSRowColumnCount(hWS)
				cellnum = vs.GetCellStr(hWS,1,1)
				vs.AlrtDialog( vs.Concat('Cell 1 ',cellnum,' Name: ',vs.GetName(h),' visible: ',vs.AreWorksheetGridLinesVisible(hWS),' rows=', rows, ' cols=', cols) )
            
			h = vs.NextObj( h )
		hLayer = vs.NextLayer( hLayer )
	return 0

 

Raymond

Edited by MullinRJ
  • Like 1

Share this post


Link to post

Yes, I've checked your code and it runs exactly as you said and what I'm searching for!

Thanks, Raymond!

Share this post


Link to post

You're welcome. I missed a handle...   vs.GetName(h) returns "none", if you change it to vs.GetName(hWS) you'll get "Worksheet-1" or whatever you named your worksheet.

 

Welcome to the VW programming forum.

 

Raymond

  • Like 1

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.

×