Author Topic: lisp to check drawing for elements with a z vlaue (ie not flattened)  (Read 5779 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
My second and last question of the day  :-)

We sometimes draw 3d polylines and points with a z value, which are later flattened to produce 2d elevations.
I'm looking for a way of checking whether a drawing has any 3d elements in it during a finalisation process and if there are then the lisp would prompt the user whether this is correct or whether superflatten should be run.

Here is a lisp I hoped would enable this but it doesn't seem to work to well, the extmin and extmax z values variable doesn't seem to be the way to go.
Using this lisp sometimes it says the drawing is flat sometimes not.

Code: [Select]
;; Check Z extents.
(defun c:CZ ( )
  (command "._zoom" "_extents")
  (if
    (and
      (equal 0.0 (caddr (getvar "extmin")) 1e-6)
      (equal 0.0 (caddr (getvar "extmax")) 1e-6)
    )
    (princ "\nDrawing is flat. ")
    (princ "\nDrawing is not flat. ")
  )
  (princ)
) ;end


here is the output between runs, the z value for some reason after the zoom extent are different:

Command: (getvar "extmin")
(505.391 33.6885 0.0)

Command: (getvar "extmax")
(534.838 60.987 0.0)

Command: cz
._zoom
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>: _extents
Command:
Drawing is not flat.

Command: (getvar "extmax")
(534.838 61.0189 3.49246e-008)

Command: (getvar "extmin")
(505.384 33.6729 -0.00152582)

Does anybody have a better method of determining whether there are any entities with a z value other than 0?

Many thanks
P

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
At a glance, why not zoom extents in the LISP?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
At a glance, why not zoom extents in the LISP?
First call.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Hangman

  • Swamp Rat
  • Posts: 566
Quote
At a glance, why not zoom extents in the LISP?

You mean switch to some isometric view or front facing view and then do a zoom extents ??
That would work easily enough I would think.


Here's my take (which isn't much) on getting some Z value points.
Most everything in the selection set of SSGET can be obtained by DXF 10 - 13.  The PLine elevation can be obtained by DXF 38, and I don't know the SPLine or MLine yet.
Code: [Select]
(if (setq i -1
            Objects (ssget "_X" (list (cons 0 "ARC,CIRCLE,ELLIPSE,INSERT,LINE,MTEXT,SOLID,TEXT,LWPOLYLINE,MLINE,SPLINE")
                                      (cons 410 "Model")
                                )
                    )
      )
    (progn
      (while (setq selObject (ssname Objects (setq i (1+ i)))); get first object entity
        (if (setq Entity (cdr (assoc 0 (entget selObject)))); open entity, get 2nd element in list (object type),
          (progn                                        ; get assoc type & DXF code
            (if (setq PTListSS10 (cdr (assoc 10 (entget selObject)))); get assoc 10 point list
              (setq PTListZ10 (car (cdr (cdr PTListSS10))); get Z value of point list
            )
            (if (setq PTListSS11 (cdr (assoc 11 (entget selObject))))
              (setq PTListZ11 (car (cdr (cdr PTListSS11)))
            )
            (if (setq PTListSS12 (cdr (assoc 12 (entget selObject))))
              (setq PTListZ12 (car (cdr (cdr PTListSS12)))
            )
            (if (setq PTListSS13 (cdr (assoc 13 (entget selObject))))
              (setq PTListZ13 (car (cdr (cdr PTListSS13)))
            )
            (if (setq PTListSS38 (cdr (assoc 38 (entget selObject))))
              (setq PTListZ38 (car (cdr PTListSS38))
            )

I'm just getting point values of each entity, I guess if the point is not equal to zero, set it to some other variable and then work some math (if variable 'a' is greater than variable 'b', keep variable 'a', etc.)
Of course I'm only selecting the items in model space, but I know you can set elevations in paper space too.
Hangman  8)

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

Pad

  • Bull Frog
  • Posts: 342
the lisp has zoom extents at the beginning

Is extmin and max a reliable way, I do not know much about it.
The attached drawing has had superflatten run on it but my CZ lisp still says it's not flat.

Command: CZ

Drawing is not flat.

Command: (getvar "extmin")
(505.384 33.6729 -0.00152582)

Command: (getvar "extmax")
(534.838 61.0189 3.49246e-008)

Maybe I just need to add in a bit of fuzz factor?

Attached is the test drawing I've been using.

P

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Missed that - my bad.

Hangman

  • Swamp Rat
  • Posts: 566
Mind you, If I am thinking this through correctly, when using 'extmin' & 'extmax', you are getting the bottom most left corner of the drawing, and the upper most corner of the drawing.  So if something is above zero plane and something below, then you have twice the distance to zero plane.?.  And depending on how far out the drawing goes, the angle of attack would increase ... ?.   When I use a default drawing template, the drawing limits are 0,0 for lower left corner and 1'-0"x0'-9" for upper right corner.  the 'extmax' and 'extmin' however are (getvar "extmax") = (1.0e+020 1.0e+020 1.0e+020) & (getvar "extmin") = (-1.0e+020 -1.0e+020 -1.0e+020), a huge difference.  Granted these two variables are to take only the limits of the drawing, but I don't think using these two variable is the best way to go.
Perhaps my thinking is askew so please correct me.
Hangman  8)

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

Pad

  • Bull Frog
  • Posts: 342
hello Hangman

Sorry I didn't really know what to do with the code you posted before.
Yeah, the extmin and max doesn't seem to work too reliably.
I think it should though, as if the drawing is flat then the 3rd value (the z value) should be 0, but for some reason sometimes it's not.
Bit of a puzzle.  I would love to find a quick and easy way via lisp or whatever just to tell me whether any elements in the model space has a value other than 0.0.
It's so I can stick it an lisp routine along with some other routines which prepare the drawing for issue.

thanks for your interest.

Have a good weekend
Pad

Joe Burke

  • Guest
Pad,

Interesting question. I will play with it.

Agreed, if both Z values are equal to or very close to zero, SuperFlatten should not be needed.

Joe Burke

  • Guest
Pad,

Using 2008.

When I run your CZ routine on your unaltered TEST file I get, "Drawing is flat". Makes sense since the following Z values are within your equal function fuzz factor 1e-6.

Command: (getvar "extmin")
(505.384 33.6573 -3.49182e-008)
Command: (getvar "extmax")
(534.838 61.0041 8.14936e-008)

I don't know why you are getting a different result.

Aside, after running SuperFlatten on your TEST file:

Command: (getvar "extmin")
(505.391 33.6885 0.0)
Command: (getvar "extmax")
(534.838 60.987 0.0)

Pad

  • Bull Frog
  • Posts: 342
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #10 on: May 10, 2010, 05:12:54 AM »
Thanks Jo for having a look at this.

Have found a strange occurrence, using 2005.

Code: [Select]
Command: ucs
Current ucs name:  *TOP*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World]
<World>:
Command: (getvar "extmin")
(505.391 33.6885 0.0)
Command: (getvar "extmax")
(534.838 60.987 0.0)
Command: cz
Drawing is not flat.
Command: (getvar "extmin")
(505.384 33.6729 -0.00152582)
Command: (getvar "extmax")
(534.838 61.0189 3.49246e-008)
Command: ucs
Current ucs name:  *WORLD*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World]
<World>:
Command: (getvar "extmin")
(505.384 33.6729 -0.00152582)
Command: ucs
Current ucs name:  *WORLD*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World]
<World>: top  [color=red] (user entered)[/color]
Command: (getvar "extmin")
(505.384 33.6729 -0.00152582)
Command: (getvar "extmax")
(534.838 61.0189 3.49246e-008)
Command: _-view Enter an option [?/Categorize/lAyer
state/Orthographic/Delete/Restore/Save/Ucs/Window]: _top Regenerating model.  [color=red](set using icon)[/color]
Command: (getvar "extmax")
(534.838 60.987 0.0)
Command: (getvar "extmin")
(505.391 33.6885 0.0)
Command: cz
Drawing is flat.

so have modified the lisp to this:
Code: [Select]
;; Check Z extents.
(defun c:CZ ( )
  (command "zoom" "extents")
(command "_-view" "_top")
;(command "regenall")
  (if
    (and
      (equal 0.0 (caddr (getvar "extmin")) 1e-6)
      (equal 0.0 (caddr (getvar "extmax")) 1e-6)
    )
    (princ "\nDrawing is flat. ")
    (princ "\nDrawing is not flat. ")
  )
  (princ)
) ;end
and it seems to work ok!

Cheers
P
« Last Edit: May 10, 2010, 05:17:08 AM by Pad »

Joe Burke

  • Guest
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #11 on: May 10, 2010, 08:25:35 AM »
I'm happy to hear you found a solution.

Pad

  • Bull Frog
  • Posts: 342
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #12 on: May 14, 2010, 04:56:47 AM »
hello

I wish I knew what I was doing!
I'm a little stuck modifying this lisp. At the moment I have a 'misplaced dot on input'.

here is the lisp:

Code: [Select]
;; Check Z extents.
(defun c:CZ ( superf )

  (command "zoom" "extents")
(command "_-view" "_top")
;(command "regenall")

(initget 1 "Yes No  ")

  (if
    (and
      (equal 0.0 (caddr (getvar "extmin")) 1e-6)
      (equal 0.0 (caddr (getvar "extmax")) 1e-6)
    )
    (princ "\n*** Drawing is flat (2D), continuing on... ***")
    ((setq superf (getkword "\n*** Drawing contains 3D elements *** Would you like to run SUPERFLATTEN? [Yes/<No>]:")))
  )



(cond
  ((= superf "Yes") (prompt "\n Running SUPERFLATTEN, back-up of drawing will be saved with PREFLAT prefix) (C:SAVE_PREFLAT))
( (or (= superf "No") (= superf "") (prompt "\n OK, moving on and leaving drawing as is in 3D..."))

 ; (princ)
) ;end




;SAVE_PRE = save copy of drawing as preflat-state
(defun C:SAVE_PREFLAT ()

(vl-load-com)
(setq AcadObj (vla-get-ActiveDocument (vlax-get-acad-object)))

  (setq File_PreName "PREFLAT-")
  (setq FileName (getvar "DWGNAME"))
  (setq PreFileName (getfiled "Input name of PREFLATTENING drawing to save" (strcat File_PreName FileName) "dwg" 1))
  (if (findfile PrefileName)
    (command "_SAVE" PreFileName "Y")
    (command "_SAVE" PreFileName)
  )
  (princ (strcat "\n" File_PreName "File saved as '" (vl-filename-base PreFileName) "'.\n"))
(c:superflatten)
  (princ)
)

I'm quite sure I have a few things wrong, like the call to run another lisp.  If somebody could show me the error of my ways, I'd be thankful.

Cheers
Pad

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #13 on: May 14, 2010, 07:21:01 AM »


Quote
I wish I knew what I was doing!
I'm a little stuck modifying this lisp. At the moment I have a 'misplaced dot on input'.

Here you go!

Code: [Select]
(defun c:CZ (/ superf)
  (command "zoom" "extents")
  (command "_-view" "_top")
;(command "regenall")

  (initget 1 "Yes No")

  (if
    (and
      (equal 0.0 (caddr (getvar "extmin")) 1e-6)
      (equal 0.0 (caddr (getvar "extmax")) 1e-6)
    )
     (princ "\n*** Drawing is flat (2D), continuing on... ***")
     ((setq superf
     (getkword
       "\n*** Drawing contains 3D elements *** Would you like to run SUPERFLATTEN? [Yes/<No>]:"
     )
      )
     )
  )
);;; added this closing
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #14 on: May 14, 2010, 07:38:00 AM »

Wow, please disregard my post. Obviously not enough coffee this morning!

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