ERROR WHEN RUNNING THIS LISP TO SET SYSVARS ETC.

This is a Lisp that most of the other LISPs in the suite I'm using accesses:


(defun Varopen ( / )
(vl-load-com) ;;;;command to load visual lisp add-on?
(setq ceho (getvar "CMDECHO"))
(setq blm (getvar "blipmode"))
(setq atd (getvar "attdia"))
(setq osm (getvar "osmode"))
(setq cl (getvar "clayer"))
(setq ar (getvar "attreq"))
(setq cls (getvar "cmleaderstyle"))
(setq angd (getvar "angdir"))
(setq osc (getvar "osnapcoord"))
(setq dz (getvar "dimzin"))
(setq ept (getvar "expert"))
(setq cs (atoi(vl-string-subst "" "1:" (getvar "cannoscale"))))
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "attdia" 0)
(setvar "osmode" 0)
(setvar "attreq" 1)
(setvar "angdir" 0)
(setvar "snapmode" 0)
(setvar "osnapcoord" 1)
(setvar "dimzin" 1)
(setvar "angbase" 0)
(setvar "expert" 5)
(setvar "cecolor" "bylayer")
(setvar "celtype" "bylayer")
(setvar "celweight" -1)
(vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
(princ)
)


(defun Varclose ( / )
(setvar "cmleaderstyle" cls)
(setvar "osnapcoord" osc)
(setvar "attreq" ar)
(setvar "cmdecho" ceho)
(setvar "blipmode" blm)
(setvar "attdia" atd)
(setvar "osmode" osm)
(setvar "clayer" cl)
(setvar "angdir" angd)
(setvar "expert" ept)
(setvar "dimzin" dz)
(vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
(princ)
)

Any LISP that contains the first line (varopen) returns an error message

; error : no function definition ; expected FUNCTION at [eval]

I'm guessing it's one of the visual LISP expressions? Do I need (VL-LOAD-COM) in Brics? I've checked the online archive of the Brics sysvars and I didn't see any vars that are different to what they're called in Acad, or any difference in the setting values. I don't get any errors when running the LISPs in AutoCAD2022 or 2023.

Comments

  • Hello,

    because this code uses (vla-...) functions, the (vl-load-com) is necessary under AutoCAD, but not under BricsCAD (for us, it is a harmless NoOperation);
    but
    (vl-load-com) should be better the first line in the file, outside (defun ...).

    From the error - it seems, the file containing the 2 functions, are simply not loaded ?
    Please check, in what file the 2 functions are located, and check whether and how it is loaded (or intended to be loaded).

    You can also run _APPLOAD comand, add that file, and check the "AutoLoad" option to have it always loaded (and move it up to first line).

    hope this helps ?
    many greetings !
  • Example of when varopen is called on by another LISP:

    (defun c:ALDBXDXF ( / sel1 Numobj Blockname LI DBLKLAY DDEPTH BDEPTH Lient BLKANG COORD )
    (varopen)
    (setq sel1 (ssget "x" '((0 . "INSERT")(2 . "DIAG_CROSS"))))
    (repeat (setq NumObj (sslength Sel1))
    (setq NumObj (1- NumObj) Blockname (ssname Sel1 NumObj))
    (setq DEPTH () CODE () )
    (GETATT Blockname)
    blah blah blah

    again, no issue running any of the LISPs in AutoCAD only BricsCAD and none of the LISPs that contain varopen as a command run in Brics.

    Thx

  • Because you have so many it may be easier to use a list approach that loops through the getvar and setvar. You can use set to convert "cecho" to a variable name.
    (("CMDECHO" "ceho" 0) ............)
  • The question is :
    where (in which Lisp file) is that function "(varopen)" defined ?
    As the error indicates, that (varopen) function is not defined, typically because the related Lisp file was not loaded ...

    Also, check your support pathes list (SRCHPATH variable in Settings dialog), whether all the folders, where your Lisp tools are located, are specified in SRCHPATH ...
    same logic as in AutoCAD.

    Then, you will need to check how that Lisp file (containing the "varopen" function) is loded under AutoCAD ... likely by Acad.lsp or AcadDoc.lsp ?
    If so, you can create an "on_doc_load.lsp" in any suitable SRCHPATH folder, and add such standard Lisp file loading into it.

    Again, most important :
    - which Lisp file defines "varOpen" function ?
    - how is that Lisp file loaded under AutoCAD ?

    many greetings !
  • So this is the on_start.lsp:

    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_00_COMMANDS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_3DP_ROUNDING.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_All_DEPTH_BLOCKS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_All_DEPTH_BLOCKS_WET.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_All_FEATURE_BLOCKS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_ALL_INVERT_BLOCKS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_ANNOTATE_SIZE.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_ANNOTATION_COPY.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_ANNOTATION_MOVE.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_AUTO_SCALE_1_VIEWPORT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_AUTO_SCALE_ALL_VIEWPORTS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_AUTO_XREF.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_BENCHMARK_BLOCK_INSERT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_BLOCK_FLIP_180.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_BOREHOLE_BLOCKS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_BOREHOLE_TABLE.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_CAD_SCALE_SETTINGS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_COORDINATE_RETRIEVAL.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_DEPTH_LEADER.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_DRAWING_VIEWPORT_INSERT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_FEATUREBLOCKS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_DWG_SETUP.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_DWG_SETUP.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_GET_BLOCK_ATTRIBUTES.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_GET_DRAWING_BLOCK.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_GET_VIEWPORTS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_LINE_LENGTHEN_3M.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_LINE_LENGTHEN_4M.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_LINE_LENGTHEN_5M.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_NDD_BLOCK_INSERT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_NDD_TABLE_INSERT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_NEARMAP_IMPORT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_NEW_LAYOUT_TABS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_NORTH_ARROW.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_PIT_LID_CIRCLES.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_PIT_TABLE_INSERT.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_POLYLINE_VERTEXES.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_SIZE_LEADER.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_STRING_TO_LIST.lsp")
    ;(load "C:\\APPDATA\\ACAD\\LISPS\\AUE_SUB-ROUTINES.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_SURVEYPOINTS.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_SYSVAR_LISP_SETTINGS.lsp") ;;;;contains the varopen and varclose defuns
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_TORIENT_CALL.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_UTILNAMECODE.lsp")
    (load "C:\\APPDATA\\ACAD\\LISPS\\AUE_EXPLODE_3D_LINES.lsp")

    It's a copy of the accadoc that's loaded by AutoCAD in the start-up suite. You can see I've removed AUE_SUB-ROUTINES from the load list.

    My feeling is that the varopen isn't loading because of one or multiple sysvar's being different between CAD and Brics or that one of the VL operations is incorrect.

    (setq cs (atoi(vl-string-subst "" "1:" (getvar "cannoscale")))) is the drawing scale called cannoscale in Brics?A google search seems like it is, the vl-string-subst is just stripping the 1: from the start of the variable.

    (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object))) are any of the VL operators wrong?

    If the defun c: for the rest of the LISPs are loaded (via group commands) and they instigate the lisp, but fail at varopen it shouldn't be an issue with loading the LISPs in general, there appears to be some issue with the varopen LISP specifically. If it was an issues with the LISP suite loading surely I wouldn't be getting to the varopen failing, I would be getting "didn't recognise the function" error. But if this was the case shouldn't I be getting a "couldn't load" error on start-up?
  • Found it!

    There's a load reference further up the list for a LISP that's not used in this specific suite "AUE_NDD_BLOCK_INSERT". This has been replaced by two other LISPs. I was getting a load error for that one LISP, but didn't expect the load to stop at that line and go no further. Once I removed that one load line things went back to working.

    Thanks for the help :)
  • Look into the "Autoload" function I think would be better way to manage lots of lisps. For me I have a custom menu or toolbar so lisp is loaded when required.
  • ...
    (setq cs (atoi(vl-string-subst "" "1:" (getvar "cannoscale"))))
    is the drawing scale called cannoscale in Brics?
    A google search seems like it is, the vl-string-subst is just stripping the 1: from the start of the variable.
    ...

    Yes, CANNOSCALE is a variable in Bricscad.
    But this function produces possibly undesired results if the active Annotation Scale name doesn't begin with "1:"
    In Bricscad's default-mm.dwt file, there are several names in the list that don't begin with "1:"
    In Bricscad's default-imperial.dwt, only one of the names begins with "1:"
  • Thanks for that Anthony. I don't work out of a default drawing, I have a predesigned template that contains all the relevant scales I will use, plus I have a LISP that sets all the cannonscales should I ever encounter the need for using a default instead of the predesign, but that's good to know.