Page 1 of 2

Cloning a template card with code

Posted: Thu Sep 17, 2015 6:19 pm
by mrcoollion
I am trying to clone a card I use as a template to a new card with a new name.
And I also need to delete a card of which I know the name

I use the code:
clone card "Template"
And this works but the name of the clone is identical to the original (duhh :shock: ).
After cloning I do not know which card to change the name of?

Is there a way to give the new card name with the clone or other command?

Any idea's?

Regards,

Paul (mrcoollion)

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 6:31 pm
by Dixie
Clone the card and then set the name of 'the last card of this stack' to whatever you want to call it... :-)

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 6:38 pm
by dunbarx
Hi.

Go to the dictionary, and look up the keyword "last". This is so useful, but may not help here at all.

So why mention it? Only because it is very convenient when doing what you intended with controls on a card, since any newly created control is automatically the "last" on. (Do watch out when using this keyword for groups. It is not stable). But this may not work with cards, since you can create (or clone) a new card in the middle of other cards in a stack, and that reference is likely broken.

However, if you set the name of the templateCard to something unique, or to something that follows a sequence you have already pre-arranged, you can then identify it and find it. You will already have set its name, and you can even find it within any other cards in the stack, and do what you will...

As regards deleting a named card, why not just delete the card? (Back to the dictionary?)

Craig Newman

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 7:03 pm
by mrcoollion
Dixie wrote:Clone the card and then set the name of 'the last card of this stack' to whatever you want to call it... :-)
I already tried this and it does change a card name but unfortunately it does not change the correct card but another card already existing :( .
I used the statement: 'set the name of the last card of this stack to thenewcardname' which is the same as you suggested.

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 7:06 pm
by Dixie
Yes, 'last' is very useful... and it does help here !
Changing the name of the card directly after issuing the clone command works here... I've just tried it cloning the last card of a stack and cloning one in the middle of a stack of cards...

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 7:10 pm
by mrcoollion
Tried the following:

Code: Select all

 clone card "Template"
   set the name of card "Template" of this stack to thenewcardname
This works. It probably changes the first card it finds that is named Template but that does not matter because they are clones anyway.

Thanks for the help.

:D

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 7:49 pm
by FourthWorld
"last" will refer to the last card in a stack, which may not be the newly created one if the creation happened while on any but the last card.

However, once a card is create it becomes the current card, so a reference to it can be obtain with "this", e.g.:

get the long id of this cd

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 7:52 pm
by dunbarx
Guys.

The" last" card is almost never the "latest" card. It is not sound, and certainly not robust, to rely on this sort of thinking.

This is, as I said above, OK with controls. since any newly created button, say, is always the last button.

But with cards, this is not necessarily true at all, since a card can be pasted, created or cloned into the middle of a stack. Don't do it.

Craig

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 7:53 pm
by Dixie
Richard... I am not seeing that. If the card is cloned and then renamed directly on the next line, I am seeing that it is the last card that has taken the name and it is the clone...

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 8:00 pm
by dunbarx
Richard's point, that you can rely on a newly created, cloned or pasted card to be the current card in the defaultStack has merit. Well and good, though it requires that you work on that card in that place; changing its name, say.

Just don't rely on "last" when dealing with copies of cards.

Craig

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 8:04 pm
by dunbarx
No.
Richard... I am not seeing that. If the card is cloned and then renamed directly on the next line, I am seeing that it is the last card that has taken the name and it is the clone...
Make a stack with several cards. Find a way to show their numbers. Go to a middle card. Put a button on it, and this in the button script:[codeon mouseUp
clone this cd
set the name of last card to "mmm"
end mouseUp.[/code]

Now check out the name of the card you are on (the cloned card) and see if its name is "mmm"

Craig

Re: Cloning a template card with code

Posted: Thu Sep 17, 2015 8:23 pm
by dunbarx
Rereading Richard and myself, I wonder if there isn't a misunderstanding. It seems that everyone knows that the cloned card is the current card, and that the last card is the last card, and that the two may be, but usually will not be, the same card.

So, use the templateCard, or work directly and immediately on the current card, but do not use the last card. Right?

Craig

Re: Cloning a template card with code

Posted: Wed May 20, 2020 7:35 pm
by mrcoollion
One can clone a card immediately into another name with

Code: Select all

clone this card as "NewCardname"

Re: Cloning a template card with code

Posted: Wed May 20, 2020 8:03 pm
by dunbarx
Certainly. It is one of the things that makes cloning so useful. Copying has more bells and whistles, but is not able to set the name of the copy.

But I still emphasize one has to watch card order. If you have a stack of ten cards, and you clone cd #5, the clone will be cd # 6, not cd 11.

Not the last card.

Craig

Re: Cloning a template card with code

Posted: Wed May 20, 2020 8:15 pm
by Klaus
One can also check IT!
From the dictionary about "clone":
...
IT: The clone command places the long id property of the newly created object in the it variable.
...