Page 1 of 2
Copy and rename a button - which takes precedence?
Posted: Wed Nov 02, 2022 10:11 pm
by M-A Kuttner
Hi all. I've got a button that I want to copy via a script and then rename the copy to a new button name. The script is essentially this:
Code: Select all
copy button ButtonName
paste
set the name of button ButtonName to "ButtonName1"
My question is; after I've copied and pasted the button, how does LC decide which of the buttons I will be renaming. Does it prioritize by earliest ID, latest ID, highest layer number, or something else? When I rename button ButtonName, am I renaming the original or the copy?
Thanks!
M-A
Re: Copy and rename a button - which takes precedence?
Posted: Wed Nov 02, 2022 11:22 pm
by mtalluto
Hi M-A
You can use 'it' to identify the reference to the pasted control.
Here is some example code:
Code: Select all
on mouseUp
copy button "marko"
paste
set the name of it to "polo"
end mouseUp
Re: Copy and rename a button - which takes precedence?
Posted: Wed Nov 02, 2022 11:28 pm
by jmburnod
Hi,
You may use clone command.
Something like that.
Code: Select all
on cloneOneBtn pTargetName, pNewName
clone btn pTargetName
set the name of last btn to pNewName
end cloneOneBtn
Best regards
Jean-Marc
Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 2:14 am
by M-A Kuttner
Many thanks, Mark and Jean-Marc!
Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 2:30 am
by dunbarx
M-A.
Know that whenever you create any new control, however you do that, it can be accessed via the "last" keyword, before you know anything else about it. But just as the local variable "it" can change almost at once, depending on what is going on in a handler, it is a good idea to explicitly set certain important properties, like the name, of that last control.
Know also "last" does not seem to work with groups.
Craig
Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 9:26 am
by Klaus
Hi friends,
we can do this:
Code: Select all
on cloneOneBtn pTargetName, pNewName
clone btn pTargetName AS pNewName
end cloneOneBtn
Best
Klaus
Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 12:50 pm
by jmburnod
Saperlipopette !!
Klaus made it shorter

Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 12:56 pm
by Klaus
That's pure lazyness!

Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 1:22 pm
by M-A Kuttner
Wow, great! Many thanks guys!
Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 4:07 pm
by stam
Klaus wrote: ↑Thu Nov 03, 2022 12:56 pm
That's pure lazyness!
That's to be applauded

Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 5:21 pm
by dunbarx
Spelling "laziness" with a "Y" is not lazy, it is extra work for little gain.
Craig
Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 5:25 pm
by Klaus
I'm a 10 finger typer, so that does not matter to me...

Re: Copy and rename a button - which takes precedence?
Posted: Thu Nov 03, 2022 7:24 pm
by Klaus
Or was that a joke that (again) I didn't get?
Re: Copy and rename a button - which takes precedence?
Posted: Fri Nov 04, 2022 6:09 am
by dunbarx
Klaus.
The extra work I mentioned derives from the longer distance one has to move one's finger in order to access the "Y" as opposed to the "I".
This is wasted energy; it requires the body to burn more calories since it takes extra work to move ones fingers that extra distance. It takes energy to displace considerable additional air, and I will not even go into the extra time required for that additional finger travel, including the return travel time, which in turn requires the computer itself to be powered on longer than necessary.
No wonder the glaciers are disappearing.
Craig
Re: Copy and rename a button - which takes precedence?
Posted: Fri Nov 04, 2022 9:57 am
by Klaus
AHA!
OK, that joke may not work so well with german keyboards, where the Y is at another place,
right above the left CMD and ALT key.