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

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #15 on: May 14, 2010, 07:45:10 AM »
thanks dvarino

i think the problem is now with this cond statement:

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

) ; end cond

but I'm damned if I can figure it out.. :|

save_preflat being this:

;SAVE_PREFLAT = save copy of drawing as preflat-state

(defun 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)
)


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 #16 on: May 14, 2010, 07:57:10 AM »

Ok, try this out.

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>]:"
    )
     )
  )
  (setq superf "No")
  (if (not superf)
    (setq superf "No")
  )
  (if (= superf "Yes")
    (progn
      (SAVE_PREFLAT)
    )
  ) ;if
  (if (= superf "No")
    (progn
      (prompt
"\n OK, moving on and leaving drawing as is in 3D..."
      )
    )
  ) ;if
) ;end defun 
;SAVE_PRE = save copy of drawing as preflat-state
(defun 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)
)
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 #17 on: May 14, 2010, 08:06:09 AM »

Third try is the charm

This should work for you..

Code: [Select]
(defun c:CZ ( / superf);fixed
  (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>]:"
    )
     )
  )
  (if (not superf)
    (setq superf "No")
  )
  (if (= superf "Yes")
    (progn
      (SAVE_PREFLAT)
    )
  ) ;if
  (if (= superf "No")
    (progn
      (prompt
"\n OK, moving on and leaving drawing as is in 3D..."
      )
    )
  ) ;if
) ;end defun 
;SAVE_PRE = save copy of drawing as preflat-state
(defun 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)
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Pad

  • Bull Frog
  • Posts: 342
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #18 on: May 14, 2010, 08:21:13 AM »
That's the one fantastic.  When I have a bit more time I will properly look at your code. Thank you very much!

one quick question though.
Code: [Select]
Command: CZ

Command:
*** Drawing is flat (2D), continuing on... ***
 OK, moving on and leaving drawing as is in 3D...nil

as the drawing is flat i don't want the 'OK, moving on and leaving drawing as is in 3D...nil' message to be displayed.

the intention when the drawing is flat is a clean exit, instead of carrying on to the superf part.

could i just add to this line
     ((princ "\n*** Drawing is flat (2D), continuing on... ***") (setq superf flat))

and then add below that

  (if (= superf "Flat")
    (princ)
  )


many thanks


edit:  just tried it and the answer is no..
« Last Edit: May 14, 2010, 08:25:45 AM by 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 #19 on: May 14, 2010, 09:14:16 AM »

Try this...


Code: [Select]
(defun c:CZ ( / superf);fixed
  (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)
     ;(princ "\n*** Drawing is flat (2D), continuing on... ***")
     (setq superf
    (getkword
      "\n*** Drawing contains 3D elements *** Would you like to run SUPERFLATTEN? [Yes/<No>]:"
    )
     )
  )
   (if (not superf) (setq superf "No"))
      (cond
      ((= superf "Yes")(SAVE_PREFLAT))
            (if (= superf "N0")
(princ)
   )
   );if
  (princ)
) ;end defun 
;SAVE_PRE = save copy of drawing as preflat-state
(defun 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)
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Pad

  • Bull Frog
  • Posts: 342
Re: lisp to check drawing for elements with a z vlaue (ie not flattened)
« Reply #20 on: May 14, 2010, 09:29:02 AM »
absolutely perfect thank you so much  :-)
will give it a good going over very shortly.

so pleased to get this working, cheers
« Last Edit: May 14, 2010, 10:04:09 AM by Pad »