copy contents of another file into active document

copy contents of another file into active document

tomasz.wilk
Observer Observer
487 Views
4 Replies
Message 1 of 5

copy contents of another file into active document

tomasz.wilk
Observer
Observer

Hi,

 

I'm trying to copy contents of another file into the active document. I have found numerous example on the net for this - none working for me. Below is the code I'm using and it is the n-th iteration - a mixture of what I thoght would work:

(defun openblk (/ adocs)
  (setq tl_path "G:\\temp\\transform2000toLocal.dwg")
  (setq acDocs (vla-get-documents (vlax-get-acad-object)))
  (setq nWin (vla-open acDocs tl_path))
  (vla-sendcommand nWin (strcat "copyclip " "w " "0,0 " "74200000,58400000 "))
  (vla-sendcommand nWin " ")
  (vla-close nWin :vlax-false)
  (command "pasteorig")
)


(openblk)

Contrary to what I would like it to do, it selects objects for copyclip from the original file and not the opened file and then it hangs on "Select objects:" query - thus the second vla-sendcommand. It never runs it though.

 

What I would like it to do is to open specific file, copy to clipboard from the opened file and paste to the original coordinates in the original file. I don't know what else to try. Can you help?

 

Cheers

0 Likes
Accepted solutions (1)
488 Views
4 Replies
Replies (4)
Message 2 of 5

martti.halminen
Collaborator
Collaborator
Accepted solution

The fundamental problem here is that when using the Multiple Document Interface mode, each open document has its own Lisp environment, which do not communicate with each other (with a few minor exceptions). So your program dies after the vla-open call, and the new document has no functions running.

 

One somewhat brute-force approach: instead of opening the other file, insert it into the original file as a block. (somewhere on the side so it doesn't mix with the original stuff.)

- explode as needed

- copy the parts you were interested in

- delete the rest

- purge

0 Likes
Message 3 of 5

paullimapa
Mentor
Mentor

Along the lines of @martti.halminen excellent reply, the code would start with Undo Mark, offer the option to select the drawing to copy objects from, Insert the selected drawing as exploded objects, have user select objects to copy, then in the background perform a Wblock of the selected objects to acad temp folder, Undo Back to original Mark and then Insert the wblock dwg from the temp location...and if desired close the routine by deleting the wblock.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

This worked, it uses a script so you would write the script using lisp with correct dwg names to suit, I had dummy c3.dwg and read objects out of c2.dwg. (setq dwgname (strcat (getvar 'dwgprefix)(getvar 'dwgname))) will get current dwg name. Closing current dwg makes it work.

 

 

 

(command "close" "Y")
open "D:/acadtemp/c2.dwg"
(command "copyclip" "w" "0,0" "74200000,58400000" "")
close
n
open "D:/Acadtemp/c3.dwg"
pasteorig

 

 

 

 

0 Likes
Message 5 of 5

tomasz.wilk
Observer
Observer

Thank you Good Sirs for the splendid suggestions. This is the code I ended up with, based on the insert drawing as block suggestion:

;explode block by name
(defun bx(bname)
(setq SS1 (ssget "X" (list '(0 . "INSERT") (cons 2 bname))))
(command "explode" SS1)
(princ))

;delete block by name
(defun bke (bname)
(setq SS1 (ssget "X" (list '(0 . "INSERT") (cons 2 bname))))
(command "erase" ss1 "")
(command "-purge" "B" bname "N" "")
(command "_regenall")
(princ)
)

(setq ssa(ssget "_A"))

(setq tl_path "G:\\temp\\transform2000toLocal.dwg")
(command "-DWGUNITS" "6" "2" "4" "Y" "Y" "N")
(command "_.-insert" tl_path '(0. 0. 0.) "1" "" "0" "")
(bx "transform2000toLocal")

;do relevant things here

;cleanup
(setq ss (ssget "_x" '((0 . "*LINE") (8 . "transfer_layer"))))
(command "_ERASE" ss "")
(bke "transform2000toLocal")

dwgunits command was necessary because the units were messed up and the inserted file was mispositioned.

 

Great Thanks.

0 Likes