2021-07-0504:45 AM - last edited on 2021-09-1412:02 AM by Noemi Balogh
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.
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.
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..
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.
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