cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Participant

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

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.

Tags (1)
11 REPLIES 11

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

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).

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

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?

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

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.

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

Thanks again Trevor

I don't want people to have to select the ellipse first - I want to learn the macro language.

I've added a bit in to check the current grid radius (so I can set it back at the end of the macro), then set it bigger for the macro, but it still doesn't select the ellipse.

I did put in a while loop to check that an ellipse was selected but as it never selects it when running the macro, it got stuck in an endless loop (how do you get out of those?)

I appreciate your help and I'm determined to be able to understand the way the macro language works.

The (selected) macro again:

macro cylinder_box

define ellipse_pt as element
define picked_ellipse as element

define start_angle as string
define end_angle as string

define me as MouseEvent
define current_document as document

define current_grid_rad as string

#GETS CURRENT GRID RADIUS

current_grid_rad = current_document.grid.radius

#SETS TEMPORARY GRID RADIUS

current_document.grid.radius = 15

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 ONLY WORKS WHEN ELLIPSE IS SELECTED BEFORE RUNNING MACRO, OTHERWISE SYNTAX ERROR
message 'ellipse segment start angle is: ' + start_angle + '. end angle is:' + end_angle

#SETS GRID RADIUS BACK AS BEFORE

current_document.grid.radius = current_grid_rad

end macro

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

Glad you want to learn. I have to admit that when I worked with yours yesterday that I commented out the select function and just had the ellipse selected. I won't do that again.

Give me a bit and I'll see if I can get it working the way you desire. Comments will be available so you can see how it works.

In regards to endless loops, the only way I've figured it is using "tskill isodraw7.1" at the run command in WindowsXP. Not a great way, but effective.

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

Attached is a working macro giving you starting and ending angles for the first segment of an ellipse.

As a note, I saw a couple issues to keep in mind.

First, the defining of a variable (global or local), just makes a placeholder. You then need to set it's value after defining it. As an example, your current_document was defined as a document. Good start. Problem that occurred was that it was never specified as a what document. IsoDraw expected a document but didn't know what one to work with.

In regards to selection, I forgot about this until I started working. The best method I found was using me.ptmm.x or me.ptmm.y. Didn't have problems. I also included the Direct statement at the end of the select command to make sure that if you were working with groups, you would only select the ellipse.

The grad radius setting is currently set to 10 in the attached macro. We stuck with the default 5, but you may want to play around with this setting. If you are working with more complex art, a smaller setting might be appropriate. Also note that this is based on pixels. Translation: The more you zoom out, the more area on your page you'll actually be grabbing from.

Hope this helps. If you have questions, let me know.

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

Thanks very much Trevor, you've made things clearer.

I see now that I didn't set a value for current document (basic error) though in your example it looks like I didn't need to use it at all because ActiveDoc is always available?

Your way of selecting works fine. Perhaps the way I had it didn't take account of the grid radius setting, because it never seemed to select an ellipse. I probably won't even need to change the grid radius at all using your method.

So thanks to you I've now learned how to select from the drawing and how to extract information from selected items - I'm getting somewhere.

I did program using ME10's macro language for over 20 years (15 of them full time) but as that's the only programming language I know, I'm constantly comparing the Isodraw one to that and it comes up way short all the time as it's missing so many things that allow you to work effectively, such as a menu system, error trapping, logical tables, in fact it seems that obstacles (or probably more likely omissions) are everywhere to make achieving simple things difficult. I find the lack of documentation doesn't help me understand how to string the commands together - just a simple syntax guide would make a huge difference.

Do you know if there are any plans to extent the macro language?

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

In regards to ActiveDoc, it's something I use regularly. The majority of the time it will handle what I need it to. The only time I've had to set a variable to a document (I still use ActiveDoc for the actual initial setting) is when I have a need to have two files open and have to switch back and forth.

In regards to syntax help, the help menu in IsoDraw has a good listing. It's not perfect, but once you get the idea of how it's written it becomes much clearer. I know, when I started, my biggest issue was when a sample would say something like myEl, representing an element, and it wouldn't tell you to set it. Once you realize that each section starts with a basic setup, the samples after only show you the appropriate line for that particular example. You still end up needing the original code.

In regards to expanding the language...no idea. But I assume they will. Some issues mentioned in the forum in the last two years ended up being introduced (and sometimes just documented as it was available in 7.0) in 7.1. Items such as error capture are now listed.

Which version of IsoDraw are you using? If you're on 7.0, there are some features that were available, but not covered in the guide. The 7.1 documents actually specify these type of items.

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

Yes ActiveDoc should do me for most things.

In ME10 there was no adding variable names to commands or functions so I just didn't understand this to start with - I still don't get the reason for it.

I'll have a think about macro features that I used to rely on and see if PTC would consider adding them to Isodraw.

A few that come to mind, just from doing this one macro:

A prompt feature - my macro needs the user to pick 3 points on the drawing, but there's no way of prompting for this without using the message function which requires the user to click OK to close it and then pick the point, making it unwieldy.

More enquiry functions on picked items:

1st example, I'm working out the approximate circumference of an ellipse but the data it gives you does not allow you to work it out directly (need major axis - given OK and minor axis - not given).

2nd example, The user picks a line and I just want the length of the line. You have to get x and y start and end points and work it all out from those.

An interactive menu function would be great as well. The menu built like a table with functions in the slots for displaying text, running a macro and displaying the value of a variable.

Do you think PTC would be interested in a complete review of what's needed to make the macro language truly useable? I guess they started with a simple record function for macros and have added some extras but not gone for a fully featured language - yet.

We're still using 7.0 here. We tried 7.1 for about a week but got into such a mess with filenames using the changed save function that we couldn't live with it. I'm guessing that this function has been changed back again, but I don't think there's enough in 7.1 to make it worth the hassle of upgrading. It's high time for version 8 now I think after 3 years, with all the maintenance we pay! We do use the excellent Thumbnailer though.

Thanks again, it's good to know there's some help out there.

Announcements