Author Topic: Check line for accuracy  (Read 11861 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Check line for accuracy
« on: February 22, 2007, 09:39:58 AM »

I am in need of some direction. I want to be able to check all lines in a drawing for for accuracy. (i.e. straight versus crooked lines). Please see picture.
Basically I want to be able to run a check on an entire drawing and have it check all lines for accuracy within a given tolerance of say 3 degrees from being straight and once found annotate them with somehow so that the user can go back through the drawing and correct accordingly if needed.

Any assistance is greatly appreciated.


AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

GDF

  • Water Moccasin
  • Posts: 2081
Re: Check line for accuracy
« Reply #1 on: February 22, 2007, 10:46:53 AM »
Check out this routine.

;;;SNAPLINE.LSP   Rectify Lines   (c)1998, Galen A. Light

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Check line for accuracy
« Reply #2 on: February 22, 2007, 10:48:57 AM »
You could always just do the math...http://www.theswamp.org/index.php?topic=5203.0



TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Check line for accuracy
« Reply #3 on: February 22, 2007, 10:50:42 AM »
Looks like it would be a fun project for some of the swampers! :-)

TheSwamp.org  (serving the CAD community since 2003)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #4 on: February 22, 2007, 11:11:24 AM »
Code: [Select]
(vlax-for Lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (vlax-for Obj (vla-get-Block Lo)
  (if
   (and
    (= (vla-get-ObjectName Obj) "AcDbLine")
    (not
     (or
      (equal (vla-get-Angle Obj) 0.0 0.05)
      (equal (vla-get-Angle Obj) (* pi 0.5) 0.05)
      (equal (vla-get-Angle Obj) pi 0.05)
      (equal (vla-get-Angle Obj) (* pi 1.5) 0.05)
     )
    )
   )
   (vla-put-Color Obj 121)
  )
 )
)

??
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Check line for accuracy
« Reply #5 on: February 22, 2007, 12:46:47 PM »

An example. I have this for for the propoerties of a line...

Command:  LIST
Select objects: 1 found

Quote
Command:  LIST
Select objects: 1 found

Select objects:
                  LINE      Layer: "A-WALL-TENT-EXST"
                            Space: Model space
                   Handle = CF05
              from point, X=154'-3 1/2"  Y=208'-1 1/8"  Z=    0'-0"
                to point, X=180'-8 3/4"  Y=208'-1 1/2"  Z=    0'-0"
          Length =26'-5 1/4",  Angle in XY Plane = 0.06453059
                  Delta X =26'-5 1/4", Delta Y = 0'-0 3/8", Delta Z =    0'-0

The Angle in the XY plane is off from being "0" by a very small amount. These are the types of lines that I want to be able to search for. In this case it is off by less than a degree.

The supplied code from T.Willey did not catch this line as being incorrect.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #6 on: February 22, 2007, 12:58:02 PM »

I am in need of some direction. I want to be able to check all lines in a drawing for for accuracy. (i.e. straight versus crooked lines). Please see picture.
Basically I want to be able to run a check on an entire drawing and have it check all lines for accuracy within a given tolerance of say 3 degrees from being straight and once found annotate them with somehow so that the user can go back through the drawing and correct accordingly if needed.

Any assistance is greatly appreciated.



This is what I went off of.  If you want a smaller tolerance, then change these lines in the code.
Code: [Select]
     (or
      (equal (vla-get-Angle Obj) 0.0 0.05)
      (equal (vla-get-Angle Obj) (* pi 0.5) 0.05)
      (equal (vla-get-Angle Obj) pi 0.05)
      (equal (vla-get-Angle Obj) (* pi 1.5) 0.05)
     )
* don't forget that the angle is in radians.  That is how I got the 0.05
Quote
Command: (* (/ 3.0 180.0) pi)
0.0523599
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Check line for accuracy
« Reply #7 on: February 22, 2007, 02:41:45 PM »
Try this one ...

Code: [Select]
(defun c:checklines ( / ss cntr new_ss x y ang ent )

  (defun check_angle (ang)
    (cond
      ((= ang (* pi 0.5)) T) ; up
      ((= ang (* pi 1.0)) T) ; left
      ((= ang (* pi 1.5)) T) ; down
      ((= ang 0.0) T) ; zero
      )
    )

  (sssetfirst nil)

  (setq ss (ssget "X" '((0 . "LINE")))
cntr 0
new_ss (ssadd)
)

  (if (not (zerop (sslength ss)))
    (while (setq ent (ssname ss cntr))
   (setq x (cdr (assoc 10 (entget ent)))
y (cdr (assoc 11 (entget ent)))
ang (angle x y)
)
   (if (not (check_angle ang))
     (ssadd ent new_ss)
     )

   (setq cntr (1+ cntr))


   );while

    );if

  (if (not (zerop (sslength new_ss)))
    (sssetfirst nil new_ss)
    )

  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #8 on: February 23, 2007, 12:42:12 AM »
Code: [Select]
     (or
      (equal (vla-get-Angle Obj) 0.0 0.05)
      (equal (vla-get-Angle Obj) (* pi 0.5) 0.05)
      (equal (vla-get-Angle Obj) pi 0.05)
      (equal (vla-get-Angle Obj) (* pi 1.5) 0.05)
     )

My variant:

Code: [Select]
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )
« Last Edit: February 23, 2007, 12:44:05 AM by ElpanovEvgeniy »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #9 on: February 23, 2007, 02:56:17 AM »
Try this one ...

Code: [Select]
(defun c:checklines ( / ss cntr new_ss x y ang ent )

  (defun check_angle (ang)
    (cond
      ((= ang (* pi 0.5)) T) ; up
      ((= ang (* pi 1.0)) T) ; left
      ((= ang (* pi 1.5)) T) ; down
      ((= ang 0.0) T) ; zero
      )
    )

  (sssetfirst nil)

  (setq ss (ssget "X" '((0 . "LINE")))
cntr 0
new_ss (ssadd)
)

  (if (not (zerop (sslength ss)))
    (while (setq ent (ssname ss cntr))
   (setq x (cdr (assoc 10 (entget ent)))
y (cdr (assoc 11 (entget ent)))
ang (angle x y)
)
   (if (not (check_angle ang))
     (ssadd ent new_ss)
     )

   (setq cntr (1+ cntr))


   );while

    );if

  (if (not (zerop (sslength new_ss)))
    (sssetfirst nil new_ss)
    )

  (princ)
  )


If at check of a corner, it is not necessary to set accuracy (fuzz)
It is enough to check up:

Code: [Select]
(or
 (= (- x1 x2) 0.)
 (= (- y1 y2) 0.)
 )

For example:

Code: [Select]
(vl-some
 (function equal)
 (mapcar (function -)
         (cdr (assoc 10 (entget e)))
         (cdr (assoc 11 (entget e)))
         '(0 0)
 ) ;_  mapcar
 '(0. 0.)
 '(1e-8 1e-8)
) ;_  vl-some

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #10 on: February 23, 2007, 11:05:44 AM »
Code: [Select]
     (or
      (equal (vla-get-Angle Obj) 0.0 0.05)
      (equal (vla-get-Angle Obj) (* pi 0.5) 0.05)
      (equal (vla-get-Angle Obj) pi 0.05)
      (equal (vla-get-Angle Obj) (* pi 1.5) 0.05)
     )

My variant:

Code: [Select]
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

You're math skills are better than mine, so I will just assume you are correct.  Nice short compact test Evgeniy.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #11 on: February 23, 2007, 11:47:22 AM »
Quote
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

I think there's a mistake, except if a equals pi/2 or 3pi/2 (fix (sin a)) will always return 0.0.

Example: if a equals pi/120 radians (very closed to 0.0°), it works

Quote
_$ (setq a (/ pi 120))
0.0261799
_$ (sin a)
0.0261769
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
T

But, if a is pi/2 + pi/120 radians (very closed to 90.0°), it don't work.

Quote
_$ (setq a (+ (/ pi 2) (/ pi 120)))
1.59698
_$ (sin a)
0.999657
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
nil

Evgeniy's code should be right whith '=' or 'eq' functions, but can't be used with 'equal' and a 'fuzz'.
« Last Edit: February 23, 2007, 11:50:05 AM by gile »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #12 on: February 23, 2007, 12:18:58 PM »
Another version, less compact, but semms to work

Code: [Select]
((lambda (a)
   (or
     (equal (sin a) 0.0 0.05)
     (equal (abs (sin a)) 1.0 0.05)
   )
 )
  (vla-get-Angle Obj)
)
Speaking English as a French Frog

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Check line for accuracy
« Reply #13 on: February 23, 2007, 12:54:16 PM »

Thanks for all of the responses. Great work. All of the posted code seems to find all lines that are greatly at an angle but not find others that are off just so slightly.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #14 on: February 23, 2007, 12:56:18 PM »
Quote
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

I think there's a mistake, except if a equals pi/2 or 3pi/2 (fix (sin a)) will always return 0.0.

Example: if a equals pi/120 radians (very closed to 0.0°), it works

Quote
_$ (setq a (/ pi 120))
0.0261799
_$ (sin a)
0.0261769
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
T

But, if a is pi/2 + pi/120 radians (very closed to 90.0°), it don't work.

Quote
_$ (setq a (+ (/ pi 2) (/ pi 120)))
1.59698
_$ (sin a)
0.999657
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
nil

Evgeniy's code should be right whith '=' or 'eq' functions, but can't be used with 'equal' and a 'fuzz'.

I am sorry! :oops:
I have hastened and have badly expressed the idea...
Many thanks gile! You have corrected me.

In my example, it is necessary to use
Code: [Select]
(fix (+ (sin a) 0.5))
Then all example will look:

Code: [Select]
((lambda (a) (equal (sin a) (fix (+(sin a)0.5)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )