Jump to content
rosebud5

Script help for classes

Recommended Posts

Hello all, I had great help with my last line weight request (script to change line weights) Now I would like to create a script for when I click on an object it automatically transfers to the chosen class, i.e., select object, run script that puts object in specified class according to script. Any ideas. Selected object is currently in NONE class and, ideally, I click "furniture class script" and it puts it into furniture class. I know that i can do this from the OIP, but would love to make a speedier way to go about it.

Thanks,

Share this post


Link to post

If it may be python:

#python code
c='class-1'
def changeclass(h):
vs.SetClass(h, c)
return()

vs.ForEachObjectInLayer(changeclass, 2, 1, 2)

If you use this, check http://developer.vectorworks.net/index.php?title=VS:ForEachObjectInLayer

for options

Because "selectec object" could mean different things (all selected everywhere, just visible objects, etc.)

You can use also:

c='class-2'
def changeclass(h):
vs.SetClass(h, c)
return()

criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"
vs.ForEachObject(changeclass, criteria)

Share this post


Link to post

Hi Thanks for the quick reply, I am not familiar with python so I choose your second option. I am trying to click on the selected item that is currently in the "None" class and put it an existing class called "Apt Construction" I put put that class name as the first line that read

c='Apt construction'

def changeclass(h):

vs.SetClass(h, c)

return()

criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"

vs.ForEachObject(changeclass, criteria)

I am thinking that maybe it should read

c='None'

def changeclass(Apt Construction):

vs.SetClass(h, c)

return()

criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"

vs.ForEachObject(changeclass, criteria)

Thanks for your help!

Share this post


Link to post

Hi

I think its just a problem of actualisation of the info-palette-view. The Objects change the class, but you do not see that immediately. To fix that, you could use

"vs.ResetObject(h)" in the script

Try this:

c='Apt Construction'
def DoIt(h):
vs.SetClass(h, c)
vs.ResetObject(h)
return()

criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"
vs.ForEachObject(DoIt, criteria)

To unterstand the stript:

1. c='class', just set c to 'class'. Instead of that we could use also vs.SetClass(h, 'class')

To use there a variable is better, because maybe later you want to input that class name in a dialog box etc. So it is better "ask" for the variable valuesat the beginning of a script.

I am thinking that maybe it should read

c='None'

def changeclass(Apt Construction):

vs.SetClass(h, c)

return()

criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"

vs.ForEachObject(changeclass, criteria)

not really, if you want to work whith an activated object. Your idea goes in a direction to put all objects in "None" to another class. (Which also could be realized)

the function ( which starts with "def"), containes a callback function for ForEachObject (FEO). And FEO takes a handle to the object and input it in the function as "h". Your Class Name you do not have to input by "FEO", because you defined it at start with c='Apt Construction'

FEO loops all objects by a criteria and "def" says, what to do with them.

Above I renamed the function to "DoIt". This makes it more clear, what happens.

All clear? :-)

Share this post


Link to post

Amazing, you really know you stuff, thank you, greatly appreciated and thanks for the video, huge help!!!!

Share this post


Link to post

Hello, I have been using my class script that DomC helped me with (see above). However, when I use the script to change the class of certain objects, for example, walls, it does not take on the attributes. It changes the class and some attributes like dash line but not line wieight. Any suggestions would be greatly appreciated. Thanks!

Share this post


Link to post

Also, when I click on the object and manually go to the class in the nav. palette and "assign to selection" it takes on the attributes, line weight, dash, etc. just fine.

Share this post


Link to post

When you assign a class by script I don't think the object is "redrawn". Try resetting each object after you change the class.

Share this post


Link to post
On 24.4.2016 at 7:19 PM, DomC said:

c='Apt Construction' def DoIt(h): vs.SetClass(h, c) vs.ResetObject(h) return() criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))" vs.ForEachObject(DoIt, criteria)

Hi,

how happy was I to find your questions and answers about setting the class of an activated object to a certain class.

I am quite new to work with scripts (and in this forum).

 

I gave it a try and just copied the above script and changed the name of the class to the one I need.

Maybe you could help me with this error:

 

File "<string>", line 3

  vs.SetClass(h,  c)

     ^

IndentationError: expected an indented block

 

Do you know what I should change?

Thanks a lot,

Lilith

 

 

 

 

 

Share this post


Link to post

Hello Lilith,

 

other than in the most programming languages code blocks are nested by intendation in Python. (usualy by 4 whitespaces or one tab)

 

I hope now it works:

c='Apt Construction' 

def DoIt(h):
	vs.SetClass(h, c) 
	vs.ResetObject(h) return() criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))" vs.ForEachObject(DoIt, criteria) 

 

Share this post


Link to post
c='Apt Construction' 

def DoIt(h):
    vs.SetClass(h, c) 
    vs.ResetObject(h) 
    return() 
    
criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"
vs.ForEachObject(DoIt, criteria) 

 

Maybe this will work?

Share this post


Link to post

Hhm... well... it behaves differently than expected.

When I blend out this special class, all other objects are also blended out -

as if they are set to this class too even if they are not and the info palette doesn`t say so either.

I have to change the class to another class and then back to the original class for them not to blend out too.

 

The objects are lighting instruments. I guess I should have said so.

Other objects don`t show this behavior (like rectangles or circles). With them it works as expected.

 

Share this post


Link to post

Hi Patrick,

 

I did some tests to get the idea with what kind of object it works and with what kind it doesn't.

Symbols from the VWX library that are not lighting instruments work.

Drawn objects work.

I change them to be a lighting device - it still works.

I change them to be a symbol in my library - it doesn't work.

I don't get the pattern yet.

 

If you blend out the class "spielt nicht mit" - you can see the results.

 

 

 

 

 

Script_Tests_Klasse_zuordnen_v2.vwx

Share this post


Link to post

When I select all Objs and run the script they all are put into 'spielt nicht mit'.

Sorry if I can't follow you.

 

Mayber you should check the criteria. You can easily create create them with the criteria dialog (click in the left corner of the script dialog): 

 

 

Bildschirmfoto 2016-11-24 um 09.44.53.png

 

Bildschirmfoto 2016-11-24 um 09.44.47.png

Share this post


Link to post

Hi Patrick,

 

I would like to select lighting instruments, run the script to put just the selected ones into the class 'spielt nicht mit' and leave all the other lighting instruments unchanged.

At the moment it puts all lighting instruments into the class wether they are selected or not.

So the criteria should be "activated" or "selected".

I will have a look at the criteria dialog you mentioned.

Thank you, Patrick!

Share this post


Link to post

Yes, the objects stay in their old class - that`s what the info palette says -  but they are blended out anyway when I blend out 'spielt nicht mit'.

Only lighting instruments behave like that.

That was the test about I tried to explain above.

 

They are somehow in both classes now. You can blend them out with their old class or with 'spielt nicht mit'.

That's kind of weird.

 

 

Share this post


Link to post

c='spielt nicht mit'

def DoIt(h):
    vs.SetClass(h, c)
    vs.ResetObject(h)
    return()
    
criteria="(INSYMBOL & INOBJECT & INVIEWPORT & (SEL=TRUE))"
vs.ForEachObject(DoIt, criteria)

 

(SEL=TRUE) is already part of the criteria, but it somehow doesn`t work.

At least I don`t get how.

 

 

Share this post


Link to post

Hello,

 

after some tests I figured out that I need to find a way to exclude both groups and layouts and objects that are not visible at the moment

(for the last I found something: (NOTINDLVP & NOTINREFDLVP & (V))

otherwise there will be bad surprises.

Or train myself to never ever leave something activated/selected in a group or layout or in a class or layer that is not visible... no, wait, if I change the class of an object to another class that is not visible (which I need to do very often) I`d have to change this new class to be visible again, deselect all objects, hide the class again and then go on with my work. That seems to be more work than to do all that without the script... hhm...

Are there any other ideas?

Share this post


Link to post

Have you tried setting up Saved Views to control class visibilities ?

&/or simply locking those instruments that you don't want to be mitgespielt.

Share this post


Link to post

Hi bcd!

 

I am searching for a faster way via script to "park" lighting devices into a certain class that is invisible in my layouts.

(During rehearsal process the lighting devices of our standard equipment tend to be thrown out and then be part of the play again and so on.)

Saved Views don't help with that, do they?

 

What does locking instruments mean?

 

I got some ideas from one of the instructors how to adjust the criteria.

Didn't have time yet to test them.

Share this post


Link to post

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.


 

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.

×
×
  • Create New...