Cheth Posted October 14, 2015 Share Posted October 14, 2015 I seem to be trying the same thing over and over again. I am trying to understand vs.ForEachObject criteria in terms of python. For example, if I take this script in vectorscript Var Light: Handle; Procedure setname(conventional:Handle); Begin SetRField(conventional,'Lighting Device','Symbol Name','Conventional'); End; Begin ForEachObject(setname,(((PON='Lighting Device') & ('Lighting Device'.'Device Type'='Light')))); End; Run(setname); And I want to move it to Python... I only get as far as, import vs; def setname(h): vs.SetRField(h,"Lighting Device","Symbol Name","Conventional"); vs.ForEachObject(setname, ????) I can't figure out the syntax to check for the device type in a lighting device that is equal to a value of Light. I error out every time. Quote Link to comment
twk Posted October 14, 2015 Share Posted October 14, 2015 From Dev Wiki def vs.ForEachObject(callback, c): return None Try this.. import vs; def setname(h): vs.SetRField(h,"Lighting Device","Symbol Name","Conventional"); crit = "(((PON='Lighting Device') & ('Lighting Device'.'Device Type'='Light')))" vs.ForEachObject(setname, crit) Disclaimer: Not Python expert Quote Link to comment
Cheth Posted October 15, 2015 Author Share Posted October 15, 2015 TWK FTW. Thank you. I was pulling my hair out trying to understand how to reference criteria in python. Quote Link to comment
Dieter @ DWorks Posted October 16, 2015 Share Posted October 16, 2015 Please also consider using dlibrary, which has a Criteria class to easily use this in Python. Dlibrary isn't finished, but everyone is encouraged to contribute to it. So extra criteria can always be added! Quote Link to comment
twk Posted October 18, 2015 Share Posted October 18, 2015 Dieter, this looks like an invaluable resource. I am just getting my head stuck into python after losing sleep over VS.hehe. People tell me python is good for file access/os access/external libraries galore/etc. So I'm slowly making the switch. Your dlibrary modules, do we just download that straight from that website? Or is there a better way? Clone? what does that mean? Looks helpful, if I knew how to use it.lol Thanks in advance Tui Quote Link to comment
Dieter @ DWorks Posted October 19, 2015 Share Posted October 19, 2015 Your dlibrary modules, do we just download that straight from that website? Or is there a better way? Clone? what does that mean? Looks helpful, if I knew how to use it.lol Thanks in advance Tui Well, you can download specific versions from the site. You can place the code where you want and it to the scripting paths in VW. In your script, you can then import the modules to use them. If you use an external editor, you can get syntax highlighting etc. Did you read the readme and manual install files? There is some info in there on how to use it, but I still have to write a good step by step guide on how to use it properly with VW. Quote Link to comment
twk Posted October 21, 2015 Share Posted October 21, 2015 I haven't read them yet. Will get to it after some python courses I'm doing. 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.