How to use Element#setLength from python?

0 votes
asked Aug 18, 2018 in Python by hamiltont (360 points)
edited Aug 18, 2018 by hamiltont

This line of code fails in python: 

currentElement.setLength(1, LENGTH_UNIT_BYTES)

with error 

0x00 PYT 2000 ERROR Python: 'TypeError: in method 'Element_setLength', argument 2 of type 'char const *''

I've tried multiple variants (LENGTH_BYTES, enclosing in quotations, prefixing with synalysis. as done in Lua, etc). Cannot get past this error - any help? 

1 Answer

0 votes
answered Aug 18, 2018 by hamiltont (360 points)
Best answer

Figured it out. The manual reports the first parameter (the length) is supposed to be of type string. Odd, but easy enough to work around. This works fine: 

currentElement.setLength(str(length), LENGTH_UNIT_BYTES)

commented Aug 23, 2018 by andreas (2,460 points)
Yes, that appears odd :-) The simple reason for it is that you can pass there the same expression as in the GUI. The expression is automatically tested for variables and if there are none, only the result of the expression is stored.

The variables are resolved at parsing time with the values of the parsing results created so far. -- Searched backwards, you know ;)