Jump to content
BricsCAD123

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

Recommended Posts

BricsCAD123
Posted (edited)

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" "s" "z_xref" "exit" "")

















(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)
)

 

Edited by SLW210
Added Code Tags

Share this post


Link to post
Share on other sites
BIGAL

Try here use make as it will make the layer if not exist and set to current. Not tested.

 

; attach xref
(command "-layer" "m" "z_xref" "")

 

 

Share this post


Link to post
Share on other sites
BricsCAD123
1 hour ago, BIGAL said:

Try here use make as it will make the layer if not exist and set to current. Not tested.

 


; attach xref
(command "-layer" "m" "z_xref" "")

 

 

The xref's are still being assigned to layer "0"

Attach XR to dwg's PS Ammended.lsp

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...