PDA

View Full Version : Need help on running lisp appp of file opened using VLA-OPEN


g.deloach
2004-12-30, 02:00 PM
Below Is a small application I've been working on and either I'm suffering from to much hoiliday excitement or I'm just not understanding.

All I'm wanting to do is run a lisp program, (getmknums), on a series of drawings seleccted by the user. The drawings will load but I can't get the application to run on any drawing in the foreach loop. Below is my code and I'll appreciate any help you may be able to provide.

(defun C:samtest ()
(vl-load-com)
(setq FileLst (dos_getfilem
"Select Connection Sheets To Retrieve"
"C:\\"
"Drawing Files (*.DWG)|2_*.dwg"
)
)
;;; The line Above Prompts User to Select Dwgs To Create List (Result Ex: = "C:\\ABC-1234\\" "2_01.dwg" "2_05.dwg")
(setq ProjFldr (car Filelst)) ; Sets Variable To The Project Folder (Result Ex: "C:\\ABC-1234\\")
(setq DwgList (cdr Filelst)) ; Sets Variable for Dwg List (Result Ex: "2_01.dwg" "2_05.dwg")
(foreach d DwgList ; Create A Loop To Run The Code Below On Each Dwg In The List
(setq CurDwg (strcat ProjFldr d)) ; Sets Variable For Dwg To Be Opened (Result Ex: = "C:\\ABC-1234\\2_01.dwg")
;(Setq NextDwg (VLA-OPEN (VLA-GET-DOCUMENTS (VLAX-GET-ACAD-OBJECT)) Curdwg) ); Set Variable and Opens Dwg
;(C:getmknums)
(vla-activate
(vla-open (vla-get-documents (vlax-get-acad-object)) CurDwg)
)
(vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
(strcat "(command \"_.OPEN\")\n" Curdwg "\n")
)
(C:getmknums)
; THE LINE ABOVE IS MY PROBLEM. I HAVE A LISP FILE ALREADY LOADED THAT USES "GETMKNUMS" TO RUN IN ACAD FROM THE
; COMMAND PROMPT AND WHAT I WANT TO DO IS RUN THIS LISP APPLICATION ON EVERY DWG IN MY LIST.
(vla-close CurDwg :vlax-true) ; This Saves The Drawing
) ; End Foreach
) ; End Defun

Thanks in Advance,
Coyote

kennet.sjoberg
2004-12-30, 10:38 PM
Hi Coyote, this was fun in R12 but not longer. Variables and manually loaded lispfiles do not transfer from drawing to drawing, drawings do not share the same envioronment.
To open and close drawings in graphic mode is not a simple task, I suppose You have to create and run a scriptfile.
But before that You can try to load "getmknums" in a start up file.

: ) Happy Computing !

kennet

RobertB
2004-12-30, 10:56 PM
Kennet is correct in a sense. Visual LISP cannot handle the MDI very well. LISP runs in the Document context, which means that a routine started in one drawing cannot continue in another drawing (the running code is still in the original drawing). VBA is much better at this sort of thing. The other workarounds Kennet mentions are options also.

g.deloach
2004-12-31, 11:34 AM
.... thought it might be a better idea to use VB but I'm still working on understanding all the intriquecies of using the code. Looks like I've found the project to do a little more learning.

As always thanks for the help
George

CAB2k
2004-12-31, 05:27 PM
kennet's script file is my choice.
Save the data you want to share in a text file or the registry & have the lisp
grab the data when it starts up in the next drawing.