See the top rated post in this thread. Click here

Results 1 to 2 of 2

Thread: Lisp error?

  1. #1
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Lisp error?

    I have a .lsp that assigns Xref's to a layer when certain commands are carried out. the routine seems to work fine however there is an warning displayed each time - error: AutoCAD variable setting rejected: "clayer" nil.

    would someone be able to advise on how to fix this, thanks in advance.

    see below code

    (if (null myxr-react)
    (setq myxr-react (vlr-command-reactor nil '((:vlr-commandwillstart . myxr-swaplayer)
    (:vlr-commandended . myxr-restorelayer)
    (:vlr-commandcancelled . myxr-restorelayer))))
    )

    (defun setormakelayer (layn doc)
    (if (null (tblsearch "layer" layn))
    (vla-add (vla-get-layers doc) layn))
    (setvar "clayer" layn)
    )

    ;;commandwillstart callback (reactor commandlist)
    (defun myxr-swaplayer (r cl / doc)
    (if (wcmatch (strcase (car cl)) "*ATTACH,*XCLIP*,*XREF");allowance for other commands
    (progn
    (setq doc (vlr-document r))
    (vlr-data-set r (getvar "clayer"))
    (if
    (= 1 (vla-get-activespace doc))
    (setormakelayer "_XREF" doc)
    (setormakelayer "_XREF" doc)
    ))))

    ;;commandended callback (reactor commandlist)
    (defun myxr-restorelayer (r cl)
    (if (wcmatch (strcase (car cl)) "*ATTACH,*XCLIP*,*XREF");allowance for other commands
    (vlr-data r))
    (setvar "clayer" (vlr-data r))
    (vlr-data-set r nil)
    )
    )

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

    Default Re: Lisp error?

    Here you are...
    I simplified it very much :

    Code:
    (vlr-remove-all)
    
    (if (null myxr-react)
      (setq myxr-react (vlr-command-reactor nil
      '((:vlr-commandwillstart . myxr-swaplayer)
        (:vlr-commandended . myxr-restorelayer)
        (:vlr-commandcancelled . myxr-restorelayer)
       )
      ))
    )
    
    (defun setormakelayer (layn doc / oldlay)
      (if (null (tblsearch "layer" layn))
        (vla-add (vla-get-layers doc) layn)
      )
      (setq oldlay (getvar "clayer"))
      (setvar "clayer" layn)
      oldlay
    )
    
    ;;commandwillstart callback (reactor commandlist)
    (defun myxr-swaplayer (r cl / doc)
      (if (wcmatch (strcase (car cl)) "*ATTACH,*XCLIP*,*XREF");allowance for other commands
        (progn
          (setq doc (vlr-document r))
          (setq oldlay (setormakelayer "_XREF" doc))
        )
      )
    )
    
    ;;commandended callback (reactor commandlist)
    (defun myxr-restorelayer (r cl)
      (if oldlay
        (progn
          (setvar "clayer" oldlay)
          (setq oldlay nil)
        )
      )
    )
    HTH.

Similar Threads

  1. Lisp Error ; error: bad argument type: stringp nil
    By The1stCADMAN in forum AutoLISP
    Replies: 2
    Last Post: 2017-08-29, 12:04 PM
  2. Running a lisp from within a lisp?
    By joe.plazio in forum AutoLISP
    Replies: 9
    Last Post: 2008-03-04, 04:45 AM
  3. lisp within a lisp
    By chrisw.94380 in forum AutoLISP
    Replies: 5
    Last Post: 2006-04-07, 12:57 AM
  4. Calling a lisp from within a lisp
    By LanceMcHatton in forum AutoLISP
    Replies: 10
    Last Post: 2005-10-16, 02:08 AM
  5. non lisp cursor location for lisp getpoint
    By dtuttle in forum AutoLISP
    Replies: 3
    Last Post: 2005-05-10, 11:37 PM

Tags for this Thread

Posting Permissions

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