General topic about condtions

General topic about condtions

sanju.p
Enthusiast Enthusiast
1,360 Views
15 Replies
Message 1 of 16

General topic about condtions

sanju.p
Enthusiast
Enthusiast
Hi everyone,

Just for curiosity,

If I have condition like length in between 1000-1500 and height greater than 500.

Now, if and progn condition used.

It's like it check the condition if not satisfied execute the second statement what I have defined.


#main part.

I want that length condtion to be carried out in second statement.
Is it possible...?

Any other conditions can we use for this...?



Thanks in advance
Basic learner.

0 Likes
Accepted solutions (1)
1,361 Views
15 Replies
Replies (15)
Message 2 of 16

thomas.schive
Enthusiast
Enthusiast

Hey, not sure if I completely get what you're asking for here, but I'll try out with something like this ...?

 

(if
    (and
        (<= length 1500)
        (>= length 1000)
        (> height 500)
    )
    (progn
        (command ...)
        (blabla ...)
    )
    ;_else
    (blablabla)
)

 

 

If you're not too happy with using IF, you could also try out with COND!

 

/ts

 

 

 

0 Likes
Message 3 of 16

ВeekeeCZ
Consultant
Consultant

Don't understand you very much, but look at this...

 

(if (> hgh 500)
  (progn
    (if (<= 1000 len 1500)

      (stuff to do... for hgh >500 and len 1000-1500)
      ) ; end of inner if

    (stuff to do... for just  hgh >500)
    ) ; end of progn
  ) ; end of main if

 

Message 4 of 16

sanju.p
Enthusiast
Enthusiast
Thank you for your reply.
In your coding I want length condition to be applied second statement
(else).

In your coding it's not possible.

Correct me if I am wrong.
0 Likes
Message 5 of 16

_gile
Consultant
Consultant

Hi,

 

If you have some difficulties to explain your request in plain English, you can draw and post a flowchart.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 16

sanju.p
Enthusiast
Enthusiast

General procedureGeneral procedureMy requirementMy requirement

0 Likes
Message 7 of 16

sanju.p
Enthusiast
Enthusiast

 

Please check above images, I have clearly mentioned what's to be required.

0 Likes
Message 8 of 16

ВeekeeCZ
Consultant
Consultant

 

Would please STOP posting this photos? Please find some other way to post the text -- the best would be is you use the "Insert code"  button. Or is you have some Latin - Cyrillic issues, you can attach a file as well. 

 

image.png

0 Likes
Message 9 of 16

thomas.schive
Enthusiast
Enthusiast

So ...

 

Is this what you want?

 

1) IF the length is between 1000 and 1500 AND the height is above 500, you would like SOMETHING to happen.

 

2) IF the length is between 1000 and 1500 (no matter what height is), you would like SOMETHING2 to happen.

 

Because now you're like "IF lenght is between 1000 and 1500 and the height is more/equal to 500, let's do this. If that's not true, let's do this and somehow involve the length condition..." I'm sorry but I'm not getting what you want to do here.

 

Couldn't this just be divided into two IF's or COND's, one for each?

 

Am i getting this right? Or is it like BeekeeCZ writes over here? 

 

/ts

 

 

0 Likes
Message 10 of 16

sanju.p
Enthusiast
Enthusiast

Thank you for your suggestions, I am new to the portal.

All these conversations sent by mobile so there is problem.

0 Likes
Message 11 of 16

ВeekeeCZ
Consultant
Consultant
Accepted solution

I this this must be it:

 

(if (and (>= l 1000)
         (<= l 1500))
  (progn
    (if (>= h 500)
      (progn
        (do stuff for h >= 500) ...))   ; L conditions is True, H cond is True
    
    (do stuff for all  l= 1000-1500)))   ;all objects with L condition is True (no matter what height is)

You simply have use 2 condition functions.

Message 12 of 16

Kent1Cooper
Consultant
Consultant

Try this:

 

(if (<= 1000 L 1500)

  (if (> H 500)

    (progn ; then

      (setq higher stuff....)

      (command ...)

    ); progn

    (progn ; else

      (setq lower stuff....)

      (command ...)

    ); progn

  ); if

); if

 

[Note the first test -- you don't need to check for the Length being at or above 1000 and at or below 1500 separately.]

Kent Cooper, AIA
0 Likes
Message 13 of 16

_gile
Consultant
Consultant

Hi,

 

I'll try a "general reply about conditions" illustrated with some flowcharts.

 

First, I will remind the used convention for conditions:

ConditionConvention.png

 

Example 1 (if thenIf else):

FlowchartExample1.png

(if (Condition1)
  (if (Condition2)
    (do stuff for Condition1 = true and Condition2 = true)
    (do stuff for Condition1 = true and Condition2 = false)
  )
  (do stuff for Condition1 = false)
)

 

Example 2 (if then elseIf):

FlowchartExample2.png

(if (Condition1)
  (do stuff for Condition1 = true)
  (if (Condition2)
    (do stuff for Condition1 = false and Condition2 = true)
    (do stuff for Condition1 = false and Condition2 = false)
  )
)

This is typically the case where (cond...) is used.

 

(cond
  ((Condition1) (do stuff for Condition1 = true))
  ((Condition2) (do stuff for Condition1 = false and Condition2 = true))
  (T (do stuff for Condition1 = false and Condition2 = false))
)

 

Exemple 3 (short-circuiting with and):

FlowchartExample3.png

(if (and (Condition1) (Condition2))
  (do stuff for Condition1 = true and Condition2 = true)
  (do stuff for Condition1 = false or Condition2 = false)
)

 

Exemple 4 (short-circuiting with or):

FlowchartExample4.png

(if (or (Condition1) (Condition2))
  (do stuff for Condition1 = true or Condition2 = true)
  (do stuff for Condition1 = false and Condition2 = false)
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 14 of 16

sanju.p
Enthusiast
Enthusiast

Thank you sir for detail flowchart explanation.

I got solution for my requirement.

0 Likes
Message 15 of 16

sanju.p
Enthusiast
Enthusiast

Those who refer it, take care of closing brackets.

0 Likes
Message 16 of 16

ВeekeeCZ
Consultant
Consultant

@sanju.p wrote:

Those who refer it, take care of closing brackets.


 

Since the LISP stands for Lost In Stupid Parenthesis, you are definitely right! 

 

Glad you've found your solution with some effort of yours, next time you would know. 

0 Likes