el_MI 发表于 2022-7-6 08:54:37

Return to Original Drawing (LI

I have a LISP routine that opens a drawing related to the drawing already open, and another one that performs some layer manipulation in the 2nd drawing, does a COPYALL, and closes the 2nd drawing. What I haven't been able to figure out, through vast amount of internet searching along with trial and error, is how to be able to return to the original drawing and paste the contents. I can, of course, do it manually, but I'd like to automate it as much as possible.
 
I've tried various lisp and script routines, also nested variations of those. The result is either a process halts due to the file opening, or a script or lisp doesn't wait for the previous one to complete before it runs. Does what I'm trying to do even sound possible??? If so, any light that can be shed on this would be greatly appreciated. Thanks.

Tharwat 发表于 2022-7-6 09:12:53

Welcome to the forum .
 
I guess you need the function *vla-activate* which would activate the needed drawing .
 
Regards,
 
Tharwat

el_MI 发表于 2022-7-6 09:20:52

Tharwat,
Thanks for your help. I have added four lines of code related to vla-activate, as suggested, but the results are still the same.
 

(defun c:GS (/ dwgPath dwgList dwgName numDwgs count scrFile)(setq dxfPath "C:\\Documents and Settings\\el_MI\\my documents\\auto_lisp\\tests\\" ; sets the pathdwgList (vl-directory-files dxfPath "*.dwg") ; get the list of all the dxf's)(if dwgList ; if dwg files exists there(progn(setq numDwgs (length dwgList) ; number of drawingscount 0 ; initiate counterscrFile (open (strcat dxfPath "Runme.scr") "w") ; open a script file in the same folder)(repeat numDwgs ; for all the drawings(setq dwgName (strcat "\"" dxfpath (nth count dwgList) "\""))(write-line ".Open" scrFile) ; write to script file(write-line dwgName scrFile)(write-line ".delay 500" scrFile);;;If you need to load a lisp routine in each dwg; (write-line "(load \"OutlineLayer.LSP\")" scrFile) ; load any required lisp routine;;; Enter your commands here.(write-line "(c:ol)" scrFile)(write-line ".delay 500" scrFile);;;(setq count (1+ count)); next dwg)(close scrFile) ; close when done(command ".script" (strcat dxfpath "Runme.scr")) ; run the script); progn); if;(setq documents (vla-get-documents (vlax-get-acad-object)));(setq DwgFile "373_0001.dwg");(setq doc1 (vla-item documents DwgFile));(vla-activate doc1)(command ".pasteorig")(princ)) ; defun
 
Any commands following the script write/run are executed immediately, without waiting for the script to complete. In this case, anything in the clipboard is pasted before the script runs. If it would wait for the script to be complete, the correct entities would be pasted.
 
I know this because if I leave the pasteorig out of the code, and wait for the sript to run, and THEN type PASTEORIG, everything is good. Thanks again for your help.

Tharwat 发表于 2022-7-6 09:34:35

First please read this and use the codes Posting Guidelines .
 
http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines&p=51051&viewfull=1#post51051

Tharwat 发表于 2022-7-6 09:43:51

At the moment , here is what I use for vla-activate function and implemented with your drawing file path ..
 

(setq acdoc (vla-get-documents (vlax-get-acad-object)))(vla-activate (vla-open   acdoc   "C:\\Documents and Settings\\el_MI\\my documents\\auto_lisp\\tests\\YourDrawingName.dwg"   :vlax-false ))Tharwat

el_MI 发表于 2022-7-6 10:05:08

Thank you for that quick response. So what happens now is the drawing specified immediately opens. When I Ctrl/tab back to the original drawing from which the lisp is called, the lisp then runs. Once this is done, I can manually paste to either drawing, as this is till not automated. I tried this both SDI=0 and SDI=1.
页: [1]
查看完整版本: Return to Original Drawing (LI