How to copy/transfer a macro into a Layout using AddLayoutElements?

This is a place for people to share the custom macros they have written.

Moderator: Moderators

grst_opt
Posts: 1
Joined: Yesterday, 01:34

How to copy/transfer a macro into a Layout using AddLayoutElements?

Postby grst_opt » Yesterday, 01:40

Hi everyone,
I’m trying to figure out the correct way to place a macro from the Macros window into a Layout via XML / ActionScript.

So far I tried something like this:

<step>Layouts.AddLayoutElements(handle:"Location=Layouts,1,1",
handles:"Location=Macros,1,11",
x:0, y:0)</step>

…but it doesn’t seem to work. The macro gets selected, but nothing is actually added to the Layout.

I also tried with Handles.SetSourceHandleFromHandle before calling AddLayoutElements, but still no success.

What is the correct method to either copy a macro into a Layout or transfer/link it there programmatically? Do I need to use AddSelectedHandleToLayout, or is there another approach for macros specifically?
User avatar
Gregory
Posts: 1379
Joined: 14 Dec 2007, 15:25
Location: London, United Kingdom
Contact:

Re: How to copy/transfer a macro into a Layout using AddLayoutElements?

Postby Gregory » Today, 19:42

Please try the following:

Code: Select all

<step>Layouts.AddLayoutElements("Location=Layouts,1,1", handle:"Location=Macros,1,11", 0, 0)</step>

In macro scripts handle: or similar indicates that the value should be converted to the type preceding the colon. This is only necessary if an conversion cannot be detected automatically so in the above although you could write handle:"Location=Layouts,1,1" for the first parameter, this is inferred by the type the function is expecting. In the case of the second parameter there are two steps to the conversion, the first is to convert the string to a single handle and the second (which is again inferred) is to convert that into a list of multiple handles (even though the list only contains a single item). If a cast is not specified the software will attempt to split the string on the commas and then convert each part as a separate handle which wouldn't work when the parts are supposed to form a location.

Who is online

Users browsing this forum: No registered users and 96 guests