Jump to content

For Each Object - Lighting Device Criteria


Recommended Posts

I am trying to run a vs.ForEachObject in Python for Lighting Devices. I can't get anything to happen with this criteria:

 

vs.ForEachObject(lightloop, 'INSYMBOL & (PON=Lighting Device)')

 

but this works fine:

 

vs.ForEachObject(trussloop, 'INSYMBOL & (PON=TrussItem)')

 

I've tried LightingDevice, LDevice...what criteria will make this work, please?

Link to comment

Hmm.  I just tried it in Vectorscript and it worked fine.  I've never tried the PON= criteria, I usually use R IN ['Lighting Device'].  I'm not terribly familiar with Python, but you might be having some trouble with your quotations.  Try vs.ForEachObject(lightloop,('INSYMBOL & (PON = "Lighting Device")')).  In VectorScript, you would need 'Lighting Device' to count as a string but PON = can be a direct command.  Look at the syntax highlighting from the editor:

 

image.thumb.png.f8b2823e91b8c6fbfc736046a64b1803.png

 

When I ran this simple Python script, I got an accurate count of Lighting Device Objects:

import vs

counter = 0

def Execute(h):
	global counter
	counter+=1

vs.ForEachObject(Execute,("PON = 'Lighting Device'"))

vs.AlrtDialog(vs.Num2Str(0,counter))

 

Link to comment

Jesse is correct. You have the quotes wrong in your criteria.

 

The value in the PON= has to be a string and therefore needs quotes around it.

The entire PON='Lighting Device" needs to be a sting also and needs quotes around that also.

 

In Python you are lucky and can use both single quotes and double quotes. In VScript, you can only use single quotes so you have to "escape" single quotes by using multiple single quotes in a row. Or I also use C_HR(39) which is a single quote, but to my eyes easier to read than ''  (which is actually two single quotes, but looks like a double quote).

 

Hope this helps explain why what Jesse did worked.

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