Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Adjusting the .lsp to set the layer the xref is assigned to?

I have taken a .lsp from http://www.lee-mac.com/index.html and I want to alter it slightly so that the Xref can be assigned to a specific layer "z_xref" rather than having it on layer " 0"

I have written the command below however, I'm unsure where to put it in the lisp (also included below)

(command "-layer" "m" "z_xref" "")

(defun c:RlxPsXref (/ _getfolder RLXref_SetPathType app adoc odbs odbx v xref folder dwg xr lay)
(vl-load-com)
(defun _getfolder ( m / sh f r )
(setq sh (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application") f (vlax-invoke-method sh 'browseforfolder 0 m 0))
(vlax-release-object sh)(if f (progn (setq r (vlax-get-property (vlax-get-property f 'self) 'path))(if (wcmatch r "*\") r (strcat r "\")))))
; i is 0 (absolute), 1 (relative) of 2 (no) -xref path
(defun RLXref_SetPathType (i)
(vl-registry-write (strcat "HKEY_CURRENT_USER\" (vlax-product-key) "\Profiles\" (getvar "cprofile") "\Dialogs\XattachDialog") "PathType" i))
(setq odbs "ObjectDBX.AxDbDocument" v (substr (getvar 'acadver) 1 2) adoc (vla-get-activedocument (setq app (vlax-get-acad-object))))
(RLXref_SetPathType 1)
(cond
((vl-catch-all-error-p (setq odbx (vl-catch-all-apply 'vla-getinterfaceobject (list app (if (< (atoi v) 16) odbs (strcat odbs "." v))))))
(princ "\nObject DBX interface not created!"))
((not (setq xref (getfiled "Select Xref to attach" "" "dwg" 0))) (alert "No Xref was selected"))
((setq folder (_getfolder "Select folder with drawings to attach xref to"))
(foreach dwg (vl-directory-files folder "*.dwg" 0)
(setq dwg (strcat folder dwg))
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list odbx dwg)))
(princ (strcase (strcat "\nError opening: " dwg)))
(progn
(princ (strcat "\nOpening: " dwg))
; attach xref
(if (vl-catch-all-error-p (setq xr (vl-catch-all-apply 'vla-AttachExternalReference
(list (vla-get-ModelSpace odbx) xref (vl-filename-base xref) (vlax-3d-point 0 0 0) 1 1 1 0 :vlax-false))))
(princ (vl-catch-all-error-message xr))
(progn
(vlax-for lay (vla-get-layouts odbx)
(if (/= "MODEL" (strcase (vla-get-name lay))) (vlax-invoke odbx 'copyobjects (list xr) (vla-get-block lay))))
(vla-delete xr)
)
)
; save drawing
(vla-saveas odbx (vla-get-name odbx))
)
)
)
)
)
(princ)
)

Comments

  • Unfortunately (or Ironically) the Forum doesn't work well with code. It's best to attach the file to post.
    It doesn't look like Lee-Mac code. Looks to have been sourced from CAD Tutor
    https://www.cadtutor.net/forum/topic/66789-lisp-to-attach-xref-to-multiple-drawings

    To put the Xref on a given layer you're best not to use a command call, but work with the objects directly.

    (setq laynm "z_xref"); set target layer
    .
    .
    .
    ;Put Xref on desired Layer
    (setq oLayer (vla-get-layers odbx)) ; retrieve the layer object
    (vla-add oLayer laynm) ; Make sure the layer exists
    (vla-put-layer xr laynm) ; Put the xref on the desired layer

    BEWARE of code that sets values in the Registry. This code has a function that sets a registry value. This has meaning when used with AutoCAD, but won't work with BricsCAD.

    BricsCAD LISP also has functions not available natively in AutoLISP. For example, you can use DOS_GetDir to select a folder in BricsCAD. I recommend that you take a look at the Lisp Developer Support-Package to see what's available.

    Attach an updated version of the LISP code that will work in BricsCAD. Note I haven't tried to keep it compatible with AutoCAD.

    The LISP places (moves) the xref on the current paper space layout. If this isn't what you intended, then you can comment out this section of code.

    Regards,
    Jason Bourhill
    BricsCAD V20 Ultimate

    CAD Concepts

    lsp
    lsp
    RLxPsXref.lsp
    4K
Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam