Skip to main content
1-Visitor
November 1, 2010
Question

Can If statement use more than 1 value?

  • November 1, 2010
  • 2 replies
  • 6065 views

Can we do if statements like below that check for 2 things instead of just one?

example:

If ((E2.Ellipse.Segments[1].Pen = RemovePen) or (E2.Ellipse.Segments[1].Pen = RemovePen2))

Create Object_Info E2
Create Object_Attribute "Delete" "String" E2
E2.Info.Attributes["Delete"].Value = "Yes"
End If

I've tried it in a macro and it doesn'[t seem to work. I'm so used to doing this in other macro languages that it didn't occur to me that it might not be possible in Isodraw macros. Can someone confirm this or tell me where my syntax is wrong?

If I separate the if statements they work, but then I have to copy the code between the if and end if for each one which makes the macro much longer.

Thanks to Trevor Hendricks for the orginal macro that I'm altering for this.

    2 replies

    12-Amethyst
    November 1, 2010

    First, thanks for the credit.

    Second, not that I'm aware of. My suggestion would be to move the following lines to a submacro.

    Create Object_Info E2
    Create Object_Attribute "Delete" "String" E2
    E2.Info.Attributes["Delete"].Value = "Yes"

    You could then call this from within each If statement. It's not the cleanest, but would reduce repeated code. Note that you'd like need to change the E2 variable to a global if it isn't already.

    TimSharp1-VisitorAuthor
    1-Visitor
    November 1, 2010

    Thanks Trevor

    I guess I shouldn't moan about missing things, but I just assumed that if statements in any language would work with multiple values.

    Yes your solution will cut down code so I'll do that.

    1-Visitor
    November 2, 2010

    I havn't checked it with your example, but IML should understand these logical operators:

    || (meaning "or")

    && (meaning "and")


    12-Amethyst
    November 2, 2010

    I've been experimenting this morning using the ampersands and pipes, but no luck. Could you provide a simple example of the sytax to use?

    1-Visitor
    November 2, 2010

    This might not make much sense, but show the syntax:

    Macro UseBooleanOperators
    Define e as Element

    e = activeDoc.firstSelectedElement

    if ( (e.type="Outer_thread") || (e.type="Inner_thread") ) then
    Message "Element is a thread."
    End If

    if ( (e.type="Group") && (exists(e.info)=true) ) then
    Message "Group is an object."
    End If

    End Macro