mhupp Posted June 9 Share Posted June 9 (edited) I do remember BricsCAD execute lisp code to other drawings that where already open. --edit found the post but it didn't work in AutoCAD back then either. ;;----------------------------------------------------------------------------;; ;; Copy Selection to All open Drawings works in BrisCAD ;; https://www.cadtutor.net/forum/topic/86226-returning-focus-to-excel-after-lisp-ends/ (defun C:Copy_to_All_Drawings () (C:C2AD)) (defun C:C2AD (/ ss x) (vl-load-com) (setq ss (ssget)) (vl-cmdf "_.Copybase" "_non" "0,0" SS "") (vlax-for x (vla-get-documents (vlax-get-acad-object)) (vla-SendCommand x (strcat "_.pasteclip pause")) ) (princ) ) Edited June 9 by mhupp 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 10 Author Share Posted June 10 nevertheless thanx for your effort to find it.. Quote Link to comment Share on other sites More sharing options...
rlx Posted June 10 Share Posted June 10 (edited) probably not exactly what you want but should be relatively easy to modify to copy to all open drawings ;;; copy to drawing (defun ctd ( ss dwg / ss->ol dbx_ver acApp acDoc dbx object-list object-safe-array) (defun SS->OL (ss / i l) (setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) (defun dbx_ver ( / v) (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))) (setq acApp (vlax-get-acad-object) acDoc (vla-get-ActiveDocument acApp)) (setq dbx (vl-catch-all-apply 'vla-getinterfaceobject (list acApp (dbx_ver)))) (vla-open dbx dwg) ; put all block objects in a list (foreach object (ss->ol ss) (setq object-list (cons object object-list))) ; put list with objects in a safe array (setq object-safe-array (vlax-make-safearray vlax-vbobject (cons 0 (1- (length object-list))))) (vl-catch-all-apply 'vlax-safearray-fill (list object-safe-array object-list)) ; copy objects to wblock-dbx-container (vla-CopyObjects acDoc object-safe-array (vla-get-ModelSpace dbx)) (vl-catch-all-apply 'vla-saveas (list dbx dwg)) (vl-catch-all-apply 'vlax-release-object (list dbx)) (setq object-list nil object-safe-array nil) (princ) ) (defun c:t1 ( / ss dwg ) (if (and (setq ss (ssget))(setq dwg (getfiled "Copy objects to :" (getvar 'dwgprefix) "dwg" 0)))(ctd ss dwg))(princ)) maybe : ;;; copy to all open doc (defun ctaod ( / ss ss->ol dbx_ver acApp acDoc dbx object-list object-safe-array) (defun SS->OL (ss / i l) (setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) (defun dbx_ver ( / v) (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))) (setq acApp (vlax-get-acad-object) acDoc (vla-get-ActiveDocument acApp)) ;;; select objects (setq ss (ssget)) ; put all objects in a list (foreach object (ss->ol ss) (setq object-list (cons object object-list))) ; put list with objects in a safe array (setq object-safe-array (vlax-make-safearray vlax-vbobject (cons 0 (1- (length object-list))))) (vl-catch-all-apply 'vlax-safearray-fill (list object-safe-array object-list)) ;;; copy objects to all open docs except active doc (vlax-for x (vla-get-documents (vlax-get-acad-object)) (if (not (eq x acDoc)) (progn (vla-CopyObjects acDoc object-safe-array (vla-get-ModelSpace x)) (vla-save x) ) ) ) (princ) ) Edited June 10 by rlx 1 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 11 Author Share Posted June 11 thank you very much, although i'm not familiar with part of instructions used , i can see it will be useful although my goal is to copy ss to only one newly created drawing in every pass of one big loop, so i will try to modify it accordingly to accept name for new file and create it, and then copy to it, save it and close it... Quote Link to comment Share on other sites More sharing options...
rlx Posted June 11 Share Posted June 11 ;;; copy to new doc (defun ctnd ( ss new-dwg-name / SS->OL dbx_ver acApp acDoc dbx object object-list object-safe-array) (defun SS->OL (ss / i l) (setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) (defun dbx_ver ( / v) (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))) (setq acApp (vlax-get-acad-object) acDoc (vla-get-ActiveDocument acApp)) (setq dbx (vl-catch-all-apply 'vla-getinterfaceobject (list (vlax-get-acad-object) (dbx_ver)))) (vl-catch-all-apply 'vla-saveas (list dbx new-dwg-name)) ; put all objects in a list (foreach object (ss->ol ss) (setq object-list (cons object object-list))) ; put list with objects in a safe array (setq object-safe-array (vlax-make-safearray vlax-vbobject (cons 0 (1- (length object-list))))) (vl-catch-all-apply 'vlax-safearray-fill (list object-safe-array object-list)) ; copy objects to wblock-dbx-container (vla-CopyObjects acDoc object-safe-array (vla-get-ModelSpace dbx)) (vl-catch-all-apply 'vla-saveas (list dbx new-dwg-name)) (vl-catch-all-apply 'vlax-release-object (list dbx)) (setq object-list nil object-safe-array nil) (princ) ) (defun c:t2 ( / ss new-dwg ) (if (and (setq ss (ssget))(setq new-dwg (getfiled "Copy objects to :" (getvar 'dwgprefix) "dwg" 1))) (ctnd ss new-dwg) ) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 11 Author Share Posted June 11 (edited) well, what to say, you're too fast that is it THANX...will name it accordingly rlx:ctnd Edited June 11 by Tomislav Quote Link to comment Share on other sites More sharing options...
rlx Posted June 11 Share Posted June 11 You're welcome (although I feel I just created lisp version for the wblock command ) 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 11 Author Share Posted June 11 (edited) would you believe me, this is first time i've heard of that command , always using block/insert... one line of code gives me error: Automation Error. Invalid owner object; this one (vla-CopyObjects acDoc object-safe-array (vla-get-ModelSpace dbx)) Edited June 11 by Tomislav Quote Link to comment Share on other sites More sharing options...
rlx Posted June 11 Share Posted June 11 dont have this error myself... do you use (vl-load-com) in your startup? but wblock alternative : (defun c:t3 ( / ss fn) (setq ss (ssget) fn "c:/temp/rlxie.dwg") (setvar 'filedia 0) (command "-wblock" fn "" "0,0" ss "" "oops") (setvar 'filedia 1) (princ) ) loose the "oops" if objects must be deleted from source drawing Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 11 Author Share Posted June 11 yes, specifically error comes from (vla-get-ModelSpace dbx) this, wblock is really nice short one Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 11 Author Share Posted June 11 (edited) what is interesting, your ctnd works on its own, but inserted in my lisp gives mentioned error, so i'm really confused there... could it be my ss includes objects that can't be copied, so i should filter it or something? Edited June 11 by Tomislav Quote Link to comment Share on other sites More sharing options...
rlx Posted June 11 Share Posted June 11 (edited) cant reproduce your error , all sunny on my side maybe change last line to (setq object-list nil object-safe-array nil dbx nil) or set some debug points in your lisp editor and see if for example object-list / safe-array is created correctly else use wblock , maybe not high-tech but if it gets the job done, who cares. well I'm of to site for a couple of hours now... ps. and check if your filename has no invalid characters in it Edited June 11 by rlx 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.