Help Request: Debugging SAVEFORMAT Toggle Program Code

The code is generating an incorrect data type as a linear unit (in this case, it is foot-inch based) instead of the SAVEFORMAT variable desired:

"1" - for 2018 DWG and

"26" for R11/12 ASCII DXF.

Can you review and provide instruction?

Note: It is critical to save to the R11/12 ASCII DXF file format for compatibility purposes.

CODE START

;File: ToggleSaveFormat.lsp
;ToggleSaveFormat - Toggles the file type between Release 11/12 ASCII DXF and 2018 DWG file formats.
;Source: AI
;By: Clint Hill
;Creation Date: August 08, 2024;
;------------------------------------------------------------------------
;
(defun c:ToggleSaveFormat (/ currentSaveFormat)
;; Get the current value of the SAVEFORMAT variable
(setq currentSaveFormat (getvar "SAVEFORMAT"))
;; Check if the current value is 1, and set it to 26, or vice versa
(if (= currentSaveFormat "1")
(setvar "SAVEFORMAT" "26")
(setvar "SAVEFORMAT" "1")
)
;; Print the new SAVEFORMAT value to the command line
(princ (strcat "\nSAVEFORMAT set to: " (rtos (getvar "SAVEFORMAT"))))
(princ)
)

CODE END

Thanks,

Clint

Comments

  • (getvar "SAVEFORMAT") returns an integer not a string. If you remove the speach marks around your values, then your code will work.

    (defun c:ToggleSaveFormat (/ currentSaveFormat)
    ;; Get the current value of the SAVEFORMAT variable
    (setq currentSaveFormat (getvar "SAVEFORMAT"))
    ;; Check if the current value is 1, and set it to 26, or vice versa
    (if (= currentSaveFormat 1)
    (setvar "SAVEFORMAT" 26)
    (setvar "SAVEFORMAT" 1)
    )
    ;; Print the new SAVEFORMAT value to the command line
    (princ (strcat "\nSAVEFORMAT set to: " (itoa (getvar "SAVEFORMAT"))))
    (princ)
    )

  • Clint2U
    edited August 12

    The issue continues to show:

    After removing the double quotes / "speech" marks around the SAVEFORMAT values 1 and 26 and reloading the program, the command line shows the values are still interpreted as a string i.e., 1" and 2'-6" instead of as an integer.

    Any insights from Jason or other LISP-experienced experts are valued!

    - Clint

  • It looks like your Linear Units (LUNITS) are set to architectural. In the code you provided you're using https://developer.bricsys.com/bricscad/help/en_US/CurVer/DevRef/source/rtos.htm to convert the system variable number to a string. Unless you specify otherwise rtos will respect the setting of LUNITS.

    You can test this for yourself by simply calling rtos by itself from the command line.

    : (rtos 26)
    "2'-2""

    As this system variable is an integer, you could use https://developer.bricsys.com/bricscad/help/en_US/CurVer/DevRef/source/itoa.htm instead. This avoids the need to worry about LUNITS.

    : (itoa 26)
    "26"

  • Just a comment on Toggling the SAVEFORMAT in this manner. This system variable is saved to your profile, meaning every drawing file you open will save to this format by default. This could give unintended results if the user isn't aware. e.g. they open a .dwg file make some changes and then save but because SAVEFORMAT is set to 26 it's saved to .dxf not .dwg resulting in duplicate drawing files. Ideally you would always work in .dwg and only ever export to .dxf.

    If you want to be able to open and edit dxf files, then save again as dxf, then this utility will automatically set your saveformat for you. You can customise the LISP to your preferred .dwg and .dxf formats.

    https://www.cadconcepts.co.nz/resources/set-save-format

    Previously discussed here

  • Hi Jason,

    The SetSaveFormat.lsp program is promising however, for some reason, the following message appears.

    At my current LISP skill level, I cannot figure out how to correct it.

    COMMAND LINE CODE START

    ; ----- Error around expression -----
    ; (C:SETSAVEFORMAT)
    ;
    ; error : no function definition <C:SETSAVEFORMAT> ; expected FUNCTION at [eval]

    CODE END

    Thanks,

    Clint

  • The intention of this lisp is to automatically set the save format to match the currently open file.

    If you open a dxf then it will change the save format to R12 dxf otherwise the default will be R2013 dwg, both of which can be changed to what ever release you wish.

    I never intended it to be called manually. Jason B gets the credit for this code.

    I added additional information to my working copy.

  • Craig,

    I thank you for clarifying the purpose and intended functionality of this great LISP.

    Clint