spettitt Posted August 27, 2023 Share Posted August 27, 2023 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? Quote Link to comment
Jesse Cogswell Posted August 27, 2023 Share Posted August 27, 2023 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: 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)) Quote Link to comment
Pat Stanford Posted August 27, 2023 Share Posted August 27, 2023 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. Quote Link to comment
spettitt Posted August 27, 2023 Author Share Posted August 27, 2023 Thank you both - that's sorted it, and I understand why now as well. Quote Link to comment
Recommended Posts
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.