Jump to content

Recommended Posts

I figured out how to scale a viewport, now I want to position it correctly.

 

The following works:

        vs.SetObjectVariableReal(vpHandle, 1003, 32) #scale

 

The following does not work:
        vs.SetObjectVariableReal(vpHandle, 1024, 0) # x
        vs.SetObjectVariableReal(vpHandle, 1025, 0) # y

 

I get the following error message:

Error: SetObjectVariable failed with constant 1024. This typically due to the operation being not supported for the passed object handle.

 

As far as I can tell in the documentation, setting the x and y should be the same as setting the scale. I can't seem to figure out why one works and the other doesn't.

 

Thanks

 

Martin

Share this post


Link to post

Martin,

   ObjVars 1024 & 1025 are marked as READ-ONLY. 

 

   Try getting the Bounding Box to find out where it is, then use HMove() to move it to where you want. The difference between the desired point and the existing point is the amount you need to move it.

 

HTH,

Raymond

Share this post


Link to post

Hello

 

perhaps this snippet from a larger script may help:

 

# -- create viewport : move viewport object to page center
vs.Layer(vLayerViewPort_name) # selects layer with ViewPort object

vViewCenter_x, vViewCenter_y = vs.GetOrigin() # this works as long SheetLayer origin was not altered
vViewPort_Rect_center_x, vViewPort_Rect_center_y = vs.HCenter(vViewPort_Object_handle)
vViewCenter_x = vViewCenter_x * -1
vViewCenter_y = vViewCenter_y * -1
vDifference_x = (vViewCenter_x-vViewPort_Rect_center_x)
vDifference_y = (vViewCenter_y-vViewPort_Rect_center_y)
# message("object_process_item : vViewCenter : " + str(vViewCenter_x) + " / " + str(vViewCenter_y) + " | " + str(vViewPort_Rect_center_x)+ " / " + str(vViewPort_Rect_center_y)  + " | " + str(vDifference_x)+ " / " + str(vDifference_y))
vObject_type = vs.GetType(vViewPort_Object_handle)
if ((vObject_type == 122) or (vObject_type == 3)): vs.HMove(vViewPort_Object_handle, vDifference_x, vDifference_y)

 

best regards

 

Share this post


Link to post

This makes perfect sense. Thanks!

 

I still don't fully "Grok" the Vectorworks API. Sometimes things are straight forward and other times it seems convoluted. I will keep working at this and hopefully one day I will be able to answer a few questions.

 

Again, Thanks

 

Martin

Share this post


Link to post

Hello

 

I complete agree with you. I feel all about the same. 🙂

Share this post


Link to post

MullinRJ

 

How do you know they are read only?

 

When I look at the appendix I see the following:

Scale                           1003 REAL ObjectVariableReal

Viewport x Position  1024 REAL  ObjectVariableReal

Viewport x Position  1025 REAL  ObjectVariableReal

 

I don't see anything that would indicate 1024 and 1025 are read only. Where do you find that nugget of information.

 

Thanks

 

 

Share this post


Link to post

Martin,

   IFF [sic] you really want to GROK the whole VectorScript experience, you'll have to procure a copy of "Hitchhikers Guide to All Things VectorScript (and Python, too!)."

 

   However, it may be a bit easier to download a copy of the SDK from the VW site:  http://www.vectorworks.net/support/custom/sdk/sdkdown

and look for this file:  .../SDK/SDKVW(build#)/SDKLib/Include/Kernel/MiniCadCallBacks.h

 

   In it you will find long sloppily typed lists of extremely esoteric and somewhat arcane factoids. When you find yourself standing precisely in Ra's shadow, notice the following illuminations: 

const short ovViewportXPosition                = 1024;        // double   read only - the X coordinate of the viewport on the sheet layer - Public for VS
const short ovViewportYPosition                = 1025;        // double   read only - the Y coordinate of the viewport on the sheet layer - Public for VS
 

That is how I know 😉

 

If this doesn't help, ...

Raymond

 

 

Share this post


Link to post

Wow!

 

Nice reference! Not related, but a long time ago I have a VW bug. I found a book on VW repair. This book was so well done that at 14  I rebuilt the engine one a 1969 classic VW. It ran for years. I wish I had the same book for VW & Python scripting. Every step seems like a slugfest.  I've been banging my head against the wall all day trying to get viewport centering to work correctly.

 

Using the following code:

 

Quote

    for selectedObjects in range(0, len(objectList)):
        vs.Layer(ModuleLayer) # make sure we are on the correct starting layer

        screenName   = objectList[selectedObjects][0] # Gets the Screen Name   - 1st item in t = (screenName,objectHandle)
        objectHandle = objectList[selectedObjects][1] # Gets the Object Handle - 2nd item in t = (screenName,objectHandle)

 

        # Get the object height, width and bounding box of object
        p1, p2       = vs.GetBBox(objectHandle)
        objectWidth  = vs.HWidth(objectHandle)  
        objectHeight = vs.HHeight(objectHandle) 

 

        #Create VP Crop Object
        vs.Rect(p1, p2, objectWidth, objectHeight)
        vpCrop = vs.LNewObj()

 

        # Create the layer and set the layer name
        layerHandle = vs.CreateLayer('01', 2)  # using 01 forces the next unused sheet nubmer to be used
        layerName   = vs.GetLName(layerHandle) # get they layer name. It appears the layer name is the sheet number
        vs.SetObjectVariableString(layerHandle, 159,'Module Layout - ' + screenName)

 

        vs.Rect(0,0,10,10) # test to see if something draws on the sheet layer

 

        #Create the VP and set Crop Object
        vpHandle = vs.CreateVP(layerHandle)
        vs.SetVPCropObject(vpHandle, vpCrop)
        vs.SetObjectVariableReal(vpHandle, 1003, 32) #set scale to a default of 32

        viewPort_X, viewPort_Y = vs.HCenter(vpHandle)
        print(viewPort_X, " ", viewPort_Y)

 

    vs.ReDrawAll()


 

 

 

viewPort_X and viewPort Y are always 0.

 

What is super strange, is when I run the script it leaves me on the last sheet layer created and I can see a viewport created at 0,0 (with a red x through it). If I change sheet layers and change back, the viewport shows up in the wrong location. You can see the two attached screen shots to see what I am talking about.

 

I've tried adding ReDraw and ReDrawAll in multiple points in the code and it makes no difference. I'm using 2108 sp3.

 

It seems like some type of reset or redraw is required after the VP is created or maybe after the crop is set.

 

Any thoughts?

 

Martin

 

 

 

Screen Shot 2018-05-16 at 4.12.25 PM.png

Screen Shot 2018-05-16 at 4.11.51 PM.png

Share this post


Link to post

Gotta run, but I have 1 quick thought and no idea how it will affect viewports. Have you tried ResetObject()? This is a lot of what programming is about when you are learning, and after 30 years scripting with MC/VW I'm still learning. When in doubt, try something, anything, and take notes.

 

Good luck,

Raymond

Share this post


Link to post

Hello

 

I am using my script for producing many small plats in a batch (moving window on every object) to export each to its own pdf for many years - first in VectorScript and now ported to Python. It works without problems. I do not need to ResetObject() nor  ReDrawAll(). In general I do not see any greate difference to your code. The only difference in my script is, that I am using a predefined presentation layer and reusing it for every plat to be drawn and exported. But I do not think that this is the problem.

 

I tried and slightly adapted your code (see attachment) and the only proble that I can see is, that vs.CreateVP() creates a ViewPort-Object with no layer and class activation (they are all set to invisible). So running your code I get also this square with the red cross in it. But when I assign class and layer visibility to active for this ViewPort-Object the bounding box of the viewport change to its real dimensions and location. Thus assigning class and layer visibility is "indispensable" to get the correct result, although the square with the red cross seems to be a temporarily "artifact" with a viewport with all classes and layers set to invisible. Finally the new created viewport has to moved to the page center (or any position) - that is default and is corresponding the manual viewport creation.

 

best regards

viewport.vwx

Share this post


Link to post

I finally got it working. I'm not sure why, however a ResetObject was needed after the layers and classes were turned on.

 

Thanks for pointing me the right direction. For some reason this was tough to get working.

 

Again, Thanks!

 

Martin

 

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.

×