Author Topic: How does 'Equal' work ...  (Read 2575 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
How does 'Equal' work ...
« on: July 01, 2010, 01:07:30 PM »
Good Morning everyone,

I am having a bit of a dilemma regarding the use of 'Equal' and also the use of the operator 'less than' (<).

My story:  I have several arcs in a drawing that are displayed as nothing more than points.  At a closer look, these arcs are basically with a zero length.  So I'm trying to replace them with circles (which they should be anyway - long story) and this is where I am having my issue.

Here's what I'm doing:
Code: [Select]
(setq origLayr (getvar "clayer")
        origColr (getvar "cecolor")
        origLTyp (getvar "celtype")
        origLWgt (getvar "celweight")
        i -1
        SS (ssget '((0 . "ARC"))) ; "_X"
  )
  (while (setq Obj (ssname SS (setq i (1+ i))))
    (if (setq eList (entget Obj))
      (progn
        (setq objAnglS (cdr (assoc 50 eList))
              objAnglE (cdr (assoc 51 eList)))
        (if [color=red](= (equal ArcAnglS ArcAnglE 0.001) T)[/color] ; or
;            [color=green](and (> ArcAnglS 0.25)(> ArcAnglE 0.25))[/color]
          (progn
            (setq objLayr (cdr (assoc 8 eList))
                  objColr (cdr (assoc 62 eList))
                  objLTyp (cdr (assoc 6 eList))
                  objLWgt (cdr (assoc 370 eList))
                  objCtrPT (cdr (assoc 10 eList))
                  objRad (cdr (assoc 40 eList))
            )
            (if (= objColr nil)
              (setvar "cecolor" "ByLayer")
              (progn
                (setq objColr (itoa objColr))
                (setvar "cecolor" objColr)
              )
            )
            (if (= objLWgt nil)
              (setvar "celweight" -1)
              (setvar "celweight" objLWgt)
            )
            (if (= objLTyp nil)
              (setvar "celtype" "ByLayer")
              (setvar "celtype" objLTyp)
            )
            (setvar "clayer" objLayr)
            (command ".circle" objCtrPT objRad)
            (command ".erase" Obj "")
          ) ; progn
        ) ; if
      ) ; progn
    ) ; if
  ) ; while

Initially, I had several arcs that had a length (DXF 50 & 51) of 0.000.  So I was using the code above in green.  But I had to reverse the operator in order to get it to work.  So the 'ArcAnglS' and 'ArcAnglE' had to be Greater than the 0.25 in order for the routine to recognize arcs smaller than 0.25.   I don't know why.

Then on a second drawing I came across these arcs and had to change my code to what is now in red above:
Quote
Select object: ((-1 . <Entity name: 7ebb88f0>) (0 . "ARC") (330 . <Entity name:
7e935ee8>) (5 . "10A4E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (62 . 0) (100 . "AcDbCircle") (10 3212.39 1104.38 0.0) (40 . 2.25014) (210
0.0 0.0 1.0) (100 . "AcDbArc") (50 . 2.00662) (51 . 2.00662))
Quote
Select object: ((-1 . <Entity name: 7ebb8910>) (0 . "ARC") (330 . <Entity name:
7e935ee8>) (5 . "10A52") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (62 . 0) (100 . "AcDbCircle") (10 3235.45 1075.96 0.0) (40 . 0.750047)
(210 0.0 0.0 1.0) (100 . "AcDbArc") (50 . 0.435826) (51 . 0.435826))

So being zero length arcs, it makes sense to 'Equal' the two points
Code: [Select]
(equal ArcAnglS ArcAnglE 0.001)
But the code is running regardless of whether the two variables are equal or not.
If I set the code to this:
Code: [Select]
(if [color=red](/= (equal ArcAnglS ArcAnglE 0.001) T)[/color]Then the 'If' statement does not run, WHEN IT SHOULD.

I'm hoping you guys can see some stupid mistake on my part and show me, because I feel like I'm losing my mind.  I'm beginning to write code in reverse of what should be.  'Greater than' is now 'Less than', 'Equal' is now '/=', etc.

Thanks for your help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

hmspe

  • Bull Frog
  • Posts: 362
Re: How does 'Equal' work ...
« Reply #1 on: July 01, 2010, 01:24:50 PM »
I don't think you need both  =  and   equal.  I'd try
Code: [Select]
(if (equal ArcAnglS ArcAnglE 0.001)
  (progn
"Science is the belief in the ignorance of experts." - Richard Feynman

Hangman

  • Swamp Rat
  • Posts: 566
Re: How does 'Equal' work ...
« Reply #2 on: July 01, 2010, 01:39:43 PM »
I don't think you need both  =  and   equal.  I'd try
Code: [Select]
(if (equal ArcAnglS ArcAnglE 0.001)
  (progn

I had it that way initially, but it wasn't doing what I thought it was suppose to do, verify the equality of the two variables.
So I thought perhaps if it was equal to its return it would work, so I put in the '=' and 'T'.  Didn't help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LE3

  • Guest
Re: How does 'Equal' work ...
« Reply #3 on: July 01, 2010, 01:49:53 PM »
I recall using this to compare two angles for equality, but not sure if it the latest, have not used this function in years..., maybe:
Code: [Select]
(defun rcmd-isAngle-equal  (a b)
  (or (equal (angtos a) (angtos b) 0.0001)
      (equal (angtos a) (angtos (+ b pi)) 0.0001)
      (equal (angtos (+ a pi)) (angtos b) 0.0001)))

Hangman

  • Swamp Rat
  • Posts: 566
Re: How does 'Equal' work ...
« Reply #4 on: July 01, 2010, 02:05:44 PM »
I recall using this to compare two angles for equality, but not sure if it the latest, have not used this function in years..., maybe:
Code: [Select]
(defun rcmd-isAngle-equal  (a b)
  (or (equal (angtos a) (angtos b) 0.0001)
      (equal (angtos a) (angtos (+ b pi)) 0.0001)
      (equal (angtos (+ a pi)) (angtos b) 0.0001)))

I'm sure this does compare two angles.  But that's not what I'm doing here.  Sorry for the confusion, my variables 'ArcAnglS' and 'ArcAnglE' are named after the help file description of DXF code 50 (arc Start angle) and 51 (arc End angle).

I'm just trying to figure out how to identify if two numbers (real) are equal or really close to it.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LE3

  • Guest
Re: How does 'Equal' work ...
« Reply #5 on: July 01, 2010, 02:10:48 PM »
post the return value of both variables, it might help others of what type of values you are getting.


I recall using this to compare two angles for equality, but not sure if it the latest, have not used this function in years..., maybe:
Code: [Select]
(defun rcmd-isAngle-equal  (a b)
  (or (equal (angtos a) (angtos b) 0.0001)
      (equal (angtos a) (angtos (+ b pi)) 0.0001)
      (equal (angtos (+ a pi)) (angtos b) 0.0001)))

I'm sure this does compare two angles.  But that's not what I'm doing here.  Sorry for the confusion, my variables 'ArcAnglS' and 'ArcAnglE' are named after the help file description of DXF code 50 (arc Start angle) and 51 (arc End angle).

I'm just trying to figure out how to identify if two numbers (real) are equal or really close to it.

Hangman

  • Swamp Rat
  • Posts: 566
Re: How does 'Equal' work ...
« Reply #6 on: July 01, 2010, 06:24:14 PM »
So, there were 40+ views of this post, 3 reply's and I found the dumbest mistake an amateur coder can do.

Oh what an idiot I am.   :realmad: :ugly: :-D

Check this out from my own post:

Good Morning everyone,

I am having a bit of a dilemma regarding the use of 'Equal' ...

My story:  I have several arcs yada yada yada ...

Here's what I'm doing:
Code: [Select]
(setq origLayr (getvar "clayer")
        origColr (getvar "cecolor")
        origLTyp (getvar "celtype")
        origLWgt (getvar "celweight")
        i -1
        SS (ssget '((0 . "ARC"))) ; "_X"
  )
  (while (setq Obj (ssname SS (setq i (1+ i))))
    (if (setq eList (entget Obj))
      (progn
        (setq objAnglS (cdr (assoc 50 eList))
              objAnglE (cdr (assoc 51 eList)))
        (if [color=red](= (equal ArcAnglS ArcAnglE 0.001) T)[/color] ; or
;            [color=green](and (> ArcAnglS 0.25)(> ArcAnglE 0.25))[/color]
          (progn
            (setq objLayr (cdr (assoc 8 eList))
                  objColr (cdr (assoc 62 eList))
                  objLTyp (cdr (assoc 6 eList))
                  objLWgt (cdr (assoc 370 eList))
                  objCtrPT (cdr (assoc 10 eList))
                  objRad (cdr (assoc 40 eList))
            )
            (if (= objColr nil)
              (setvar "cecolor" "ByLayer")
              (progn
                (setq objColr (itoa objColr))
                (setvar "cecolor" objColr)
              )
            )
            (if (= objLWgt nil)
              (setvar "celweight" -1)
              (setvar "celweight" objLWgt)
            )
            (if (= objLTyp nil)
              (setvar "celtype" "ByLayer")
              (setvar "celtype" objLTyp)
            )
            (setvar "clayer" objLayr)
            (command ".circle" objCtrPT objRad)
            (command ".erase" Obj "")
          ) ; progn
        ) ; if
      ) ; progn
    ) ; if
  ) ; while

< ... >

Notice the code in RED.
Now look at the two variables declared just above that.

No wonder the stupid thing isn't working.  I'm declaring the WRONG VARIABLES !!    :pissed:   beating head against wall



It was LE3's request to post the values that enlightened me.

So let that be a lesson to you all, verify your variables before wasting everyones time !!

Sorry guys, my bad.     :oops:
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How does 'Equal' work ...
« Reply #7 on: July 02, 2010, 08:20:56 AM »
When debugging with VLIDE it is a simple matter to step through the code while looking at the values of those variables.
If you did that you would see there was a problem with the variable values and that would narrow your search for an answer.

My 2 cents. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How does 'Equal' work ...
« Reply #8 on: July 02, 2010, 10:40:39 AM »

When debugging with VLIDE it is a simple matter to step through the code while looking at the values of those variables.
If you did that you would see there was a problem with the variable values and that would narrow your search for an answer.

My 2 cents. :)


But He can't do that Alan ...

<  .. >
No wonder my code is crap, I use Notepad++ for most all of my editing.   :wink:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: How does 'Equal' work ...
« Reply #9 on: July 02, 2010, 10:50:41 AM »

When debugging with VLIDE it is a simple matter to step through the code while looking at the values of those variables.
If you did that you would see there was a problem with the variable values and that would narrow your search for an answer.

My 2 cents. :)

But He can't do that Alan ...

<  .. >
No wonder my code is crap, I use Notepad++ for most all of my editing.   :wink:

Touche Kerry !!    :-D
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~