Results 1 to 5 of 5

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2020-07
    Posts
    7
    Login to Give a bone
    0

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

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


    Code:
    (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)
    )
    Last edited by Opie; 2020-08-04 at 02:47 PM. Reason: [code] tags added

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Adjusting the .lsp to set the layer the xref is assigned to?

    When using ObjectDBX, you have to stick with some rules when coding… For ex. command calls aren't allowed… So you should consider implementing your action through (vla-xxx) calls… Even then I don't believe you can achieve what you requested as (entmod) also isn't allowed and also setting current layer prior to attach isn't allowed (setvar 'clayer "z_xref")… For more info about ObjectDBX, look here - at very beginning of page it's explained what restrictions ObjectDBX method brings… http://www.lee-mac.com/odbxbase.html

  3. #3
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: Adjusting the .lsp to set the layer the xref is assigned to?

    Quote Originally Posted by wdobbin791223 View Post
    I have taken a .lsp from 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"
    From your description all you want is to change the layer the xref is inserted on. I can't understand why you appear to be trying to modify the drawing being referenced.
    Lisp to simply change the layer the xref is inserted on is a lot easier. If you attach a link to the original (working) lisp or post the code by clicking the [Go Advanced] button at the bottom of your Reply which puts a toolbar at the top and the # icon in that toolbar places code tags around
    Code:
    selected text
    for you or simply paste your code inside so that it displays correctly.

    Personally I prefer having all xrefed drawings on a layer with the same name as the drawing. When I xref drawing "ABC" I want it on layer "ABC".
    Lee Mac's Layer Director lisp may be you want. http://www.lee-mac.com/layerdirector.html

  4. #4
    Member
    Join Date
    2020-07
    Posts
    7
    Login to Give a bone
    0

    Default Re: Adjusting the .lsp to set the layer the xref is assigned to?

    The original code is:

    (defun c:RlxFaXref (/ _getfolder app adoc odbs odbx v xref folder dwg xr)
    (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)))
    ; save drawing
    (vla-saveas odbx (vla-get-name odbx))
    )
    )
    )
    )
    )
    (prince)
    )

    I would like it to incorporate the code below for every drawing I select using the "odbx"

    (setq oldlayer (getvar "CLAYER")) ;get the current layer first
    (command "-layer" "m" "z_xref" "c" "White" "z_xref" "exit" "") ;make and set preferences for z_xref layer
    (setvar "CLAYER" oldlayer) ;Return to original layer

  5. #5
    Member
    Join Date
    2005-01
    Posts
    18
    Login to Give a bone
    0

    Default Re: Adjusting the .lsp to set the layer the xref is assigned to?

    I'm no lisp expert but i use this:

    (defun c:InsertXref (/)
    (setq oldlayer (getvar "CLAYER")) ;get the current layer first

    (COMMAND "LAYER" "M" "Zz_30_30_ExternalReferences_" "C" "White" "" "") ;create layer and set colour

    (initdia)
    (command "_.-XREF" "_Overlay")
    (if (> (getvar "CMDACTIVE") 0)
    (progn
    (command "_None" '(0.0 0.0 0.0))
    (while (> (getvar "CMDACTIVE") 0) (command ""))
    )
    )
    (princ)
    (setvar "CLAYER" oldlayer)
    (command "_regenall")
    (command "_zoom" "E")

    )

Similar Threads

  1. Replies: 4
    Last Post: 2020-03-31, 07:04 PM
  2. Replies: 7
    Last Post: 2010-05-29, 10:03 AM
  3. 2008 SCALE 1:100 xref xref xref xref- scale list issues
    By Apsis0215 in forum AutoCAD Customization
    Replies: 2
    Last Post: 2008-11-21, 08:17 PM
  4. Replies: 12
    Last Post: 2005-08-10, 07:50 PM
  5. Replies: 0
    Last Post: 2004-09-21, 08:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •