XREF_ROUTINES_v3_01......................................free

Command: RX (Reload Xref)

This function reloads selected xref.

Command:XF (Xref Freeze)

This function freezes the layer of selected xref (xref stays loaded to the drawing but its on a frozen layer).

Command: XPU (Xref Path Update)

This function updates path of selected xref and reloads it. Might be handy when xref is not found (only path visible shown in modelspace) and the user wants to quickly load it. The user then just needs to pick not found xref and the program will take new path from clipboard and reload xref.The user has to copy new path to clipboard first.
Copying file path to clipboard can be done from windows explorer by editing and copying windows adress bar content or by selecting "Copy File Path" from the context menu, but requires FILE_PATH_UTILITY installed on windows, shown on the video. This useful tool can be downloaded from www.gnostice.com. I use Freecommander with keyboard shortcut assigned to a button.

 

Code:

;;; =================================================
;;;        XREF_RUTINES_v3_01.LSP
;;;
;;;        Written by Andrzej Kalinowski
;;;        v3.00 - 23.08.2016
;;;        v3.01 - 01.03.2019
;;;
;;;        Command: RX - reloads selected xrefs    
;;;        Command XF - freezes layer on which is the xref 
;;;
;;;        Command XPU - updates path of selected xref and reloads it. 
;;;                Might be handy xref is not found (only path visible shown in modelspace) wants to quickly load it. 
;;;                The user then needs to pick not found xref and program will take new path from clipboard and reload xref.
;;;                The user has to copy new path to clipboard first.
;;;
;;; =====================================
;;;                    RX               
;;; =====================================  
;23.08.2016
(defun c:RX (/ xref1 xname1 )
    (setq xref1 (SELECT_XREF) )
    (setq xname1 (cdr (assoc 2 (entget xref1))))
    (command "-xref" "_reload" xname1)
    (princ)
);end defun
;;; =====================================
;;;                    XF               
;;; =====================================  
;23.08.2016
(defun c:XF (/ xref1 xlay1 curlay)
    (setq curlay (getvar "CLAYER") )
    (setq xref1 (SELECT_XREF) )
    (setq xlay1 (cdr (assoc 8 (entget xref1) ) ) )
    (if (/= xlay1 curlay)
        (command "_-layer" "_f" xlay1 "")
        (alert "Xref is on the current layer")
    );if
    (princ)
);end defun
;;; =====================================
;;;                    XPU -Xref Path Update               
;;; =====================================  
;24.04.2017
(defun C:XPU ( / xref1 xpath1 pozslash strlen1 ext1)
    (setq xref1 (SELECT_XREF) );selecting xref
    (setq xpath1 (TXTFROMCLIPBOARD) );geting path (string type) from clipboard
    ;-----------------------------------------
    ;checks if the path is to a DWG file
    ;-----------------------------------------
    (setq
         strlen1 (strlen xpath1)
         ext1 (strcase (substr xpath1 (- strlen1 3) strlen1) )
    );setq
    (if (/= ext1 ".DWG") 
        (progn
            (princ "\nWrong path")
            (exit)
        );progn 
    );end if
    ;-----------------------------------------
    (setq xref1 (vlax-ename->vla-object xref1))
    (vlax-put xref1 "Path" xpath1);this line has troubles in GstarCAD
    (command "-xref" "_reload" (vlax-get xref1 'Name) )
    (princ)
);defun
;;; ================================================
;                     SELECT_XREF
;;; ================================================
(defun SELECT_XREF ( / xref1)
    ;-----------------------------------------
    ;object selection
    ;-----------------------------------------
    (setq xref1 nil)
    (prompt "select object")
    (while (= xref1 nil)
        (setq xref1 (ssget "_:S+.") )
        (if (= xref1 nil)
            (princ "\nwrong object");then
            (progn;else
                (if (> (sslength xref1) 1);checks if only 1 object is selcted
                    (progn;then
                        (princ "\nselect only one object. Object must be xref")(princ)
                        (setq xref1 nil)
                    );progn then
                    (progn ;else
                        (if 
                            (not
                                (and
                                    (= (vlax-property-available-p (vlax-ename->vla-object (ssname xref1 0)) 'Path))
                                    (= (vlax-get (vlax-ename->vla-object (ssname xref1 0)) 'ObjectName) "AcDbBlockReference")
                                );and
                            );not
                            (progn
                                (princ "\nSelected object is not an xref..")
                                (setq xref1 nil)
                            );progn
                        ); if 
                    ); else
                ); if   
            ); else
        ); if
    ); while
    (setq xref1 (ssname xref1 0))
  xref1
);defun
;;; =======================================================
;;;                          TXTFROMCLIPBOARD                           
;;; =======================================================
(defun TXTFROMCLIPBOARD (/ htmlfl PrntWndw CBdata txtstr1)
    (setq
            htmlfl (vlax-create-object "HTMLfile");starts application
            PrntWndw (vlax-get-property htmlfl 'ParentWindow)
            CBdata (vlax-get-property PrntWndw 'ClipBoardData)
    );setq
    ;(vlax-dump-object CBdata t);->displays supported methods: -> fod ClipboardData: clearData, GetData and SetData
    (setq
            txtstr1 (vlax-invoke-method CBdata 'GetData "TEXT");returns variant
            txtstr1 (vlax-variant-value txtstr1);Returns the value of a variant 
    );setq
    (vlax-release-object htmlfl)

    txtstr1
);defun

Example:

Download file: XREF_RUTINES_v3_01.FAS

No comments:

Post a Comment