Author Topic: Help on a lisp i wrote...  (Read 1820 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
Help on a lisp i wrote...
« on: February 25, 2011, 05:22:38 PM »
Code: [Select]
(defun c:clean-scr-e ()
  (GCI)
  (vlt)
  (Esize)
(princ)
  )

(defun c:clean-scr-d ()
  (GCI)
  (vlt)
  (Dsize)
(princ)
  )

(defun GCI(/ newdictlist)

(cond
  ((setq newdictlist (dictsearch (namedobjdict) "GcImageDef_Dict")) (dictremove (namedobjdict) "gcImageDef_Dict")))
;   (alert "\nThe GcImageDef_Dict has been removed."))
 
;  ((alert "\nGcImageDef_Dict does not exist.")))
 
(princ)

)
;
;
(defun vlt ( / ss ) (vl-load-com)
 
(command "._units" "2" "6" "1" "0" "0" "n")
  (if (setq ss (ssget "_X" '((0 . "VIEWPORT"))))
    (princ
      (strcat "\n--> LTSCALE set to "
        (rtos
          (setvar 'LTSCALE
            (/ 1.
              (* 4.0             
                (vla-get-CustomScale
                  (vlax-ename->vla-object (ssname ss 0))
                )
              )
            )
          )
        )
        " <--"
      )
    )
  )
  (princ)
)
;
;
(defun Esize ()
;
(command "._layer" "set" "0" "")
(command "._layout" "set" "")
(command "._ZOOM" "E")
(command "._viewres" "y" "10000")
(command "._mview" "lock" "on" "all" "")
(command "._units" "2" "6" "1" "0" "0" "n")
(command "._ZOOM" "w" "40.5,3.5,0.0" "44.3,0.23,0.0")
(command "._LWDISPLAY" "off")
(command "._units" "4" "2" "1" "0" "0" "n")
(command "._purge" "all" "*" "n")
(command "._purge" "all" "*" "n")
(command "._INSERT" "BGE_LayerBlock=Q:/Std/BG&E/CADstandards/BGE-Standards.dwg" "0,0" "1" "1" "0" "._erase" (entlast) "" "._purge" "B" "BGE_layerBlock" "N")
(command "._Filedia" "0")
(command "._saveas" "2000" "" "y")
(command "._Filedia" "1")
(command "textscr")
(command "graphscr")

(princ)
)

(defun Dsize ()
;
(command "._layer" "set" "0" "")
(command "._layout" "set" "")
(command "._ZOOM" "E")
(command "._viewres" "y" "10000")
(command "._mview" "lock" "on" "all" "")
(command "._units" "2" "6" "1" "0" "0" "n")
(command "._ZOOM" "w" "30.5,3.5,0.0" "34.3,0.2,0.0")
(command "._LWDISPLAY" "off")
(command "._units" "4" "2" "1" "0" "0" "n")
(command "._purge" "all" "*" "n")
(command "._purge" "all" "*" "n")
(command "._INSERT" "BGE_LayerBlock=Q:/Std/BG&E/CADstandards/BGE-Standards.dwg" "0,0" "1" "1" "0" "._erase" (entlast) "" "._purge" "B" "BGE_layerBlock" "N")
(command "._Filedia" "0")
(command "._saveas" "2000" "" "y")
(command "._Filedia" "1")
(command "textscr")
(command "graphscr")

(princ)
)

(princ)

I run this in script pro to batch 100's of drawings with the lisp above

Code: [Select]
(load"bgeClean")
clean-scr-d

Code: [Select]
(load"bgeClean")
clean-scr-e

Only problem is that I have too run these on different sets of plans because some are E size and some are D size....

What I need help with is some how being able to run only 1 script file on all of the drawings and for the lisp to find the a block attribute and then tell lisp or script which one to run for that given size of file...

The Block name is: BORDER

The Tag that holds the attribute it would need to read is: SIZE

The 2 values i would need are: E or D

If its E then it should run "clean-scr-e"

If its D then it should run "clean-scr-d"

It makes sense in my head...

Thanks in advance

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Help on a lisp i wrote...
« Reply #1 on: February 25, 2011, 06:05:49 PM »
You need to find the block ( ssget ), then step through it ( entnext ) until you get an attribute whose tag ( dxf code 2 ) is what you want.  Then branch from there ( if ).
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help on a lisp i wrote...
« Reply #2 on: February 25, 2011, 06:10:22 PM »
I did a quick revamp of you code & did NOT test it so it's up to you to make it work.  :-)
Code: [Select]
(defun c:clean-scr ( / newdictlist ss dsize titleblock attributes att)

  (vl-load-com)

;;  The Block name is: BORDER
(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "BORDER")(66 . 1))))
  (progn
     (setq titleblock (vlax-ename->vla-object (ssname ss 0)))
     (setq attributes (vlax-invoke titleblock 'getattributes))
    (foreach att attributes
      (if (= "SIZE" (vla-get-tagstring att))
        (setq dsize (= "D" (strcase(vla-get-textstring att))))
      )
    )
  )
)
 
(cond
  ((setq newdictlist (dictsearch (namedobjdict) "GcImageDef_Dict")) (dictremove (namedobjdict) "gcImageDef_Dict")))
 
 
(command "._units" "2" "6" "1" "0" "0" "n")
  (if (setq ss (ssget "_X" '((0 . "VIEWPORT"))))
    (princ
      (strcat "\n--> LTSCALE set to "
        (rtos
          (setvar 'LTSCALE
            (/ 1.
              (* 4.0             
                (vla-get-CustomScale
                  (vlax-ename->vla-object (ssname ss 0))
                )
              )
            )
          )
        )
        " <--"
      )
    )
  )


 
(command "._layer" "set" "0" "")
(command "._layout" "set" "")
(command "._ZOOM" "E")
(command "._viewres" "y" "10000")
(command "._mview" "lock" "on" "all" "")
(command "._units" "2" "6" "1" "0" "0" "n")
(if dsize
  (command "._ZOOM" "w" "30.5,3.5,0.0" "34.3,0.2,0.0")
  (command "._ZOOM" "w" "40.5,3.5,0.0" "44.3,0.23,0.0")

(command "._LWDISPLAY" "off")
(command "._units" "4" "2" "1" "0" "0" "n")
(command "._purge" "all" "*" "n")
(command "._purge" "all" "*" "n")
 
(command "._INSERT" "BGE_LayerBlock=Q:/Std/BG&E/CADstandards/BGE-Standards.dwg" "0,0" "1" "1" "0" "._erase" (entlast) "" "._purge" "B" "BGE_layerBlock" "N")
(command "._Filedia" "0")
(command "._saveas" "2000" "" "y")
(command "._Filedia" "1")
(command "textscr")
(command "graphscr")

(princ)
)

(princ)
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.