fantasyfly 发表于 2007-9-29 15:36:00

acad.lsp 中如何判断已加载了VBA工程

<p>(defun s::startup()<br/>&nbsp;;(if (not S::startup)<br/>&nbsp;;(setvar "cmdecho" 0)<br/>&nbsp;(command "_vbaload" "C:\\Program Files\\AA\\AA.dvb")<br/>&nbsp;(command "_vbarun" "AA")<br/>;(setvar "cmdecho" 0)<br/>&nbsp;(princ)<br/>)</p><p>这是加在ACAD.LSP里的语句,就是启动CAD时自动运行VBA程序.</p><p>我如何时才能判断是否已经加载了AA.DVB?以避免出现已加载的提示.</p><p>谢谢各位朋友.</p>

fantasyfly 发表于 2007-9-29 16:09:00

<p>(defun s::startup()<br/>&nbsp;;(if (not S::startup)<br/>&nbsp;;(setvar "cmdecho" 0)<br/>&nbsp;(command "_vbarun" "C:\\Program Files\\AA\\AA.dvb!thisdrawing.AA")<br/>;(setvar "cmdecho" 0)<br/>&nbsp;(princ)<br/>)</p><p></p><p>为何在未启动CAD时,同时打开多个DWG图就会导致CAD死掉,</p><p>而在已启动CAD时,同时打开多个DWG图却没有问题?</p>

yhjyhjyhj 发表于 2010-9-17 09:37:00

第四个例子是一个LISP例程。它使用相同的ActiveX对象判断一个工程是否已经加载,如果没有,就加载它。




(defun c:loadMyProject ()
;; This routine will load a project if it is not already loaded
;; the VBE (VB extensibility) ActiveX object is used to reference
;; the loaded projects
;; Load ActiveX
(vl-load-com)
;; Get the VBE extisibility object
(setq acadObject (vlax-get-acad-object))
(setq acadVbe (vla-get-vbe acadObject))
(setq acadVbeProjects (vlax-get-property acadVbe 'VBProjects))
;; Get the number of loaded VBA projects
(setq int1 (vlax-get-property acadVbeProjects 'count))
;; Counter and test variable named loaded
(setq int2 1)
(setq loaded "False")
;; Repeat for each project
(repeat int1
;; Itereate through the projects, getting the name of
;; next project, each time through
(setq Item (vlax-invoke-method acadVbeProjects 'Item int2))
(setq pName (vlax-get-property Item 'Name))

;; Test the name for the name of the project I want to load
;; If it is already loaded the set the test variable to True
(if (= pName "my_test_project")
(progn
   (prompt "\nmy_test_project is already loaded\n")
   (Setq Loaded "True")
)
)
;; Increment the number used to get the next Project
(setq int2 (+ int2 1))
)
;; Load project if it is not already loaded by testing
;; the Loaded variable
(if (= Loaded "False")
(progn
(princ "\nLoading my_test_project")
(command "-VBALOAD"
            "D:/vba-apps/a-2000/already loaded test.dvb"
)
)
页: [1]
查看完整版本: acad.lsp 中如何判断已加载了VBA工程