Skip to main content
1-Visitor
Mar 23, 2011 12:05 PM UTC
Question

How can I access current settings and change them back again after a macro?

Looking back at some of my older macros I see that in several of them I change things in Isodraw to suit the macro but once the macro is finished, the changed attributes remain, they are not put back to their former state.

For example I have one that adds text to a drawing and sets:

Text size 7
Text align base_line right

Doing this of course leaves the text size at 7 and text align at base_line right regardless of what they were before the macro was run.

What should really be done is to make a variable of the existing text size and alignment settings, so that they can be set back as they were at the end of the macro.

Trouble is I don't know how to extract these values. I'm sure there should be a way, but I can't find it in Macro help.

    13 replies

    12-Amethyst
    Mar 23, 2011 2:55 PM UTC

    What you're requesting could be simple, or it could be difficult. It just depends.

    For your example, it's kind of a loaded question. My suggestion would be to set up a new pen with the settings you desire and the normal pen alone. That way, to switch back, just select the pen you had selected before running the macro (use a variable to capture the pen name before starting the macro).

    This approach could change for things such as controlling a CGM export. You could capture the settings in variables before changing them and then just set them back.

    So, to simplify, or rather not, it depends.

    Translate
    12-Amethyst
    Mar 23, 2011 2:57 PM UTC

    Another quick note. Remember "Select None". If you start fooling with font stuff and happen to have a text element selected, you'll change that element. So make sure to include a "Select None" statement before changing your fonts.

    Translate
    TimSharp1-VisitorAuthor
    1-Visitor
    Mar 23, 2011 3:25 PM UTC

    I didn't really want to create new styles.

    We only use 1 text style, just changing the size as required. Similarly for callouts - we just use 1 style and macros to change end dots on or off as required. That way we don't have to keep changing the style as we add callouts, we can just select a group of callouts to change afterwards and click the macro.

    I guess there wouldn't be any problems creating a new style for the macro, but I was hoping there was a way to extract current settings for 'Normal' types so they could be changed for the macro and changed back again afterwards.

    Thanks for the reminder about Select None. We've been using this macro for years without that in, so it's probably caught a few people out - though no-one's said.

    Translate
    12-Amethyst
    Mar 23, 2011 3:29 PM UTC

    Based on your description then, you could write a text element, grab the settings using the element reference, and then change the text settings as desired. Select None when done and then reset your text settings to their originals.

    Translate
    1-Visitor
    Mar 24, 2011 5:30 AM UTC

    Hi

    You can create a macro based on editing the preference to current settings and add it at the end of each macro you use.....

    Translate
    TimSharp1-VisitorAuthor
    1-Visitor
    Mar 24, 2011 3:26 PM UTC

    Yes good, that's what I was trying to do. The problem is I can't find a way to extract the current settings for everything - for example, how do you check what the current text size and alignments are? You can set them OK by just using Text size and Text align, but I haven't found a way of checking their existing settings.

    Translate
    1-Visitor
    Mar 25, 2011 4:45 AM UTC

    Hi,

    I would like to know whether u would like to retain the Edit----> Prefrence settings (or) pens, layers , line style etc.

    If so you must note each and every setting values from the Preference menu and Layer window and so on.

    Run ur macro.

    Check for what all are the changes made in preference menu after running the macro.

    keeping that changes write macro to change it to ur old preference which u noted.

    I am sorry, without seeing what are all the changes ur macro does, i cannot give a clear reply.

    Thks & Regards

    Vaduga

    Translate
    1-Visitor
    Mar 31, 2011 5:48 PM UTC

    Here is a real sloppy way to find out a font size.

    We use fonts between sizes between 7 and 24, if I run this it stops on the first font size that matches and I hold that value as (i) until the end of the macro, then at the of the macro I use

    Select if type is equal to text

    Text size i

    Macro Text Size

    Define el as Element

    Define i as integer

    for i = 7 to 24

    Select if Font_size is equal to i if (exists (activeDoc.firstSelectedElement) = False) then

    i = i + 1

    end for

    else

    Message "Font Size is"+i

    End Macro

    Translate
    TimSharp1-VisitorAuthor
    1-Visitor
    Apr 8, 2011 7:27 AM UTC

    Thanks, that way will at least change the font back to a size that's already used on the current drawing.

    Actually we only tend to use 2 font sizes so I could just set it back to the other font size when the macro's run.

    I would just like to leave things unaffected when my macros run so that people aren't confused when they later re-use something the macro has changed. I'd have thought that as you can set the text size, you'd be able to check what the current size is as well.

    Translate