Author Topic: lisp help  (Read 2069 times)

0 Members and 1 Guest are viewing this topic.

pryzmm

  • Guest
lisp help
« on: April 01, 2008, 11:40:13 AM »
hi everyone  :lol:,

;; can somebody give me some help with this simple lisp i did,,,
;; im not so good at it as im new to it, but im very willing to learn.
;; here it is.

;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; this routine will purge, image detach, zoom & start plot;
;
(prompt "\n use command:pizp")
(defun c:pizp ()
(setvar "cmdecho" 0)
   (command ".-layer" "s" "0" "" "")
   (command "tilemode" "0")
   (command "pspace")
   (command "zoom" "all")
   (command "-image" "d" "*" ) ;; can anyone show me how to fixed this line as when the drawing has no image it return with error, can this line check the drawing for any image/s and if "found" detach them, if "none" exit image command and proceed with the next task.
   (command "-purge" "all" "" "n")
   (prompt "\nPurging #1")(terpri)
   (command "-purge" "all" "" "n")
   (prompt "\nPurging #2")(terpri)
   (prompt "...done")(terpri) ;; is there a string to ensure that all the above run and finish completely before invoking the "plot" command, as right now when i type in "pizp" it go straight to plot, dunno if the above is already completed.  :-o

(command "plot");; i need this to show me the standard plot configuration table and not the command line plot.
(princ))

;;;;;;;;;;;;;;;;;;;;;;;;

thank you in advance  :-),

excuse my grammar  :|


Guest

  • Guest
Re: lisp help
« Reply #1 on: April 01, 2008, 11:53:13 AM »
First off....welcome to The Swamp.

Here's a quick and dirty way to determine if there are images.

Code: [Select]
(defun c:pizp ( / ss)
   (setvar "filedia" 1) [color=green]; Ensure that dialog boxes will be displayed instead of using the command line[/color]
   (setvar "cmdecho" 0)
   (command ".-layer" "s" "0" "" "")
   (command "tilemode" "0")
   (command "pspace")
   (command "zoom" "all")

[color=green];;;========================================================================
; Search drawing for images...[/color]
   [color=red](if (setq ss (ssget "X" '((0 . "IMAGE"))))[/color]
[color=green]      ; If there are images, detach them[/color]
      [color=red](command "-image" "d" "*" )[/color]
      [color=green]; If there aren't any images, just spit out a prompt that there aren't any images[/color]
      [color=red](princ "\n There are NO images here...")[/color]
   [color=red])[/color]
[color=green];;;========================================================================[/color]

   (command "-purge" "all" "" "n")
   (prompt "\nPurging #1")
   (command "-purge" "all" "" "n")
   (prompt "\nPurging #2")
   (prompt "...done")
   (command "plot")
   (princ)
)
« Last Edit: April 01, 2008, 12:13:43 PM by Matt W »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: lisp help
« Reply #2 on: April 01, 2008, 12:01:02 PM »
Matt,

You're going to need a progn for that to work or switch the prompts around.

Code: [Select]
   (if (setq ss (ssget "X" '((0 . "IMAGE"))))
      (command "-image" "d" "*" );;image found detach
      (princ "\n There are no images here...");;no image prompt
   )

or

(if (setq ss (ssget "X" '((0 . "IMAGE"))))
  ;;found and detached
  (progn (princ "\n There are images here...")
(command "-image" "d" "*")
  )
  ;;not found
  (princ "\n There are no images here...")
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Guest

  • Guest
Re: lisp help
« Reply #3 on: April 01, 2008, 12:15:00 PM »
Matt,

You're going to need a progn for that to work or switch the prompts around.


Yeah... yeah... yeah...

I screwed it up.... Trying to do too much at once, I guess.   :|

Code: [Select]
[color=green];;;========================================================================
; Search drawing for images...[/color]
   [color=red](if (setq ss (ssget "X" '((0 . "IMAGE"))))[/color]
[color=green]      ; If there are images, detach them[/color]
      [color=red](command "-image" "d" "*" )[/color]
      [color=green]; If there aren't any images, just spit out a prompt that there aren't any images[/color]
      [color=red](princ "\n There are NO images here...")[/color]
   [color=red])[/color]
[color=green];;;========================================================================[/color]

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: lisp help
« Reply #4 on: April 01, 2008, 12:16:52 PM »
this should help, it will only execute plot if the other commands are successful and you had too many "" for you set to layer 0 (i also added for it to thaw 0 layer just in case)

Code: [Select]
(defun c:pizp ( / ss)
(if
(progn
   (setvar "filedia" 1) ; Ensure that dialog boxes will be displayed instead of using the command line
   (setvar "cmdecho" 0)
   (command "-layer" "t" "0" "s" "0" "")
   (command "tilemode" "0")
   (command "pspace")
   (command "zoom" "all")

;;;========================================================================
; Search drawing for images...
   (if (setq ss (ssget "X" '((0 . "IMAGE"))))
      ; If there are images, detach them
      (command "-image" "d" "*" )
      ; If there aren't any images, just spit out a prompt that there aren't any images
      (princ "\n There are NO images here...")
   )
;;;========================================================================

   (command "-purge" "all" "" "n")
   (prompt "\nPurging #1")
   (command "-purge" "all" "" "n")
   (prompt "\nPurging #2")
   (prompt "...done")
);progn
   (command "plot")
);if
   (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

pryzmm

  • Guest
Re: lisp help
« Reply #5 on: April 02, 2008, 12:13:36 AM »
;;;thank you, matt
;;;thank you, ron
;;;thank you, allan, for your advice.

i took allans code and run it at my end, it goes well, but for some reason it exit at "purging" routine and did not continue to load the command:plot  :oops:.....can you pls. take a look again,,

;;appreciate your help.

 :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: lisp help
« Reply #6 on: April 07, 2008, 01:39:40 PM »
Code: [Select]
(defun c:pizp ( / ss)
;   (setvar "filedia" 1) ; Ensure that dialog boxes will be displayed instead of using the command line
   (setvar "cmdecho" 0)
   (command "-layer" "t" "0" "s" "0" "")
   (command "tilemode" "0")
   (command "pspace")
   (command "zoom" "all")

;;;========================================================================
; Search drawing for images...
   (if (setq ss (ssget "X" '((0 . "IMAGE"))))
      ; If there are images, detach them
      (command "-image" "d" "*" )
      ; If there aren't any images, just spit out a prompt that there aren't any images
      (princ "\n There are NO images here...")
   )
;;;========================================================================

   (command "-purge" "all" "" "n")
   (prompt "\nPurging #1")
   (command "-purge" "all" "" "n")
   (prompt "\nPurging #2")
   (prompt "...done")
   (initdia);this will force a dialog box
   (command "plot")
   (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox