Construct object name from string

Discuss Lemur and share techniques.
Post Reply
daviddeskew
Newbie
Posts: 3
Joined: 21 Nov 2016 01:02
Location: New York
Contact:

Construct object name from string

Post by daviddeskew »

Can this be done?

Suppose I have 50 labels with names like label1, label2, ... label50

I would like to set an attribute on each label and obviously I would prefer not to write

setattribute....

50 times

Ideally I'd like a for loop (say) where I could create the string name for each object, e.g.

for (i = 1; i<=50; i++)
setattribute('label' + inttostr(i), 'content', 'x'); // Set the caption for each label

However, the basic experiment,

setattribute('label1', 'content', 'a')

fails, presumably because setattribute wants an object name as the first parameter.

So how does one create an object name from a string? (And I assume there's a function that converts an integer to a string as well)


Thanks
____________
David Jameson
http://gigperformer.com
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Construct object name from string

Post by oldgearguy »

integer to string:

Code: Select all

strNum = '' + 1; 
strNum will now contain '1'

attached is one way to create and reference dynamic object names

One trick is to create the object name as a string and then use findobject() to get the object reference to use in setattribute(). I'm sure I've used other ways as well, but that one is fairly straightforward.
Attachments
objtest.jzml
(4.5 KiB) Downloaded 106 times
daviddeskew
Newbie
Posts: 3
Joined: 21 Nov 2016 01:02
Location: New York
Contact:

Re: Construct object name from string

Post by daviddeskew »

Got it --- all makes sense.

One last question if I may.....

I haven't been able to figure out the difference between Properties and Attributes as specified for the various objects so I don't know how to change things programatically.

I understand the setattribute function (have used it with the attribute 'content' to change labels) but how do I change the foreground/background color of a knob.

Neither setattribute(knob, 'Foreground', RGB(..)) nor
knob.Foreground = RGB(...)

works

What am I missing here?

Thanks so much for your responses.
____________
David Jameson
http://gigperformer.com
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Construct object name from string

Post by oldgearguy »

this should work:

Code: Select all

setattribute(Knob, 'color', {RGB(0,1,1),RGB(0,0,1)});
note that you can't set foreground and background separately in most cases; you need to set color to an array of 2 values for foreground and background.
daviddeskew
Newbie
Posts: 3
Joined: 21 Nov 2016 01:02
Location: New York
Contact:

Re: Construct object name from string

Post by daviddeskew »

Wow --- is that syntax documented anywhere? I did not notice that in the documentation anywhere.

Much appreciated.
____________
David Jameson
http://gigperformer.com
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Construct object name from string

Post by oldgearguy »

daviddeskew wrote:Wow --- is that syntax documented anywhere? I did not notice that in the documentation anywhere.

Much appreciated.
Kind of - taking the Knob as an example, on page 98 the attribute color is shown as an array of 2 values. The earlier text somewhere (don't have it now) talks about arrays (they call them vectors) using curly braces.
I know they call out in the Properties Foreground and Background, but in my experience i haven't always been able to directly address Properties with any success. There are functions for expressions and attributes (get and set) and variables are directly addressed via the dot notation (Knob.x).

Note that in some cases you have a color attribute and a colors attribute. The color is general foreground/background (or on/off) and the colors is an array (vector) of color information for every object of that type defined. For example, if you declare a 2x2 grid of pads you can use the colors attribute to set the off color of each pad to be something different.
Phil999
Regular
Posts: 919
Joined: 11 Jan 2012 01:53

Re: Construct object name from string

Post by Phil999 »

thank you for this clear description. I somehow manage to do things, but often have to refer to older projects or examples from the library; not knowing exactly how and why things work or don't work. Now it has become more clear to me.
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Construct object name from string

Post by oldgearguy »

Phil999 wrote:thank you for this clear description. I somehow manage to do things, but often have to refer to older projects or examples from the library; not knowing exactly how and why things work or don't work. Now it has become more clear to me.
you're welcome. I often try to go back to larger projects I've written looking for examples, but sometimes I get lost in the weeds.
Creating simple examples and then working variations on it until I understand what Lemur is actually doing tends to help it stick in my head.

What I really need to do is create a compendium of small examples showing off these less-than-perfectly documented techniques because they really are building blocks for larger and more complex projects.
nick_liine
Liine Staff
Posts: 285
Joined: 01 Oct 2010 11:06

Re: Construct object name from string

Post by nick_liine »

oldgearguy wrote:
Phil999 wrote:thank you for this clear description. I somehow manage to do things, but often have to refer to older projects or examples from the library; not knowing exactly how and why things work or don't work. Now it has become more clear to me.
you're welcome. I often try to go back to larger projects I've written looking for examples, but sometimes I get lost in the weeds.
Creating simple examples and then working variations on it until I understand what Lemur is actually doing tends to help it stick in my head.

What I really need to do is create a compendium of small examples showing off these less-than-perfectly documented techniques because they really are building blocks for larger and more complex projects.

Please get in touch if you already have an existing list of these, this could perhaps on the documentation wiki or at least serve as a guideline for which examples are most needed.
Post Reply