home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p086 / 3.img / ACADSUP.LIF / KINETIC.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1991-06-11  |  18.4 KB  |  13 lines

  1. ;;;*********************************************************************;;;   Kinetic.lsp 1.01;;;   Copyright (C) 1990 by Autodesk, Inc.;;;;;;   Entitiy animation command for use with AutoCAD Release 10;;;  ;;;   Permission to use, copy, modify, and distribute this software and its;;;   documentation for any purpose and without fee is hereby granted.  ;;;;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.;;;     ;;;   Designed and implemented by Jamie Clay in June of 1990;;;   Reformatted file for compliance with coding standards.  ;;;     JSY -- Sept. 1990;;; ;;;   Note: Requires the presence of PTOOLS.LSP;;;    ;;;*********************************************************************;;;  NUMBERS;;;  f# - total number of frames;;;  s# - entity motion start number;;;  r# - entity motion steps;;;  c# - count number for entity list;;;  m# - stored value for frame starting number;;;  rf# - reference entity counter;;;  strt# - start number for filmrolls;;;  count - animation process counter;;;  ent_sel -  index counter for anim_set;;;  ent_sel# - number of lists in anim_set;;;;;;  STRINGS;;;  flm -  updated name for filmrolls;;;  kflm - saved name for filmrolls;;;  kname - user entered filmroll name;;;  pline - response string for path prompt;;;;;;  LISTS;;;  anim_set - master animation list;;;  hold_set - backup animation list used for test mode;;;  items - selected entites;;;  camlst - path points;;;  remove - polyline paths to be removed in slide animations.;;;  rot - block rotation information;;;  xs - block x scale information;;;  ys - block y scale information;;;  zs - block z scale information;;;  rfpt;;;;;;  MISC;;;  appfile - append support file switch;;;  hide  - hide command switch;;;  seepath - read a PATH script switch;;;  rem     - remove path switch;;;  testmode - test animation switch;;;  flatland - flatland value when routine is started;;;  osmode - object snap value when routine is started;;;  blipmode - blip setting value when routine is started;;;  *olderror* - stored *error* function;;;  steps - while switch;;;  select - switch for animation setup while loop;;;;;;*********************************************************************(prompt "\nLoading...")(vmon)(defun c:kinetic (/ outfile select spin flm kflm kname f# items zs                    spin ent_sel remove anim_set hold_set ent_sel# count                    camlst r# s# c# pline rfpt rf# hide seepath rem                     appfile ucsfollow refents sshade)  ;; This function has been broken into three parts to allow it to run in  ;; very tight memory situations.  The three functions are listed below.    (kine-1)                            ; Set up, get name and frames.  (kine-2)                            ; Start the selection while loop.  (kine-3)                            ; Output and cleanup before exiting.  (princ));;; Kinetic part 1 of the defun c:kinetic;;; All variables are defined in c:kinetic.(defun kine-1 ()  (if (= oset "Test")(setq oset nil))  ;; Set up the system variables  (setvar "cmdecho" 1)
  2.   (setq rf#        0        flatland   (getvar "flatland")        ucsfollow  (getvar "ucsfollow")        osmode     (getvar "osmode")        blipmode   (getvar "blipmode")        ent_sel    -1        *olderror* *error*        *error*    *close*  )  (setvar "flatland" 0)  (setvar "osmode" 0)  (setvar "highlight" 1)  (setvar "ucsfollow" 0)  (command "ucs" "world")  (getdir)                            ;  Find atk information  ;; Get the file name  (if (not dwg_name)    (setq kflm (substr (justname (getvar "dwgname")) 1 4))    (setq kflm (substr dwg_name 1 4))  )  (while (not kname)    (setq kname (getname (strcat "\nFilmroll title <" kflm ">: ")))    (if (not kname) (prompt "\nInvalid file name, please re-enter."))  )  (if (= kname "")    (setq kname (justname (getvar "dwgname")))    (setq kflm (substr kname 1 4))  )  (while (not f#)    (initget 7)    (setq f# (getint "\nNumber of frames: "))    (if (< f# 3)      (progn        (setq f# nil)        (prompt "\nPlease use a larger number.")      )    )  )  (if (or (not deed) (= deed "TEST")) (setq m# 1))  (if (not m#) (setq m# 1))  (initget 6)  (setq strt# (getint (strcat                        "\nStarting number <" (cname "" m#) ">: "))  )  (if strt# (setq m# strt#)));;; Kinetic part 2 of the defun c:kinetic;;; All variables are defined in c:kinetic.(defun kine-2 ()  (setq select T)  (while select    (prompt "\n\n[Entity Selection]\n*press RETURN when finished*")    (setq items (elget)               ; Collect entities to move          xs 0          ys 0          zs 0          rfpt nil          steps T    )        (if items      (progn        ;; get the entity motion information        (if (/= f# 3) ; if this is a 3 frame animation, skip this part.          (motion_steps)          (setq s# 1 c# 0)        )                             ; end of if \= 3 f#        ;; get the path information        (kine2a)        ;; get the spin information        (kine2b)        ;; set angles and the animation set        (kine2c)      )                               ; end of the 'if items true progn'      (progn        (if (< (length anim_set) 1)          (setq anim_set nil)          (progn            (initget "Yes No")            (setq select (getkword                 "\nAre you finished with the selection process? <Y>: ")            )            (if (or (not select) (= select "Yes"))              (setq select nil)            )          )        )      )    )                                 ;end of the 'if items'    (setq testf# f#          testm# m#    )  )                                   ; end of the 'while select');;; Kinetic part 2, subpart a;;; All variables are defined in c:kinetic.(defun kine2a ()  ;; get the path information  (while (not pline)    (initget "Fixed Path List")    (setq pline (getkword "\nEntity motion: Path/Fixed/List <Path>: "))    (if (= pline "Path") (setq pline nil))    (cond      ((= pline "Fixed") (refpoint))      ((= pline "List")        (while (not camlst)         (setq pathfile (getstring "\nMotion, point list>> File to use: ")                camlst (ptsread pathfile)          )          (if (and (< txtpt# r#) camlst)            (progn                            (prompt "\nInsufficient number of points.")              (prompt "\nSorry, can not use this file.")              (setq camlst nil)            )           )         )      )      ((not pline)        (progn          (while (not pline)            (setq pline (entsel                             "\nMotion path>> Select a polyline: ")            )            (setq pline (polytest pline))          )          (if remove            (setq remove (ssadd (car pline) remove))            (setq remove (ssadd (car pline)))          )            (setq spin T)          (if r#            (setq camlst (gather pline r#))            (setq camlst (gather pline f#))          )        )      )     ; No T condition. If a cond isn't found it this cond will pass through    )  ));;; Kinetic part 2, subpart b;;; All variables are defined in c:kinetic.(defun kine2b ()  (while spin    (initget "Reference X Y Z")    (if (or rfpt (= pline "Fixed"))      (setq spin (getkword              (strcat "\nRotation settings X[" (rtos xs 2 2) "] Y["                         (rtos ys 2 2) "] Z[" (rtos zs 2 2)                 "]\nRotation>> X/Y/Z (press RETURN when finished): ")              )      )      (setq spin (getkword            (strcat "\nRotation settings X[" (rtos xs 2 2) "] Y["                       (rtos ys 2 2) "] Z[" (rtos zs 2 2)       "]\nRotation>> X/Y/Z/Reference (press RETURN when finished): ")            )      )    )    (initget 1)    (cond      ((= spin "X") (setq xs (getreal "\nRotation X axis: ")))      ((= spin "Y") (setq ys (getreal "\nRotation Y axis: ")))      ((= spin "Z") (setq zs (getreal "\nRotation Z axis: ")))      ((and (= spin "Reference") (/= pline "Fixed"))        (progn          (refpoint)          (setq items (append (list (entlast)) items))        )      )      ; No T condition. If a cond isn't found it this cond will pass through    )  ));;; Kinetic part 2, subpart c;;; All variables are defined in c:kinetic.(defun kine2c ()  (if r#    (setq xang (rtos (/ xs r#) 2 4)          yang (rtos (/ ys r#) 2 4)          zang (rtos (/ zs r#) 2 4)    )    (setq xang (rtos (/ xs (1- f#)) 2 4)          yang (rtos (/ ys (1- f#)) 2 4)          zang (rtos (/ zs (1- f#)) 2 4)            r# f#    )  )  (setq spin nil        pline nil        ent_sel (1+ ent_sel)        ent_sel# (1+ ent_sel)        count 0  )  (if anim_set    (setq anim_set (append anim_set            (list (list items rfpt xang yang zang camlst s# c# r#)))    )    (setq anim_set (list           (list items rfpt xang yang zang camlst s# c# r#))    )  )  (setq camlst nil         s# nil  )  (setvar "highlight" 0)  (command "select" (elgot items) "")  (if rfpt (command "select" "p" rfpt ""))  (setvar "highlight" 1)  (setq select T));;; Kinetic part 3 of the defun c:kinetic;;; All variables are defined in c:kinetic.(defun kine-3 ()  (output)                            ; find output format  (if (= deed "TEST")    (progn      (setq hold_set anim_set            testmode T      )      (while testmode        (command "undo" "mark")        (k_action)                    ; do the animation        (princ "\n*press any key to reset animation*")        (while (/= (nth 0 (grread)) 2))  ;pause for keyboard input        (command  "undo" "back")        (output)                      ; Get output settings        (if (/= deed "TEST")          (setq testmode nil)        )        (setq count 0                 ; Restore the values needed for animation              f# testf#              m# testm#              anim_set hold_set        )      )    )  )  ;; if you are doing a slide process, remove the paths. (if you want to)  (if rem                            (command "erase" remove "")  )  (if deed    (k_action)  )  ;; All done, shut her down  (if outfile    (progn      (close outfile)      (cond        ((= deed "MSLIDE")           (princ (strcat "\nAnimation list "                          (strcase fdir)                          (strcase fname)))        )        ((= deed "SAVE")           (princ (strcat "\nDrawing block list "                           (strcase fdir)                           (strcase fname)))        )      )      (if appfile        (princ " updated.")        (princ " created.")      )    )  )  (if seefile (close seefile))  (if rem    (progn      (setq repo 0)      (repeat (sslength remove)        (entdel (ssname remove repo))        (setq repo (1+ repo))      )    )  )  ;; if there are reference entities, remove them.  (if refents      (command "erase" refents "")  )  (command "ucsicon" "all" "on")  (command "undo" "end")  (setvar "cmdecho" 1)  (setvar "highlight" 1)  (setvar "ucsfollow" ucsfollow)    (setq *error* *olderror*));;; Supporting defuns;;; K_ACTION -(defun k_action ()  (setq f# (1- f#))  (command "ucsicon" "all" "off")  (if seepath (view seepath))  ;; Hide or shade the image as requested  (if hide    (command "hide")    (if sshade      (command "shade")    )  )  (setq flm (cname kflm m#)        m# (1+ m#)  )  (if (or (= deed "MSLIDE") (= deed "SAVE"))    (supfile flm kname)  )  (if (= deed "TEST")   (princ (strcat "\nTest mode >> " flm ))   (progn     (princ (strcat "\nMaking " fdir flm sfx))     (if (and (findfile (strcat fdir flm ".dwg"))(= deed "SAVE"))
  3.        (command deed (strcat fdir flm) "Y")       (progn
  4.          (if (= deed "DXFOUT")
  5.             (command deed (strcat fdir flm) "B")
  6.             (command deed  (strcat fdir flm)))
  7.         )
  8.      )   )  )  (setvar "highlight" 0)  ;; Process the animation  (repeat f#    (repeat ent_sel#      (action (nth ent_sel anim_set))      (setq ent_sel (1- ent_sel))    )    (setq flm  (cname kflm m#))    (if seepath (view seepath))    ;; hide or shade the image as requested    (if hide      (command "hide")      (if sshade        (command "shade")      )    )    (if (= deed "TEST")      (princ (strcat "\nTest mode >> " flm))      (progn        (princ (strcat "\nMaking " fdir flm sfx))        (if (and (findfile (strcat fdir flm ".dwg"))(= deed "SAVE"))          (command deed (strcat fdir flm) "Y")           (progn
  9.              (if (= deed "DXFOUT")
  10.                 (command deed (strcat fdir flm) "B")
  11.                 (command deed  (strcat fdir flm)))
  12.             )
  13.         )      )    )    (if (or (= deed "MSLIDE") (= deed "SAVE"))      (supfile flm (justname (getvar "dwgname")))    )    (setq m# (1+ m#)          ent_sel (1- ent_sel#)          count (1+ count)    )  ));;; ELGET - AutoLISP function used to get an entity list.(defun ELGET (/ elist index e# x)  (setq x (ssget))                    ; Create the selection set.   (if x     (progn        (setq e# (sslength x)         ; Find the lenght.              index 0                 ; Reset index for ssname function.        )        (repeat e#          (setq e (ssname x index))   ; Get an entity from selection set.          (if (= index 0)                           (setq elist (list e))     ;  Start the list.            (setq elist (append elist (list e)))  ;  Add to the list.        )        (setq index (1+ index))       ; Up the index count.      )    )  )  (setq elist elist)                  ; "Display" the list.)    ;;; ELGOT - AutoLISP function used to retrieve an entity list.  Requires;;; an argument list of entities.(defun ELGOT (x / elist index e)  (setq e# (length x)                 ; Find the list lenght.        index 0                       ; Set the index for nth function.        elist (ssadd)                 ; Start the entity list.  )  (repeat e#    (setq e (nth index x)             ; Get the first entity.          elist (ssadd e elist)       ; Add it to the list.          index (1+ index)            ; Up the index count.    )  )  (eval elist)                        ; "Display" the selection set. )                 ;;;  ACTION - The Entity Mover(defun action (elset / pt1 pt2 doit)  (setq item (elgot (nth 0 elset))    ; entity list        rfpt (nth 1 elset)            ; reference point        xang (nth 2 elset)            ; X angle rotation        yang (nth 3 elset)            ; Y angle rotation        zang (nth 4 elset)            ; Z angle rotation        camlst (nth 5 elset)          ; Point list        st# (nth 6 elset)             ; motion start        count2 (nth 7 elset)          ; motion steps count        end (nth 8 elset)             ; motion end  )  (if st#    (setq start (1- st#))    (setq start -1)  )  (if  (= xang "0.0000") (setq xang nil))  (if  (= yang "0.0000") (setq yang nil))  (if  (= zang "0.0000") (setq zang nil))  (if (<= (+ end start) count )    (setq xang nil          yang nil          zang nil          camlst nil    )  )  (if (>= count start)    (progn      (if camlst                  ; Set motion points        (progn          (if count2              ; Step process switch            (setq pt1 (nth count2 camlst)                  pt2 (nth (1+ count2) camlst)            )            (setq pt1 (nth count camlst)                  pt2 (nth (1+ count) camlst)            )          )          (if pt2 (command "move" item "" pt1 pt2)) ; Move the entities        )      )      (if rfpt                                    ; Set reference point        (if (= (cdr(assoc 0 (entget rfpt))) "POLYLINE")          (setq pt2 (cdr (assoc 10 (entget (entnext rfpt))))                Zdir (cdr (assoc 10 (entget (entnext (entnext rfpt)))))                vector T          )          (setq pt2 (cdr (assoc 10 (entget rfpt))))        )      )      ; X world rotation      (if (and xang pt2)        (progn          (command "ucs" "X" "90")          (command "ucs" "Y" "90")          (command "rotate" item "" (trans pt2 0 1) xang)          (command "ucs" "W")        )      )      ; Y world rotation      (if (and yang pt2)        (progn          (command "ucs" "X" "90")          (command "rotate" item "" (trans pt2 0 1) yang)          (command "ucs" "W")        )      )      ; Z world rotation      (if (and zang pt2)        (if vector          (progn            (command "ucs" "ZA" pt2 Zdir)            (command "rotate" item "" "0,0,0" zang)            (command "ucs" "W")            (setq vector nil)          )          (command "rotate" item "" pt2 zang)        )      )    )  )  (if (and count2 (>= count start))    (setq anim_set       (subst       (list (nth 0 elset) rfpt xang yang zang camlst st# (1+ count2) end)      elset anim_set)    )  ));;; REFPOINT - Function used to establish a world spin reference point ;;; or vector. (defun refpoint (/ rfpt1 rfpt2)  (while (not rfpt)    (setq rfpt (car (entsel       "\nRotation point>> Select a node, 3dpoly (press RETURN to define): "))    )    (if (not rfpt)      (setq rfpt 1)      (cond        ((= (cdr (assoc 0 (entget rfpt))) "POINT") T)        ((and (=  (cdr (assoc 0 (entget rfpt))) "POLYLINE")               (= (logand  8 (cdr (assoc 70 (entget rfpt)))) 8) ) T)        (T (progn             (princ "\n:Not a valid reference entity:")             (princ "\nMust be a NODE or 3D Polyline.")             (setq rfpt nil)           )        )      )    )  )  (if (= rfpt 1)     (setq rfpt nil)  )  (if (not rfpt)    (progn      (initget 1)      (setq rfpt1 (getpoint "\nRotation base>> Pick a point: ")            rfpt2 (getpoint rfpt1                   "\nRotation Z axis direction>> Pick a point <none>: ")      )      (if (and rfpt1 rfpt2)        (command "3dpoly" rfpt1 rfpt2 "")        (command "point" rfpt1)      )      (setq rfpt (entlast))           ; collect reference point for anim_set       (if refents        (setq refents (ssadd (entlast) refents)); add entity to delete list        (setq refents (ssadd (entlast))); create a selection set if none      )    )  )  (initget 1)  (if (= (cdr(assoc 0 (entget rfpt))) "POLYLINE")    (setq zs (getreal "\nRotation>> Rotation amount: ")          spin nil    )    (setq spin T)                     ; set true for spin.  )    ) ;;; Load support functions(setq loaded T)(if (not gather) (load "ptools"));;; End of the load.(princ "\C:KINETIC v1.01 - Loaded!")(princ)