Lisp routine developed a new bug with a recent update of Bricscad. Why?

I use a lisp routine in modelspace to set the "scale" of the drawing so that text, leaders, dimensions, etc. are sized correctly. I don't use paperspace and don't want to start.

This routine used to always work fine, until a few updates past of Bricscad. Now it runs fine, but after I close the drawing and re-open the settings are retained but when I add a leader with text the text there is a problem. The first leader works fine, but the second comes out with the text too large and the leader also. Then I run the routine again to set the scale and it all works fine.

Bricscad used to remember all the variables correctly when I closed and reopened the drawing. Now it seems to be forgetting one. Is this a BCad bug I should report, or am I doing something wrong in the routine or assuming something incorrectly?

Here is the code:

(defun c:ds nil
(initget 2 "Architectural Engineering")
(setq type-1 (getkword "Architectural or Engineering scale? :"))
(if (or (eq type-1 "Architectural") (eq type-1 nil))
(setvar "dimscale" (* 12 (/ 1 (getreal "Enter 'x' where 'x' inch = 1 foot: "))))
)
(if (eq type-1 "Engineering")
(setvar "dimscale" (* 12 (getreal "Enter 'y' where 1 inch = 'y' feet: ")))
)
(setvar "textsize" (* (getvar "dimscale") (getvar "dimtxt")))
(setvar "ltscale" (* (getvar "dimscale") 0.2))
(princ "DIMSCALE = ")
(princ (getvar "dimscale"))
(princ " TEXTSIZE = ")
(princ (getvar "textsize"))
(princ " LTSCALE = ")
(princ (getvar "ltscale"))
(princ)
)

Comments

  • dugBarnz
    edited October 2023
    Since you didn't state what version you are using I applied your code to the version I'm using, BricsCAD V23.2.06 (x64) Ultimate. Your code did work in V23. So I suspect you're on V24? Please reply so we may possibly better assist.

    As I couldn't help myself from trying to improve the code, I offer up these changes:
    1) formatted code with Blade Reformat (Beautify) {refer to image below}
    2) replaced nil with local variable list {second line of code}
    3) renamed variable from type-1 to st%getkword {for my own preference}
    4) applied default for getkword function
    4a) added <> around Architectural as indicator
    4b) added if statement for if st%getkword was null
    5) added princ statement acknowledging which discipline was selected
    6) simplified if statement, eliminating second if statement in place of if else syntax below

    I did take the "improve the code" too far and will post that next, for learning purposes, if desired.

    (defun c:ds (/ st%getkword) (initget 2 "Architectural Engineering") (setq st%getkword (getkword "<Architectural> or Engineering scale? :")) (if (null st%getkword) (setq st%getkword "Architectural")) (princ (strcat st%getkword " selected")) (if (eq st%getkword "Architectural") (setvar "dimscale" (* 12 (/ 1 (getreal "Enter 'x' where 'x' inch = 1 foot: ")))) (setvar "dimscale" (* 12 (getreal "Enter 'y' where 1 inch = 'y' feet: "))) ) (setvar "textsize" (* (getvar "dimscale") (getvar "dimtxt"))) (setvar "ltscale" (* (getvar "dimscale") 0.2)) (princ "DIMSCALE = ") (princ (getvar "dimscale")) (princ " TEXTSIZE = ") (princ (getvar "textsize")) (princ " LTSCALE = ") (princ (getvar "ltscale")) (princ) )

    All the best!
    Doug
    BricsCAD V23.2.06 (x64) Ultimate

  • I am using v. 23 and I think this problem started occurring when I upgraded to that version. I'll try your modified code to see if it works any better. Thanks!
  • Now that I look at your code, did you leave out the "else" statement? It is kind of hard to tell since the code is all run together. But I don't see an "else" in there.
  • Refer to the image below in which I've highlighted the else part of the if statement.


  • I understand. The else is implied.
  • dugBarnz
    edited October 2023
    Yes, implied.

    FYI: Use (progn if you want multiple statements, such as:


  • I tried your version of this routine and it works the same as mine -- with the same problem. Actually now I have tracked the problem down to a different lisp routine that I use to make leaders and MTEXT. It uses the textsize variable that is set by this "DS" routine.

    Perhaps I should submit this as a support request, but I wanted to see if I'm missing something in the lisp coding. Here is a simplified version of the MTEXT routine that duplicates the problem. I have added several statements to print the value of the variable "textsize" at various points. This routine asks you for two corners of a box, and then for several lines of text (end with a blank line) and it will create an MTEXT block there.

    (defun c:testtext (/ txtsz pt1 pt2)
    (princ (getvar "textsize"))
    (princ)
    (setvar "textsize" 0.75)
    (setq txtsz (getvar "textsize"))
    (princ (getvar "textsize"))
    (princ)
    (setq pt1 (getpoint "\nPick 1st point.. "))
    (setq pt2 (getpoint pt1 "\nPick 2nd point.. "))
    (command "MTEXT" pt1 "J" "TR" "S" "STANDARD" "H" txtsz pt2)
    (while (/= (getvar "cmdactive") 0)
    (command pause)
    )
    (princ (getvar "textsize"))
    (princ)
    )

    If you run this on a newly-created drawing, the first time it runs correctly -- text is created with a height of 0.75". But you can see that the last print of the "textsize" system variable has the value as 9 rather than 0.75. It seems that the "while" statement is causing the problem. But then if you run the routine again, it correctly uses 0.75 and textsize stays at that value. So it is just the first time that the variable get changed to 9 for some reason.

    Is this my fault or is it a BCAD bug?

    Thanks!
  • When you start a new dwg what is your textstyle set to if using a DWT etc. It may be set to say a annotative style with a height of 9. Reset it to Standard and save, also is standard set to 0.0.
  • Are you saying set textsize to zero? It won't let me do that. In any case, why would that matter, and why did this routine work correctly in V22 but then stopped working in V23?
  • I submitted as a support request and they provided a workaround. The (command pause) statement is causing the problem somehow but using a global variable of my own for textsize and setting the system "textsize" variable to that when needed makes it work ok.