⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blackboard.lsp

📁 Autocad-2005-简体中文-解密版.zip
💻 LSP
📖 第 1 页 / 共 2 页
字号:
        current contents of the global variable *shared-functions*.


        This file (blackboard.lsp) when loaded attempts to find the 
		current definition of the s::startup function. If the 
		s::startup function is a list (defined by defun-q) the
		definition of the function named my-startup is appended to 
		the current definition of s::startup. The function 
		my-startup is the initializing function that is responsible 
		for evaluating every item in the blackboard variable named
        *shared-functions*.
		
	* Flow of the program
		
        During a <drawing new> or <drawing open> command, the 
		s::startup function is evaluated after AutoCAD has completed
		basic drawing initialization. The s::startup function then 
		inspects the current blackboard value of *shared-functions* 
		and if it is not nil, an eval is performed foreach item in 
		this list.

	* Potential Uses and Enhancements
	
        This example demonstrates just one of many designs for 
		creating an application that is able to share between 
		documents. It could be expanded to keep track of a bill
        of materials or large schedules that are generated on a
		separate drawing representing an entire collection or
		project of drawings. The options are endless.
				
    	General Comments:
		The functions s::startup and ac:register-function-to-
		blackboard mimic the vl-propagate function with the 
		exception that data passed to ac:register-function-to-
		blackboard is not immediately available to all documents.
		It is the responsibility of a document to retrieve the data
		when it is required by the application. In this manner the 
		application has the flexibility when to update its value 
		from the blackboard.
 		
|;

;;;
;;; ----------------------------------------------------------------------
;;;  This enables any application to "pre-populate"
;;;  definitions to the blackboard.
(setq regfunc 
'(defun ac:register-function-to-blackboard (funcAsList evaluate)
(if (equal (type funcAsList) 'list)
  (progn 
  (princ "\nRegistering ") (prin1 funcAsList)
  
  ;; Does the funcAsList need to be evaluated at this time?
  (if evaluate
  ;; if so, evaluate it.
     (eval funcAsList)
    )
    
;; Look at the value of *shared-functions*.
    
(if (vl-bb-ref '*shared-functions*)

;; If *shared-functions* is present, use the value from the
;; blackboard, cons the new item to the list ensuring that
;; it is added at the end of the list (note the double reverse).

  (setq	*shared-functions*
	 (reverse (cons funcAsList
	       (reverse (vl-bb-ref '*shared-functions*))
	       ))
	)
	;; otherwise, create the variable from scratch with the 
	;; desired initial value.
  (setq	*shared-functions*
	   (cons funcAsList
	         *shared-functions*)
	       )
	)
  )
)
;; Always update the blackboard value and return the value of
;; *shared-functions* as if setq was used.
  
(vl-bb-set '*shared-functions* *shared-functions*) 
  ))
  
  

;; evaluate the function ac:register-function-to-blackboard
;; so it can be used within this context.
(eval regfunc)

;; Now place it in the blackboard and do not evaluate it.
(ac:register-function-to-blackboard regfunc  nil )
;;; ----------------------------------------------------------------------


(setq regFunc
 '(defun ac:evaluate-Blackboard-items ()
;; automatically update any function in the blackboard.
;; variable *shared-functions*.
(if (vl-bb-ref '*shared-functions*)
  (progn
    (princ "\nEvaluating *shared-functions*")
    (foreach func (vl-bb-ref '*shared-functions*)
      (eval func)
      )
    )
  )
  ))

;;; register the function ac:evaluate-Blackboard-items
;;; and evaluate it now
(ac:register-function-to-blackboard regfunc  T )
;;; ----------------------------------------------------------------------


(setq regFunc 
  '(defun ac:register-mdi-drawing-names ()
  (if (null (member (getvar "dwgname") (mapcar 'car *ac:mdi-drawing-names*)))
    (progn
      (princ (strcat "\nadding " (getvar "dwgname") " to global list *ac:mdi-drawing-names*."))
      (setq
	;; retrieve the blackboard value for the
	;; variable *ac:mdi-drawing-names*
	*ac:mdi-drawing-names*
	 (vl-bb-ref '*ac:mdi-drawing-names*)
	;; change the value of *ac:mdi-drawing-names*
	*ac:mdi-drawing-names*
	 (cons (list (getvar "dwgname"))
	       *ac:mdi-drawing-names*
	       )
	)
      ;; place the value of *ac:mdi-drawing-names* into the blackboard.
      (VL-BB-SET '*ac:mdi-drawing-names* *ac:mdi-drawing-names*)
      ;; retrieve the blackboard value for the variable 
	;;*ac:mdi-drawing-names*
      (setq *ac:mdi-drawing-names* (vl-bb-ref '*ac:mdi-drawing-names*))

      )
    )
  )
      )

;;; register the function ac:register-mdi-drawing-names
;;; and evaluate it now
(ac:register-function-to-blackboard regfunc  T )
;;; ----------------------------------------------------------------------
      
(setq regfunc
;;; c:documents returns a history list of all opened
;;; or created documents during an AutoCAD session.
'(defun c:documents ()
(princ (vl-bb-ref '*ac:mdi-drawing-names*))
  (princ)
  )
)

(ac:register-function-to-blackboard regfunc T)
;;; ----------------------------------------------------------------------

;;; register the function call to ac:register-mdi-drawing-names
;;; and evaluate it now
(ac:register-function-to-blackboard '(ac:register-mdi-drawing-names) T)
;;; ----------------------------------------------------------------------


;;; make s::startup a native AutoLISP compatible defun 
(defun-q my-startup ()
    (princ "\nStartup Created in blackboard.lsp")
	;; automatically update any function in the blackboard.
	;; variable *shared-functions*.
	(if (vl-bb-ref '*shared-functions*)
	  (progn
	    (princ "\nEvaluating *shared-functions*")
	    (foreach func (vl-bb-ref '*shared-functions*)
	      (eval func)
	      )
	    )
	   (progn
	     (princ "\nThe Blackboard Variable *shared-functions* is nil")
	     (princ)	     
	     )
	  )
    (princ)
  )

;; we assume s::startup has been defined using defun-q
;;
(if (listp s::startup)
  ;; A response of T indicates that it is a list
     (setq s::startup (append s::startup
			      	(cdr my-startup) ; remove the nil
			      ))
  ;; s::startup is not a list so we create our own
  ;; s::startup function using my-startup 
     (setq s::startup my-startup)
  )

(princ "\nValue of s::startup")
(prin1 s::startup)

;;; s::startup is automatically evaluated by AutoCAD.
;;; All we need to do is propagate the function to all
;;; new documents.
;;;
;;; Note: By default it will be present
;;; in all existing documents.

(vl-propagate 's::startup)

;;;(princ "\nThe value of *shared-functions* (within this document) is: ") (prin1 *shared-functions*)
;;;(terpri)
;;;(princ "\nThe value of *shared-functions* ( as defined in the blackboard) is: ")
;;;(prin1 (vl-bb-ref '*shared-functions*))

(princ "\nBlackboard Example Initialized")
(princ)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -