home *** CD-ROM | disk | FTP | other *** search
-
- ; AutoShade commands for AutoCAD
-
- ; Designed and implemented by Kelvin R. Throop in May of 1987
-
- ; CAMERA -- Insert a camera
-
- (defun C:CAMERA ( / omode sname gname lfxy laxy oang selev
- scale slayer ltyp orth rot)
-
- (setq omode (cmode)) ; Set common modes
- (graphscr)
-
- (setq sname (acqs "Enter camera name" nil))
-
- ; Get the camera's target.
-
- (setq laxy (gp3d "Enter target point"))
-
- ; Get the object's look from point
-
- (setq lfxy (gp3d "Enter camera location"))
- (setq rot (* (/ 180 pi) (- (angle lfxy laxy) 1.570796)))
- (setq scale (/ (getvar "VIEWSIZE") 9.52381))
- (command
- "insert"
- "camera"
- lfxy
- scale
- scale
- (strcat "<<" (rtos rot 2 6))
- sname ; SNAME
- " " ; GNAME
- (rtos (car laxy) 2 6) ; LAX
- (rtos (cadr laxy) 2 6) ; LAY
- (rtos (caddr laxy) 2 6) ; LAZ
- )
-
- ; Restore the previous operating mode
-
- (smode omode)
- (terpri)
- )
-
- ; LIGHT -- Insert a light source
-
- (defun C:LIGHT ( / omode sname gname lfxy laxy oang selev
- scale slayer blkn ltyp orth rot)
-
- (setq omode (cmode)) ; Set running modes
- (graphscr)
-
- (setq sname (acqs "Enter light name" nil))
-
- ; See if the light is a point source or a parallel (directed) source.
- ; If it's a directed source, get the direction of the beam.
-
- (setq selev T)
- (while selev
- (setq selev (strcase (substr
- (acqs "Point source or Directed" "P") 1 1)))
- (cond ((= selev "P")
- (setq blkn "overhead")
- (setq gname " ")
- (setq laxy '(0 0 0))
- (setq selev nil)
- )
- ((= selev "D")
- (setq blkn "direct")
- (setq gname "Parallel")
- (setq laxy (gp3d "Enter light aim point"))
- (setq selev nil)
- )
- )
- )
-
- ; Get the light's location
-
- (setq lfxy (gp3d "Enter light location"))
- (setq scale (/ (getvar "VIEWSIZE") 9.52381))
- (if (= blkn "overhead")
- (setq rot 0)
- (setq rot (* (/ 180 pi) (- (angle lfxy laxy) 1.570796)))
- )
- (command
- "insert"
- blkn
- lfxy
- scale
- scale
- (strcat "<<" (rtos rot 2 6))
- sname ; SNAME
- gname ; GNAME
- (rtos (car laxy) 2 6) ; LAX
- (rtos (cadr laxy) 2 6) ; LAY
- (rtos (caddr laxy) 2 6) ; LAZ
- )
-
- ; Restore the previous operating modes
-
- (smode omode)
- (terpri)
- )
-
- ; SCENE -- Define a scene
-
- ; It prompts the user for a camera name and optional light sources
- ; and insert a series of scene blocks, one for the camera and as many as
- ; needed for the light sources.
-
- (defun C:SCENE ( / sname cname lname savss savobj wlist oname ename
- lfxy scale lrefs)
-
- (setq sname "") ; The set name
- (setq olist nil) ; List of the scene's objects
- (graphscr)
-
- ; Obtain scene name
-
- (setq sname (acqs "Enter scene name" nil))
-
- ; Save the SCENE name
-
- (setq olist (list sname))
-
- ; Get the camera's name. Don't take null for an answer.
-
- (setq objct "CAMERA")
-
- (bget (slob "\nSelect the " ": " nil))
- (setq cname (cdr (assoc '1 (eget "SNAME"))))
- (prompt (strcat " " cname "\n"))
-
- ; Include the camera name in the list of objects
- ; which belong to the scene.
-
- (setq
- olist
- (append olist (list (list "CAMERA" cname)))
- )
-
- ; Get the light sources' names. Here, a null
- ; line is interpreted as an end of the list of light sources.
-
- (setq objct "LIGHT")
- (setq lrefs "Lights:")
-
- (setq lname 1)
- (while (and cname lname)
- (setq lname (slob "\nSelect a " ": " T))
-
- ; Include the light name in the list of
- ; objects which belong to the scene. Don't
- ; do it if the light is already part of the
- ; scene.
-
- (if lname
- (progn
- (bget lname)
- (setq lname (cdr (assoc '1 (eget "SNAME"))))
- (prompt (strcat " " lname "\n"))
- (if (notin lname)
- (setq olist
- (append olist
- (list (list objct lname))
- )
- lrefs (strcat lrefs " " lname)
- )
- (prompt (strcat "\nLight " lname " already selected.\n"))
- )
- )
- )
- )
-
- (if olist
- (progn
-
- ' Create a list of all of the objects to be inserted
-
- (setq wlist (cdr olist))
-
- ; Get the camera name
-
- (setq oname (cadr (assoc '"CAMERA" wlist)))
-
- ; Obtain location to put scene reference block
-
- (setq lfxy (gp3d "Enter scene location"))
- (setq scale (/ (getvar "VIEWSIZE") 85.0))
-
- ; Put the clapper in the drawing
-
- (clinsu sname lfxy scale (strcat "Camera: " oname) lrefs)
-
- ; Insert the Scene's camera block and update its attributes
-
- (sinsu sname "CAMERA" oname lfxy scale)
-
- ; Insert the Scene's light sources and update their attributes
-
- (foreach oname wlist
- (if (eq (car oname) "LIGHT")
- (progn
- ; Offset each SHOT block to form bars on the clapper
- (setq lfxy (cons
- (+ (car lfxy) (* 0.8 scale)) (cdr lfxy)))
- (sinsu sname "LIGHT" (cadr oname) lfxy scale)
- )
- )
- )
- (prompt (strcat "\nScene " sname " included\n"))
- )
- (prompt "\nNo scenes included\n")
- )
- (setq olist nil)
- )
-
- ; SINSU - Scene insert update attributes
-
- ; It will insert a scene block and update its attributes accordingly.
-
- ; Input: sname The scene name
- ; otype The object' type
- ; oname The object's name
-
- (defun SINSU (sname otype oname lfxy scale / omode slayer)
-
- (setq omode (cmode)) ; use common modes
-
- (command "insert"
- "shot" ; Load up the number 4 buck, Billy Bob!
- lfxy ; Shot reference location
- scale ; X scaling
- scale ; Y scaling
- "<<0" ; No rotation
- otype ; Object type (e.g., light, camera)
- oname ; Object name (its name)
- sname ; Scene name
- )
-
- ; Restore the previous operating modes
-
- (smode omode)
- )
-
- ; Insert clapper. The whole purpose of the clapper is to carry the
- ; extra attributes which cannot be added to the SHOT block.
-
- (defun clinsu (sname lfxy scale cref lref / omode slayer)
-
- (setq omode (cmode)) ; use common modes
-
- (command "insert"
- "clapper" ; No applause for morons
- lfxy ; Shot reference location
- scale ; X scaling
- scale ; Y scaling
- "<<0" ; No rotation
- sname ; Scene name
- cref ; Camera reference string
- lref ; Light reference string
- )
-
- ; Restore the previous operating modes
-
- (smode omode)
- )
-
- ; SMODE - Save and set operating modes
-
- ; Saves the operating modes in MLIST and sets them to the values
- ; indicated. It returns a list with the current settings.
-
- ; Input: mlist - A list containing paired lists with operating names
- ; and the values which to set them. The format is as
- ; follows:
-
- ; ((STRING1 VALUE1) (STRING2 VALUE2) ... (STRINGN VALUEN))
-
- ; Return: clist - A list with the same format as MLIST containning the
- ; current settings.
-
- (defun smode (mlist / clist pair string oval)
- (setq clist nil)
- (foreach pair mlist
- (setq string (car pair))
- (setq oval (getvar string))
- (setq clist (append clist (list (list string oval))))
- (setvar string (cadr pair))
- )
- clist
- )
-
- ; CMODE -- Set operating modes used whilst accessing our blocks
-
- (defun cmode()
- (smode '(("CMDECHO" 0)("LIMCHECK" 0)("EXPERT" 1)
- ("ORTHOMODE" 0)))
- )
-
- ; ACQS -- Acquire string. Handles defaults and rejects null;
- ; input if there is no default.
- ; Since this is used only for object names, it limits
- ; the name length to 8 characters.
-
- ; Input: a - The prompt string
- ; b - The default string
- ;
-
- (defun acqs ( a b / c d)
-
- ; Initialise working environment
-
- (setq c nil d T)
-
- ; Display default value, if necessary
-
- (cond
- ((null b)
- (setq a (strcat "\n" a ": ")))
- (T
- (setq a (strcat "\n" a " <" b ">: ")))
- )
- (while d
- (setq c (getstring a))
- (if (or (not (or (null c) (= c ""))) b)
- (setq d nil)
- )
- )
-
- ; A null answer causes default to be returned
-
- (substr (if (= c "") b c) 1 8)
- )
-
- ; SLOB Select Object
-
- ; Selects one of the active object types.
- ; Won't take NULL for an answer.
-
- ; Input: prefix prompt
- ; postfix prompt
- ; Null pick ok flag
-
- ; Uses globals objct and objo
-
- ; Return: entity
-
- (defun slob (pre post nulok / prcd)
-
- (setq prcd 1)
-
- ; Select the object to update.
-
- (while (= 1 prcd)
- (setq ename (car (entsel (strcat pre (strcase objct t) post))))
- (if ename
- (if (= (cdr (assoc '0 (setq elist (entget ename)))) "INSERT")
- (progn
- (setq bnam (cdr (assoc '2 elist)))
- (cond
- ; Inserted block must have the desired object name.
- ((or
- (= objct bnam)
- (and (= bnam "DIRECT") (= objct "LIGHT"))
- (and (= bnam "OVERHEAD") (= objct "LIGHT"))
- (and (= bnam "SHOT") (= objct "SCENE")))
- (setq prcd nil)
- )
- (T
- (prompt (strcat "\nSelected object is not a "
- (strcase objct t) " \n")))
- )
- )
- )
- (if nulok
- (setq prcd nil))
- )
- )
- ename
- )
-
- ; bget (ename)
-
- ; Starting at ENAME entity name it searches the database for an SEQEND
- ; entity . The following list is returned:
-
- ; (elist0 elist1 elist2 ... elistN), where
-
- ; elist0 Is the block's entity list
-
- ; elist<i>, i=1,N are the entities lists of the block's attributes
-
- ; If the desired INSERT entity is not found nil is returned
-
- ; Input: ename - Where to start the search.
-
- ; Return: blist - A global value
-
- (defun bget ( ename / prcd elist)
-
- (setq prcd 1)
-
- ; Before starting, see if the current blist contains
- ; the desired entity.
-
- (cond
- ((and (listp 'blist) (= ename (cdr (assoc '-1 (car blist)))))
- (ename))
-
- (T
- (setq blist (list (entget ename)))
- (while prcd
- (setq elist (entget (setq ename (entnext ename))))
- (if (= (cdr (assoc '0 elist)) "SEQEND")
- (setq prcd nil)
- (setq blist (append blist (list elist)))
- )
- )
- (cdr (assoc '-1 (car blist)))
- )
- )
- )
-
- ; eget ( tagn )
-
- ; Searches the current blist for an ATTRIB elist whith an attribute
- ; tag equal to the argument's tag name. It returns either the
- ; attribute's elist or nil.
-
- ; Input: tagn - The attribute tag name
- ; blist - A global list containning the elists to be
- ; searched.
- ;
- ; Return: elist - The desired entity list or nil
-
- (defun eget ( tagn / elist wlist)
-
- (setq elist nil)
- (foreach wlist blist
- (if (and (= (cdr (assoc '0 wlist)) "ATTRIB")
- (= (cdr (assoc '2 wlist)) tagn)
- )
- (setq elist wlist)
- )
- )
- elist
- )
-
- ; NOTIN
-
- ; It searches the current OLIST looking for the named object. If
- ; the object is defined it returns T otherwise nil.
-
- ; Input: oname - The name of the object being searched.
- ; olist - A global list containing the list of objects
- ; which belong to the current defined scene.
-
- ; Return: T - if the object is already part of the scene.
- ; nil - otherwise
-
- (defun notin ( lname / opair odfnd)
-
- (setq odfnd nil) ; Say object not defined
- (foreach opair (cdr olist)
- (if (and (eq "LIGHT" (car opair)) (eq lname (cadr opair)))
- (setq odfnd 1)
- )
- )
- (null odfnd)
- )
-
- ; GP3D -- Acquire 3D point
-
- (defun gp3d (p)
- (initget (+ 1 8 16)) ; no null, limcheck off, want 3D
- (setvar "lastpt3d" (getpoint (strcat "\n" p ": ")))
- )
-
- (princ "\nAutoShade Commands Loaded, errors: ")
- (setq olist nil)
-