home *** CD-ROM | disk | FTP | other *** search
- ;;; WBLKSOL.lsp
- ;;; ¬⌐┼v (C) 1992 Autodesk ñ╜Ñq
- ;;;
- ;;; Ñ╗│n┼ΘºK╢O¿╤▒z╢iªµÑ⌠ª≤Ñ╬│~╗▌¿D¬║½■¿⌐íB¡╫º∩ñ╬╡oªµ, ª²¼O░╚╜╨┐φ┤`ñU¡z
- ;;; ¡∞½h :
- ;;;
- ;;; 1) ñWªC¬║¬⌐┼v│qºi░╚╗▌ÑX▓{ªb¿Cñ@Ñ≈½■¿⌐∙╪íC
- ;;; 2) ¼█├÷¬║╗í⌐·ñσÑ≤ñ]Ñ▓╢╖⌐·╕ⁿ¬⌐┼v│qºiñ╬Ñ╗╢╡│\Ñi│qºiíC
- ;;;
- ;;; Ñ╗│n┼Θ╢╚┤ú¿╤º@¼░└│Ñ╬ñW¬║░╤ª╥, ª╙Ñ╝┴n⌐·⌐╬┴⌠ºtÑ⌠ª≤½O├╥; ╣∩⌐≤Ñ⌠ª≤»S«φ
- ;;; Ñ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºtÑX¿π¬║½O├╥, ªbª╣ñ@╖ºñ⌐ÑHº_╗{íC
- ;;;
- ;;;
- ;;; By Rick Barrientos
- ;;; Thanks to Rajiv Jain for providing technical support.
- ;;; Version 0.6 20 April 1992
- ;;;
- ;;;----------------------------------------------------------------------------;
- ;;;
- ;;; DESCRIPTION
- ;;;
- ;;; WBLKSOL.lsp is a sample AME 2.0 lisp routine.
- ;;;
- ;;; It allows the user to WBLOCK a solid without losing the entity
- ;;; handles. Normaly, if the WBLOCK command is used on a solid, the
- ;;; entity handles are lost and the solid loses all its information.
- ;;;
- ;;; This program uses a cheap trick to get around this problem.
- ;;; The * option in WBLOCK will keep the entity handles, however
- ;;; it also writes out everything in the drawing. WBLKSOL temporarily
- ;;; deletes everything in the drawing except what the user selects to
- ;;; write to a file. In this way the handles are kept intact.
- ;;;
- ;;; This program is designed to work just like WBLOCK. All the
- ;;; prompts are the same. The only exception is that the user can not
- ;;; enter the name of a block, the solid must be selected by pointing
- ;;; to it.
- ;;;
- ;;; Revison 0.5 has added a new function to this file, The command
- ;;; INSRTSOL. The normal Autocad INSERT commnad can not be
- ;;; used reliably with AME. It's use can result in bad handles.
- ;;; This function automates the XREF and EXPLODE procedure that
- ;;; is recommended for solid block insertion.
- ;;;
- ;;; INSRTSOL is designed to work like the normal AutoCAD insert
- ;;; command, it prompts for an insertion point and rotation. It
- ;;; also checks if the specified block name is already defined
- ;;; within the drawing and allows it's insertion.
- ;;;
- ;;; Revision 0.6 has added support for standard file dialogue
- ;;; boxes. If the filedia variable is set to 1, a dialogue box
- ;;; will appear. If filedia is set to 0, the interface will be
- ;;; via the command line.
-
- (defun wb_err (s) ; If an error (such as CTRL-C) occurs
- ; while this command is active...
- (if (/= s "Function cancelled")
- (princ (strcat "\n┐∙╗~: " s))
- )
- (setq sset1 nil) ; Free selection-sets if any
- (setq sset2 nil)
- (setq sset3 nil)
- (setq ss_sol nil)
- (setq ss_mat nil)
- (setvar "cmdecho" ce) ; Restore saved mode
- (setvar "filedia" fd)
- (setq *error* olderr) ; Restore old *error* handler
- (princ)
- )
-
-
- ;function that writes out the solid
-
- (defun doit (/ sset1 sset3 count length ename)
-
- (setvar "filedia" 0)
- ;set undo marker. prompt for an insertion base point.
-
- (command "_.undo" "_group")
- (initget 1)
- (setvar "insbase" (getpoint "\n┤íñ▐íu░≥╖╟┬Iív: ")) (terpri)
-
- ;prompt user to pick selection set and create selection set of all
- ;other entities
-
- (setq sset1 (ssget))
- ;Check that something has been picked. If nothing is selected, exit
- ;If selection set is valid, go ahead and writ out the entities.
- (if (null sset1)
- (progn (princ "\nÑ╝┐∩¿∞╣╧ñ╕íC")(setq loop 0))
- (progn
- ;Print out an explanation of what is happening
- (princ "\n╜╨╡y¡╘; ª╣╣L╡{Ñi»α╢╖»╙Ñ╬ñ@¼q«╔╢ííC")
- (princ "\n╣∩⌐≤╣╧ñ╕íu╝╚«╔«°Ñóív¬║▒íº╬, ñúñ⌐─╡Ñ▄íC")
-
- ;Make a null set ss2 to add entities in it.
- (setq sset2 (ssadd))
- ;Call addent to add all the top level solids and
- ;its children to sset2. Note: sset1 will be useless then.
- (setq length (sslength sset1))
- (setq count 0)
- (repeat length
- (setq test_top 0)
- (setq solname (ssname sset1 count))
- (addent solname)
- (setq count (+ count 1))
- )
-
- ;Lets get all the entities in the drawing
- (setq sset3 (ssget "x"))
-
- ;subtract selection set (sset2) with picked items and their
- ; children from the selection set of all entities(sset3)
- ; or sset3 = sset3 - sset2
- (setq count 0)
- (setq length (sslength sset2))
- (repeat length
- (setq solname (ssname sset2 count))
- (ssdel solname sset3)
- (setq count (+ count 1))
- )
-
- ;Now we'll get two more selection sets with special blocks in them
- ;and remove them from sset3
-
- (setq ss_sol (ssget "x" (list (cons 2 "AME_SOL"))))
- (setq count 0)
- (setq length (sslength ss_sol))
- (repeat length
- (setq solname (ssname ss_sol count))
- (ssdel solname sset3)
- (setq count (+ count 1))
- )
-
- (setq ss_mat (ssget "x" (list (cons 2 "AME_MAT"))))
- (setq count 0)
- (setq length (sslength ss_sol))
- (repeat length
- (setq solname (ssname ss_sol count))
- (ssdel solname sset3)
- (setq count (+ count 1))
- )
-
- ;erase all the other entities and save the file
-
- ;temporary deletion of sset3
- (command "_.erase" sset3 "")
- (if chk
- (command "_.wblock" filename "_Yes" "*")
- (command "_.wblock" filename "*")
- )
-
-
- ;restore the drawing to how you found it
-
-
- (command "_.undo" "_end" "_u")
-
- (princ "\nº╣ª¿ !")(setq loop 0)
- )
- )
- (setvar "filedia" fd)
- )
- ;this function looks for entities in extended entity data
- (defun addent (ename / t_hand oldent lchild rchild n_value)
-
- (ssadd ename sset2)
- ; get the Extended Entity DATA
- (if
- (= -3 (car (last (setq oldent (entget ename
- (list "AME_SOL"))))))
-
- ; Check the version number of the solid
- ; if 1 then the solid is made with AME 2 else
- ; if 0 then ot is AME 1.
- (progn
- (if
- (= 0 (cdr (nth 2(last (last oldent)))) )
- (setq n_value 6)
- ;else
- (setq n_value 7)
- )
- (if
- ; Checking if the solid is a boolean ..
- (= 7 (logand 255 (cdr (nth 4 (last (last oldent))))))
- (progn
- ;get the Back ground entity wire frameor pmesh of
- ; top level solid only
- (if
- (= 0 test_top)
- (progn
-
- (setq test_top 1)
- (setq t_hand (cdr (nth (+ n_value 2) (last (last oldent)))))
- (if
- (/= "0" t_hand)
- (ssadd (handent t_hand) sset2)
- )
- ; Now lets get the Boundary files.
- (setq t_hand (cdr (nth (+ n_value 3) (last (last oldent)))))
- (while (/= "0" t_hand)
- (ssadd (handent t_hand) sset2)
- (setq t_hand (cdr (last(last(last (entget
- (handent t_hand)(list "AME_SOL")))))))
- )
- )
- )
- (setq t_hand (cdr (nth n_value (last (last oldent)))))
- (setq lchild (handent t_hand))
- (addent lchild)
- (setq t_hand (cdr (nth (+ n_value 1) (last (last oldent)))))
- (setq rchild (handent t_hand))
- (addent rchild)
- )
- ; For primitives lets get the background entity and
- ; the bfile
- (progn
- (setq listt (cdr (last (last oldent))))
- (setq bglist (member (assoc '1005 listt) listt))
- (setq t_hand (cdr (car bglist)))
- (if
- (/= "0" t_hand)
- (ssadd (handent t_hand) sset2)
- )
- (setq t_hand (cdr (car (cdr bglist))))
- (while (/= "0" t_hand)
- (ssadd (handent t_hand) sset2)
- (setq t_hand (cdr (last(last(last (entget
- (handent t_hand)(list "AME_SOL")))))))
- )
- )
- )
- )
- )
- )
-
- ;main function for wblksol command
-
- (defun C:WBLKSOL (/ fd bs ce filename chk loop rep pu)
-
- (if (not SOLSUB)
- (princ "\n░⌡ªµª╣Ñ\»αñº½e, Ñ▓╢╖Ѳ╕ⁿñJíuAME 2.0ív⌐╬íu¡▒░∞ív╢∞½¼╡{ªí íC")
- (progn
-
- ;read start settings and set variables
- (setq olderr *error*
- *error* wb_err)
-
- (setq ce (getvar "cmdecho"))
- (setvar "cmdecho" 0)
- (setq fd (getvar "filedia"))
- (setq pu (getvar "popups")) ;check for null display
- (setq bs (getvar "insbase"))
- (command "_.undo" "_group") ;set group marker
-
- ;prompt for a file name
-
- (if (and (= 1 fd)(/= 0 pu)) ;Use a dialog if possible
-
- (progn
- (setq filename (getfiled "½╪Ñ▀íu╣Ω┼Θív╣╧º╬└╔«╫" "" "dwg" 3))
- (if (/= nil filename)
- (setq chk (open filename "r"))
- )
- )
- (progn ;If not a fan of dialogs
- (setq filename (getstring "\n└╔ªW: ")) (terpri)
- (setq chk (open (strcat filename ".dwg") "r"))
- )
- )
-
- (if (= 1 fd)
- (progn
- (if (/= nil filename)(progn (setq loop 0)(doit)))
- )
- (progn
- (if chk (setq loop 1) (doit))
- (while (= loop 1)
- (initget "Yes No")
- (prompt "ñw╕gªsª│ªPªW¬║╣╧└╔; \n")
- (setq rep (getkword "¼Oº_╣w│╞ñ⌐ÑH╕m┤½? <N> "))
- (cond ((= rep "No") (setq loop 0))
- ((= rep nil) (setq loop 0))
- ((= rep "Yes") (doit))
- )
- )
- )
- )
- ;restore variables and empty selection sets
- (command "_.undo" "_end") ;set group marker
- (setvar "cmdecho" ce)
- (setvar "insbase" bs)
- (setq sset1 nil)
- (setq sset2 nil)
- (setq sset3 nil)
- (setq ss_sol nil)
- (setq ss_mat nil)
- (setq *error* olderr) ;Restore old *error* handler
- )
- )
- (princ)
- )
-
-
- ;This function strips out unwanted chatacters to return
- ;the drawing name without a path
- (defun gtname (name / lstchar blknm rep blk)
- ;set lstchar to the last character in string
- (setq lstchar (substr name (strlen name) 1))
- ;set blknm to nothing
- (setq blknm "")
-
- ;while lstchar is not what we are looking for
- (while (and (/= "\\" lstchar)
- (/= ":" lstchar)
- (/= "/" lstchar)
- (> (strlen name) 0)
- )
-
- ;if true, do this stuff
- (progn
- ;set lstchar to the last character in string
- (setq lstchar (substr name (strlen name) 1))
- ;append lstchar to blknm
- (setq blknm (strcat blknm lstchar))
- ;set name to all but last char
- (setq name (substr name 1 (- (strlen name) 1)))
- )
- )
- ;dump the slash or colon
- (if (or (= "\\" lstchar)
- (= ":" lstchar)
- (= "/" lstchar)
- )
- (setq blknm (substr blknm 1 (- (strlen blknm) 1)))
- )
- ;else stop and reverse string
- (setq rep (strlen blknm))
- (setq blk "")
- (repeat rep
- ;set lstchar to the last character in string
- (setq lstchar (substr blknm (strlen blknm) 1))
- ;append lstchar to blknm
- (setq blk (strcat blk lstchar))
- ;set name to all but last char
- (setq blknm (substr blknm 1 (- (strlen blknm) 1)))
- )
- (setq blk blk)
- )
-
- ;main function for insrtsol command
-
- (defun c:insrtsol ( / filename name ins fd ce pu)
-
- (setq olderr *error*
- *error* wb_err)
-
- (setq ce (getvar "cmdecho"))
- (setvar "cmdecho" 0)
- (setq fd (getvar "filedia"))
- (setq pu (getvar "popups")) ;check for null display
- (if (= 0 (getvar "handles")) ;enable handles
- (command "_.handles" "_on")
- )
-
- (command "_.undo" "_group") ;set group marker
-
- (if (and (= 1 fd)(/= 0 pu)) ;Use a dialog if possible
-
- (setq filename (getfiled "Insert Drawing File of Solid" "" "dwg" 2))
-
- (progn
- (setq filename (getstring "\n└╔ªW: ")) ;Just in case
- (setq filename (strcat filename ".dwg")) ;you're not a
- (if (= nil (findfile filename)) ;fan of dialogs
- (progn
- (princ "\nºΣñú¿∞└╔«╫íC")
- (setq filename nil)
- )
- )
- )
- )
- (if (/= nil filename)
- (progn
- ;check to see that file is not already defined as a block in the
- ;current drawing
- (setvar "filedia" 0)
- ;remove the .dwg part of the filename
- (setq name (substr filename 1 (- (strlen filename) 4)))
-
- ;remove the drivename and path
- (if (> (strlen name) 1)
- (setq name (gtname name))
- )
-
- (if (tblsearch "block" name) ;check block name
-
- ;if block is already defined in drawing
- (progn
- (princ "\níu")(princ name)
- (princ "ívªbÑ╪½e╣╧└╔ñññw¼░ñ@íu╝╨╖╟╣╧╕sívíC")
- (princ "\n┤íñ▐íu╣╧╕s ")(princ name)(princ "ív? ")
- (initget "Yes No")
- (setq ins (getkword "Yes/<No>: "))
- (if (= ins "Yes")
- (progn
- (princ "\n┐ΘñJíu┤íñ▐┬Iívñ╬íu▒█┬α¿ñívíC")
- (command "_.insert" name pause "" "" pause)
- (command "_.explode" "_l")
- )
- )
- )
-
- ;if no block of this name exists in drawing
- (progn
- ;if a real file is selected, xref it, bind it and explode it
- (if (/= nil filename)
- (progn
- (princ "\n┐ΘñJíu┤íñ▐┬Iívñ╬íu▒█┬α¿ñív: ")
- (command "_.xref" "_a" filename pause "" "" pause)
- (command "_.xref" "_b" name)
- (command "_.explode" "_l")
- )
- )
- )
- )
- )
- )
- (command "_.undo" "_end") ;set group marker
- (setvar "cmdecho" ce)
- (setvar "filedia" fd)
- (setq *error* olderr) ;Restore old *error* handler
- (princ)
- )
-
- (princ "\níuC:WBLKSOLív╗PíuC:INSRTSOLívñw╕ⁿñJ;")
- (princ " ╜╨ÑH WBLKSOL ñ╬ INSRTSOL ▒╥░╩½ⁿÑOíC")
- (princ)