License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
GDL
About building parametric objects with GDL.

Returning Subroutine definitions from a Macro

dushyant
Enthusiast
Hi

Is it possible to return subroutines defined in a macro? If so, how are they returned and how are they used in the caller object? Subs should be after END, and if a macro returns it, it would be before END, so I'm not sure how (if at all) this thing would work. But I really need this as I need to use certain subs repeatedly in several objects.

Thanks.
8 REPLIES 8
Podolsky
Ace
I don't see a problem with subroutine in a macro. If you want to request subroutine from macro, set a variable in macro, let say 'numberRequest' and write in a macro:

IF numberRequest=1 THEN GOSUB 'SubRoutine 1'
IF numberRequest=2 THEN GOSUB 'SubRoutine 2'
IF numberRequest=3 THEN GOSUB 'SubRoutine 3'

When you call your macro, write:

CALL 'Subroutine Macro' PARAMETERS numberRequest=1
CALL 'Subroutine Macro' PARAMETERS numberRequest=2
CALL 'Subroutine Macro' PARAMETERS numberRequest=3

This way you can call the same macro but in each case different subroutine. The END at the end of the script, but before subroutines scripts, does not interfere with macro call, because at the point of end script is stopping and subroutine requests and executions happen before script ends.
dushyant
Enthusiast
I want to return the subroutine itself from the macro, which I can then run in the caller object as: GOSUB returnedSubroutine
Podolsky
Ace
How can you imagine it? Return subroutine like macro returning variables? Why the option I propose is not working for you?
dushyant
Enthusiast
It works, but it does not update the 2D view in the Object Settings dialog when I change some options. Only after I hit OK, does it show the result of the changed sub in the plan.
The caller obj calls a macro in Parameters script passing an int value, and the macro then derives the name of the sub to call (apart from other things), and returns it to the caller obj. The caller obj then calls another macro (from 2D script) containing the subs to generate 2D symbols, passing the name of the sub, pen, etc.
If the subs were in the caller obj, they updated in the 2D preview of the Obj Settings dialog.
That's the scenario roughly..
I might be having the sequence to the CALLs wrong..
dushyant
Enthusiast
Podolsky,
Nevermind, it works.
Thanks.
Podolsky
Ace
There is similar problem with 2d preview update, if you want to show different content of 2d preview depends on page number. For example you want to determinate polygon nodes and when you go to nodes page, that in preview the polygon would be shown with a numbers next to polygon. Or openings in polygon with different colour. By default - when you go from page to page 2d preview is not updating. I was trying to solve different ways and finally have decided just add a button saying ‘update 2d preview’.
In all these cases it’s necessary to understand what script exactly doing in this moment of time and if logically looks, that it cannot perform some operation with additional input - add some button that can help to resolve it. It’s same logic like with editing curtain wall. Exists ‘edit’ button you need to hit to enable additional function.
Peter Baksa
Graphisoft
Graphisoft
It is not possible to export a subroutine from a macro.
You might pass around a label of a subroutine as a string or int, but the one in the code that uses gosub/goto will be used, not the macro's that returned it.

There are two ways to solve this:
- have a subroutine collection in a macro, all their inputs as parameters plus a parameter telling which subroutine to use, and the results returned with the end command. Call the macro instead of the subroutine.
- write each subroutine in a separate macro, they can be called using a string variable for the name
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest
dushyant
Enthusiast
Ok, thanks!

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!