Jump to content
Martin Crawford

Layers with Python

Recommended Posts

Hi

 

I have created a python script to draw LED panels and data lines. The LED panels should be on one layer and the lines on a separate layer.

 

I thought I could use  vs.Layer('Screen - Panels') for the LED Panels and vs.Layer('Screen - Data') for the data lines and simply call them before drawing the objects.

 

When the script runs, everything is on the last vs.Layer used, in this case 'Screen - Data'

 

 

Share this post


Link to post

Martin,

   Try this script:

import vs;

vs.Layer('Screen - Panels')
vs.Rect(0, 0,   1, 1)
vs.DSelectAll()


vs.Layer('Screen - Data')
vs.ArcByCenter(1, 1, 0.5, -90, 270)
vs.DSelectAll()

 

It creates a layer and draws a Rectangle on it (and deselect it), then creates another layer and draws an Arc on it (and deselect it). How does this differ from your script?

 

Raymond

 

 

 

 

Share this post


Link to post

If I run the above as a script everything shows up on the correct layers, however if I create a plug-in object and run the exact same code, everything is on the Screen - Data layer.

 

I was not doing a deselect all and I thought that would be the problem, however it still is not working.

 

Is there something else that needs to be done because I am doing this within a plug-in?

 

Martin

Share this post


Link to post

Interestingly, if I create a Marionette node to create two object on two different layers, it works, if I then convert the marionette to an object node, then it no longer works.

 

I suspect because the Marionette changes the parent obj to change a layer, however this fails when working with a plug-in object.

 

Is there a way to have a plug-in with objects on separate layers and classes? This seems like it should be straight forward.

 

Thanks

 

Share this post


Link to post

Martin,

   A basic Plug-In object is a SINGLE object and it must reside on one layer. It can contain multiple parts, like a symbol or a group, but it is treated as ONE object. You can put the pieces in multiple classes, but not on multiple layers. It is possible to "cast off" objects to other layers as your Plugin code runs, but that is definitely not standard practice.

 

   You could run your code as a Menu Command and draw on separate layers. That is more akin to running code from a script palette. Write back if you need more direction.

 

Raymond

Share this post


Link to post

Another way to think about it.  Everything drawing inside of a PIO is considered part of that PIO. Since the PIO can only exist on a single layer, all of the objects inside that PIO must be on that layer.

 

If it is possible to adjust your file to use Classes instead of Layers, then you can keep everything inside the PIO.

 

If you have to use layers, as Raymond says, the objects will have to be "cast off."  I think you can do this by using the SetParent command and a handle the the objects that need to be on the other layer. Set the Parent to the layer you want them to be on.

 

 

Share this post


Link to post

Thanks,

 

I think I can make it work with a combination of classes and layer. And I think I understand the layers and PIO

 

 

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