Lisp file to save drawing to AutoCAD Release 11/12 ASCII DXF (*.dxf)

I am new to Bricscad. I have had some experience with creating lisp's in Autocad, but it feels intimidating trying to figure out how to do this in Bricscad. I've done a bit of internet searching looking for what I need, but no luck so far.

I would like to create a lisp called SPF that saves the current drawing to AutoCAD Release 11/12 ASCII DXF (*.dxf), which is $ACADVER "AC1009".

This is the drawing version requirement for the customers Plasma cutter. Any help is appreciated!

Comments

  • Usually lisp functions work the same in Bricscad as in Autocad. They put a lot of effort into compatibility. Do you have a lisp function that does what you want in Autocad but doesn't work in Bricscad? If so, you should post it and maybe someone will be able to see the problem. And Bricsys will probably make it work properly in the next release.

    To save in R11/12 ASCII DXF format, you'd need to set the SaveFormat variable to 23 temporarily. So use (setq OldFormat (getvar "SaveFormat")) to save the current save format, then (setvar "SaveFormat" 23) to change it, then execute the Save command (command "_SaveAs"), maybe with something about filename and/or path, and then restore the previous save format (setvar "SaveFormat" OldFormat).

  • Anthony: I do not have an old lisp routine that does this. It is a new one for me that I am hoping to cut down on keyboard/mouse input. In my previous project there were 195 individual plasma files to open, edit, and save.

  • OK, understood. To create the new lisp function that you want, just put all the functions I gave you, in that order, inside a (defun) function. To make it a custom command, put a C and a colon in front of the function name.

  • You can use DXFOUT and maybe saveformat 25.

  • Below is my lisp routine. As the APPLOAD window screenshot shows, SPD is loaded but Bricscad is not recognizing the SPD command. Am I missing something in the code?

    ; SPD - Save Plasma Drawing
    ; Save the DXF plasma drawing to AutoCAD Release 11/12 ASCII DXF (.dxf)
    ; 17 = AutoCAD 2000 ASCII DXF (
    .dxf)
    ; 26 = AutoCAD Release 11/12 ASCII DXF (*.dxf)
    (defun SPD
    (setq OldFormat (getvar "SaveFormat")) ; save the current save format
    (setvar "SaveFormat" 26) ; to change it to AutoCAD Release 11/12 ASCII DXF
    (command "_SaveAs") ; run Save As command
    (setvar "SaveFormat" OldFormat) ; restore the previous save format
    )

    (SPD) ; auto run on loading

  • Anthony Apostolaros
    edited June 25

    Good work. But you need a pair of parentheses after the name of the function. Change (defun SPD to (defun SPD ().

    Then you'll have defined a function, and the user can execute that function by entering (SPD) on the command line. Bricscad accepts lisp functions on the command line. But if you want the user to be able to execute it without the parentheses, you have to convert the function to a custom command, by changing (defun SPD () to (defun c: SPD (). Then it'll work without the parentheses, and it won't work with them.

    You should add an error-handling function that restores the SaveFormat variable in the event of an unexpected termination of the function. Without that, if the user cancels the SaveAs command, then that will end the processing of the function at that point. The SaveFormat variable won't be changed back to its initial value. DXF R11/12 will remain as the default save format. Future saves will also be in that format, and the user won't even know.

  • JimWebster
    edited June 25

    The below is my updated version:

    ; SPD - Save Plasma Drawing
    ; Save the DXF plasma drawing to AutoCAD Release 11/12 ASCII DXF (.dxf)
    ; 17 = AutoCAD 2000 ASCII DXF (
    .dxf)
    ; 26 = AutoCAD Release 11/12 ASCII DXF (*.dxf)
    (defun c:SPD ( / OldFormat )
    (setq OldFormat (getvar "SaveFormat")) ; save the current save format
    (setvar "SaveFormat" 26) ; to change it to AutoCAD Release 11/12 ASCII DXF
    (command "_SaveAs") ; run Save As command
    (setvar "SaveFormat" OldFormat) ; restore the previous save format
    )

    (SPD) ; auto run on loading

    This is the error message when I load Bricscad:

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

  • Anthony Apostolaros
    edited June 25

    The C: prefix changes it to a command. It's no longer a function, so it can't be executed as a function. Anything on the command line that's inside parentheses has to be a function. So the user has to enter it as a command instead, without the parentheses.

    For the same reason, you shouldn't include (SPD) in your autorun file. The autorun file will try to execute a function that doesn't exist. And anyway, you shouldn't set the command to run automatically on loading. The user should execute it when wanting to save. Once the custom command is defined (by executing the defun function), that command will always be available, just like the built-in commands.

  • You need to make a choice, there is no problem using (spd) as the last line of the preloaded defun spd, if you make defun c:spd then your last line needs to be (c:spd) ie a full match of defun name. The advantage of c:spd is at any time you can type spd and it will execute the "savesas".

    You may want to use (command-s "_SaveAs") this will allow completion of the saveas command pretty sure needs a filename.

  • JimWebster
    edited June 26

    AlanH: Thank for commenting to correct of the last line to  (c:spd). That solved an error message that I was getting. I also opted to replace _SAVEAS with QSAVE to eliminate the SaveAs Dialog Box, which I did not want. The below is the final rendition.

    ; SPD - Save Plasma Drawing
    ; Save the DXF plasma drawing to AutoCAD Release 11/12 ASCII DXF (.dxf)
    ; 17 (AC1015) = AutoCAD 2000 ASCII DXF (
    .dxf)
    ; 26 (AC1009) = AutoCAD Release 11/12 ASCII DXF (*.dxf)
    (defun c:SPD ( / OldFormat )
    (setq OldFormat (getvar "SaveFormat")) ; save the current save format
    (setvar "SaveFormat" 26) ; to change it to AutoCAD Release 11/12 ASCII DXF
    (command "QSAVE") ; run QSAVE command
    (setvar "SaveFormat" OldFormat) ; restore the previous save format
    )

    (c:SPD) ; auto run on loading