matteoluigi Posted November 1, 2020 Share Posted November 1, 2020 Joshua Benghiat already told me, that record-format-criteria with variables can be finicky. However, I now wanted to switch my script to python. Can anyone tell me why "ZANZAHL = vs.Count("('Wohnung'.'Haus-Nr'=Variable)");" doesn't work, or beter, what can I do for make it working? Sure, the whole Syntax inbetween the quotation marks is a string, so, the variable gets lost. Maybe I really have to concatenate the criteria to make them working, do I really have to? Sounds quite strange to me. Looking for record format criteria with variables sounds to me quite normal. Quote Link to comment
JBenghiat Posted November 2, 2020 Share Posted November 2, 2020 Criteria are strings, and that is especially true in python. Assuming Variable is also a string: ZANZAHL = vs.Count("('Wohnung'.'Haus-Nr'='"+Variable+"')") 1 Quote Link to comment
matteoluigi Posted November 2, 2020 Author Share Posted November 2, 2020 (edited) What does the „+“ stand for? And why did you write the variable in single quotation marks? (‘) Edited November 2, 2020 by matteoluigi Quote Link to comment
JBenghiat Posted November 2, 2020 Share Posted November 2, 2020 the + will concatenate strings in python You seem to have figured out that any string values, including those build from variables, should be surrounded in single quotes. Quote Link to comment
matteoluigi Posted November 15, 2020 Author Share Posted November 15, 2020 finally have been able to resume my work on python, never thought it would be that different between vectorscript and python. The code from above doesn't return me any syntax errors, however, it doesn't still work I actually try to calculcate the area of all objects with the same criteria, (like I already have been able to do in Vectorscript) I tried it your way, then I tried it the other way you suggested me last time in vectorscript. Concatenating strings works fine in python, with + signs and with vs.Concat. However the area-function doesn't return me the area of all objects with the wanted criteria. So I integrated the AlrtDialog in the end of the script, just to see what really is happening inside the script, and, every concatenation looks really good. However, the area is always empty. I also wrote # in front of the area function, just to see, if there was another problem. From that moment the HAREA variable was always = 1234. (because I set it = 1234 in the 5th line) Somehow I want to port my script to python, too 1) because I am learning both, python and vectorscript 2) because i think that python in long terms is the better choice... thanks for your great help to my last questions! (unfortunately tabs don't work as I want them to work in the forum-quote) Quote BR = vs.Chr(10); kQC = vs.Chr(39); HNR=1 WHNR=1 HAREA=1234 for HNR in range (10): HNRS = (vs.Concat(HNR)) # HNRS = vs.Num2Str(HNR, 0) HQUERY = (vs.Concat('(',kQC,'datenbank', kQC,'.', kQC,'Haus', kQC,'=',HNRS,')')) # critSTRING = vs.Concat('((', kQC,'Wohnung', kQC,'.', kQC,'Haus-Nr', kQC,'=', kQC, HNR, kQC,') & (', kQC,'Wohnung', kQC,'.', kQC,'Whg-Nr', kQC,'=', kQC, WHGNR, kQC,'))'); HAREA = vs.Area(HQUERY) # ZANZAHL = vs.Count("('datenbank'.'Haus'='"+HNR+"')") vs.AlrtDialog(vs.Concat('Haus-Nr ',HNRS,' hat ', HAREA,' m²',BR,'Abfrage: ', HQUERY)) python_criteria_test.vwx Quote Link to comment
JBenghiat Posted November 15, 2020 Share Posted November 15, 2020 First, one advantage to python is that it excepts both single and double quotes as string identifiers. That means that if you formulate your criteria string with double quotes, you don’t need to concatenate in all those quote characters, making your code more human-readable and thus easier to spot errors. I would also use the criteria builder in the script editor as a starting place. The criteria builder will tell you how many objects match your search, functioning as a quick unit test. Then, take the resulting string, select the variable and type: "++" (or ", , " for vs.Concat), and insert your variable name. There may be a simple error here, for example if the house number is stored as an integer, you would not enquote the search value. Also try AreaN() instead. Quote Link to comment
matteoluigi Posted November 15, 2020 Author Share Posted November 15, 2020 4 hours ago, JBenghiat said: AreaN() HAREA = vs.AreaN("('datenbank'.'Haus'="+HNRS+")") made it. The Variable also only works without single quotes. (not HAREA = vs.AreaN("('datenbank'.'Haus'='"+HNRS+"')") ) first step made 😄 thank you!!! 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.