Jump to content

Return to Original Drawing (LISP, script)


el_MI

Recommended Posts

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.

Link to comment
Share on other sites

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 path
dwgList (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 drawings
count 0 ; initiate counter
scrFile (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.

Edited by el_MI
attached code now properly posted
Link to comment
Share on other sites

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\\[color=red][b]YourDrawingName.dwg[/b][/color]"
   :vlax-false
 )
)

Tharwat

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...