COPY_BETWEEN_SESSIONS_v1_01....................free

Command: COPYBS

This test function copies selected objects between opened documents (it is- between activespaces of those documents). Program has limitation to two opened sessions

 

Code:

;;; ================================================
;;;        COPY_BETWEEN_SESSIONS_v1_01.LSP     
;;;
;;;        Written by Andrzej Kalinowski,     www.autolisps.blogspot.com
;;;        v1.00 - 12.04.2020 - first release
;;;        v1.01 - 22.05.2020 - fixed bug with second session = nil
;;;
;;;        Command: COPYBS
;;;            This function copies selected objects between opened documents (it is- between activespaces of those documents)
;;;            Program has limitation to two opened sessions
;;;
;;; ================================================
(defun c:COPYBS ( / ss1 i1 vlaObjLst curobj1 actDoc1 safArr1 docLst actspc2 doc1)
    (if (setq ss1 (ssget) )
        (progn
            ;-----------------------------------------
            ;creating list of vla-objects from selection set
            ;-----------------------------------------
            (repeat (setq i1 (sslength ss1) )
                (setq i1  (1- i1) )
                (setq curobj1 (vlax-ename->vla-object (ssname ss1 i1) ) )
                (setq vlaObjLst (cons curobj1 vlaObjLst) )
            );repeat
            (setq safArr1 (vlax-make-safearray vlax-vbObject  (cons 0 (1- (length vlaObjLst))) )  )
            (vlax-safearray-fill safArr1 vlaObjLst)
            ;-----------------------------------------
            ;getting documents
            ;-----------------------------------------
            (setq actDoc1 (vla-get-activedocument (vlax-get-acad-object)));activeDoc1
            (setq docLst (list) )
            (vlax-for doc1
                (vla-get-documents (vlax-get-acad-object) ) ;collection
                (setq docLst (cons doc1 docLst) ) 
            );vlax-for
            (if (or (> (length docLst ) 2) (= (length docLst ) 1) ) (progn (princ "\nThis program works only with max 2 opened sessions.") (exit) ) )
            (if (equal (cadr docLst) actDoc1)    (setq docLst (reverse docLst ) ) );placing base document in first position
            ;-----------------------------------------
            ;getting active space in second document
            ;-----------------------------------------
            (setq actspc2 (vla-get-activespace (cadr docLst) ) ); returns 1 - model; 0-paperspace
            (if (= actspc2 1)
                (setq actspc2 (vla-get-modelspace (cadr docLst) ) )
                (setq actspc2 (vla-get-paperspace (cadr docLst) ) )
            );if
            ;-----------------------------------------
            ;copying objects
            ;-----------------------------------------
            (vla-copyobjects
                actDoc1 ;this document
                safArr1  ; our collection to be copied
                actspc2 ;destination place (can be model or layout in current document or in another document.)
            );vla-copyobjects
            (vla-put-activedocument (vlax-get-acad-object) (cadr docLst) )
        );progn
    );if
    (princ)
);defun

Example:

Version history:
1.00 - 12.04.2020 - first release

1.01 - 22.05.2020 - fixed bug with second session = nil

 Compatibility:
-All Autocad
versions

Remarks:
-The application comes with the long command names listed above. To create your own short aliases for these commands, go to ACAD.PGP file or Menu Manage->Customization->Edit aliases->Edit Aliases.


Download file: COPY_BETWEEN_SESSIONS_v1_01.FAS

No comments:

Post a Comment