Skip to main content
1-Visitor
July 22, 2011
Question

Using macros to draw items. How (and where) do you set line type and fill.

  • July 22, 2011
  • 2 replies
  • 4842 views

I'm getting bogged down trying to do something simple.

I'm trying to draw items in a macro, some in "No Pen", some with "Thick" lines and some with white fill

I'm using rectangle, but am having problems both setting the fill type (can't see how this is set) and in getting the pen type to work.

The example below is the simplest way I can show the problem pen problem.

macro testrectangle

Set active pen "No Pen"
create rectangle 9 9 9 19 19 19 19 9
Set active pen "Thick"
create rectangle 10 10 10 20 20 20 20 10
end macro

What I think it should do is draw 1 rectangle in "No Pen" and the 2nd rectangle in "Thick", but what it does is draw both rectangles in thick and thin.

Do rectangles work differently to lines - can't you set the linetype and fill for them in a macro?

    2 replies

    12-Amethyst
    July 22, 2011

    Try this.

    Macro Test_Rectangle

    Select None

    Create Rectangle 9 9 9 19 19 19 19 9
    Set Active Pen "No Pen"

    Select None
    Create Rectangle 10 10 10 20 20 20 20 10

    Set active pen "Thick"
    Select None
    End macro

    A couple things. When you use set active pen, it not only changes your active pen but also whatever you have selected. Use this to your advantage. Draw the object and then apply the pen.

    In your original sample, both pens would be the same because you draw one, change the pen which changes the one you just drew, and then you draw a new one. Use select none a lot.

    In regards to the thick/thin, it appears to be a default. You could like make a call to shut off drawing the thick/thin line (check your preferences for this setting). I'm guessing (Haven't tested) that this should resolve it.

    TimSharp1-VisitorAuthor
    1-Visitor
    July 22, 2011

    Thanks Trevor, helpful as always.

    Trouble is that to make my example as simple as possible, I removed a lot of the coding. If I put that back in, along with the "select none"'s that were already there, it still doesn't work.

    I start a group before drawing the first bit of geometry, ending it after drawing the last bit. I guess the "select none" command is being ignored if it's inside the "start group" command:

    Macro Test_Rectangle


    start group

    Select None

    Create Rectangle 9 9 9 19 19 19 19 9
    Set Active Pen "No Pen"

    Select None
    Create Rectangle 10 10 10 20 20 20 20 10

    Set active pen "Thick"
    Select None

    end group

    end macro

    Suppose I'll have to add some infos to each bit of geometry and then select them by the infos later to group them. I wonder why do they make things so difficult in IML?

    12-Amethyst
    July 22, 2011

    Ah, groups. Yes, I've experimented with those and despised that function. In that case, your approach of selecting after and then grouping likely is the best option. Good luck.

    1-Visitor
    July 22, 2011

    Hi tim,

    See whether this will be Helpful.........

    Macro dsf
    Set Active Pen "Thin"
    start group
    Create Rectangle 9 9 9 19 19 19 19 9
    Create Rectangle 10 10 10 20 20 20 20 10
    Select None
    end group
    UNGROUP SELECTION deep
    Define el as element
    el = activeDoc.firstSelectedElement
    el.Rect.segments[1].pen = "Thin"
    el.Rect.segments[2].pen = "Thin"
    el.Rect.segments[3].pen = "Thin"
    el.Rect.segments[4].pen = "Thin"
    cut
    PASTE same_position
    Group selection
    End macro

    1-Visitor
    July 22, 2011

    I think after ungrouping you can provide specific attribute values and then select using the attribute values,

    apply thin, thick,

    then Group

    1-Visitor
    July 22, 2011

    Some Changes

    Macro dsf
    Set Active Pen "Thin"
    start group
    Create Rectangle 9 9 9 19 19 19 19 9
    Create Rectangle 10 10 10 20 20 20 20 10
    Select None
    end group
    UNGROUP SELECTION deep
    Define el as element
    el = activeDoc.firstSelectedElement
    el.Rect.segments[1].pen = "Thin"
    el.Rect.segments[2].pen = "Thin"
    el.Rect.segments[3].pen = "Thin"
    el.Rect.segments[4].pen = "Thin"
    el = el.nextSelectedElement
    el.Rect.segments[1].pen = "Thick"
    el.Rect.segments[2].pen = "Thick"
    el.Rect.segments[3].pen = "Thick"
    el.Rect.segments[4].pen = "Thick"
    cut
    PASTE same_position
    Group selection
    end macro