Skip to main content
1-Visitor
December 7, 2010
Question

How does the macro syntax work? I'm trying to extract variables from element properties

  • December 7, 2010
  • 1 reply
  • 8329 views

As part of a macro, I'm trying to work out the approximate perimiter of a selected ellipse.

I'm falling down right at the start because I don't understand how to extract the information needed to do the working out.

In my macro, the user selects an ellipse. I then want to extract various bits of information from the ellipse

properties in order to work out the approximate perimiter.

Below is an extract of what I've done so far - it is not correct though, as it doesn't work!

macro cylinder_properties
define ellipse_pt as element

define start_angle as string

define me as MouseEvent

me = Wait MouseClick
ellipse_pt = me.ptMMGrid
Select at pt.x pt.y

start_angle = ellipse_pt.ellipse.segments[1].startAngle

#TO TEST IT I JUST WANTED TO DISPLAY ON SCREEN THE VALUE IT'S FOUND FOR start_angle BUT IT GIVES A SYNTAX ERROR
message 'ellipse segment start angle is: ' + start_angle
end macro

I've not figured out yet how you extract data using the language, so can anyone help me?

I find that the lack of any kind of guide to the syntax of the macro language makes things very difficult - why is it so poorly documented? I'm used to having a 'trace' function that allows you to follow what a macro does and pinpoints

where errors occur - is there anything like this in Isodraw?

Any help would be much appreciated.

    1 reply

    12-Amethyst
    December 7, 2010

    The problem with the macro is that the ellipse_pt element is not being set. To correct, insert "ellipse_pt = ActiveDoc.FirstSelectedElement" after your select statement.

    In regards to troubleshoot, though it's not the best, you can go through the menu to Macros | Macros | Debug macro...

    Within this utility you can run a macro line by line monitoring up to three variables while moving through (note that if you are using a local variable, you can't select until you've defined it).

    TimSharp1-VisitorAuthor
    1-Visitor
    December 8, 2010

    Thanks for your help Trevor.

    Unfortunately I did have the ellipse_pt = ActiveDoc.FirstSelectedElement statement in my macro, I just missed copying it to my post in my effort to cut it down to just the relevant bits of code!

    I have noticed that I don't get the error if I select an ellipse before I run the macro. If I don't select it first, then I get the error, suggesting that the macro won't select the ellipse in the wait mousclick bit. Should I be selecting the ellipse in a different way? We have element points set to magnetic, but do macros not use this?


    macro cylinder_box

    define ellipse_pt as point
    define picked_ellipse as element
    define start_angle as string
    define end_angle as string

    define me as MouseEvent


    me = Wait MouseClick
    ellipse_pt = me.ptMMGrid
    Select at pt.x pt.y

    picked_ellipse = activeDoc.firstSelectedElement
    start_angle = picked_ellipse.ellipse.segments[1].startAngle
    end_angle = picked_ellipse.ellipse.segments[1].endAngle


    #MESSAGE BELOW DOESN'T WORK - SYNTAX ERROR.
    message 'ellipse segment start angle is: ' + start_angle + '. end angle is:' + end_angle

    end macro

    I haven't 'twigged' the rules of this language yet, I wish there was a tutorial somewhere explaining the basics of how it works - perhaps that is a future seminar you could do?

    12-Amethyst
    December 8, 2010

    A couple different approaches.

    Easiest: Select the ellipse and then run the macro.

    2nd option: Put a loop in that checks if the select statement actually selects an ellipse. This will help with the situation you mention above, as well as when a user selects text or a normal line. If you go with this second approach I'd recommend atleast temporarily adjusting the snap distance (I believe the default is 5 pixels) so that selection of the ellipse is easier.

    If you choose the second let me know and I can help with the syntax.