Construct object name from string
-
- Newbie
- Posts: 3
- Joined: 21 Nov 2016 01:02
- Location: New York
- Contact:
Construct object name from string
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
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
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: Construct object name from string
integer to string:
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.
Code: Select all
strNum = '' + 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 107 times
-
- Newbie
- Posts: 3
- Joined: 21 Nov 2016 01:02
- Location: New York
- Contact:
Re: Construct object name from string
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.
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.
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: Construct object name from string
this should work:
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.
Code: Select all
setattribute(Knob, 'color', {RGB(0,1,1),RGB(0,0,1)});
-
- Newbie
- Posts: 3
- Joined: 21 Nov 2016 01:02
- Location: New York
- Contact:
Re: Construct object name from string
Wow --- is that syntax documented anywhere? I did not notice that in the documentation anywhere.
Much appreciated.
Much appreciated.
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: Construct object name from string
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.daviddeskew wrote:Wow --- is that syntax documented anywhere? I did not notice that in the documentation anywhere.
Much appreciated.
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.
Re: Construct object name from string
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
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: Construct object name from string
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.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.
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.
-
- Liine Staff
- Posts: 285
- Joined: 01 Oct 2010 11:06
Re: Construct object name from string
oldgearguy wrote: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.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.
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.