Need help to set default value to LISP

Need help to set default value to LISP

per_hellstrom
Explorer Explorer
552 Views
5 Replies
Message 1 of 6

Need help to set default value to LISP

per_hellstrom
Explorer
Explorer

When I launch the lisp first thing I need to do is "Enter offset distance".

The default value is set to 2.

 

I need help to set the default offset distance to 200 instead of 2.

And remain the last used value when I use the lisp again.

 

0 Likes
Accepted solutions (1)
553 Views
5 Replies
Replies (5)
Message 2 of 6

Brock_Olly
Collaborator
Collaborator
Accepted solution
(defun c:bt (/ osdd osd en enlist1 ss pt1 pt2 ang hpi osang1 osang2
                os1pt1 os1pt2 os2pt1 os2pt2 ct enlist2 pt3 pt4
                intpt1 intpt2 enlist3)

  ;; Retrieve stored offset or use default
  (setq osdd (getcfg "AppData/CoT/btOffset"))
  (if (or (not osdd) (= osdd ""))
    (setq osdd "200")
  )

  ;; Prompt user with the default or last-used offset
  (setq osd (getdist
              (strcat "\nChest O Tools: Break Touching Lines"
                      "\nEnter offset distance <" osdd ">: ")
            )
  )

  ;; Store the new value or use the default if Enter is pressed
  (if osd
    (setcfg "AppData/CoT/btOffset" (rtos osd 2 8))
    (setq osd (atof osdd))
  )

  ;; Select base line
  (while (/= "LINE" (cdr (assoc 0 enlist1)))
    (if (setq en (car (entsel "\nSelect a base line: ")))
      (setq enlist1 (entget en))
    )
  )

  ;; Select other lines to break
  (if (setq ss (ssget '((0 . "LINE"))))
    (progn
      (command "_.undo" "_begin")

      (setq pt1 (cdr (assoc 10 enlist1))
            pt2 (cdr (assoc 11 enlist1))
            ang (angle pt1 pt2)
            hpi (* 0.5 pi)
            osang1 (+ ang hpi)
            osang2 (- ang hpi)
            os1pt1 (polar pt1 osang1 osd)
            os1pt2 (polar pt2 osang1 osd)
            os2pt1 (polar pt1 osang2 osd)
            os2pt2 (polar pt2 osang2 osd)
            ct 0
      )

      (repeat (sslength ss)
        (setq enlist2 (entget (ssname ss ct))
              pt3 (cdr (assoc 10 enlist2))
              pt4 (cdr (assoc 11 enlist2))
              ct (1+ ct)
        )

        (if (inters pt1 pt2 pt3 pt4 T)
          (progn
            (setq intpt1 (inters os1pt1 os1pt2 pt3 pt4 nil)
                  intpt2 (inters os2pt1 os2pt2 pt3 pt4 nil)
            )

            (if (and (/= pt1 pt3)
                     (/= pt1 pt4)
                     (/= pt2 pt3)
                     (/= pt2 pt4)
                     (or (and (inters os1pt1 os1pt2 pt3 pt4 T)
                              (inters os2pt1 os2pt2 pt3 pt4 T))
                         (and (inters os1pt1 os1pt2 pt3 pt4 T)
                              (inters os1pt2 os2pt2 pt3 pt4 T))
                         (and (inters os1pt2 os2pt2 pt3 pt4 T)
                              (inters os2pt1 os2pt2 pt3 pt4 T))
                         (and (inters os2pt1 os2pt2 pt3 pt4 T)
                              (inters os1pt1 os2pt1 pt3 pt4 T))
                         (and (inters os1pt1 os2pt1 pt3 pt4 T)
                              (inters os1pt1 os1pt2 pt3 pt4 T))
                     )
                )
              (progn
                (if (equal (angle intpt1 intpt2) (angle pt3 pt4) 0.1)
                  (progn
                    (setq enlist3 (cons '(0 . "LINE")
                                        (member '(100 . "AcDbEntity")
                                                (subst (cons 10 intpt2)
                                                       (assoc 10 enlist2)
                                                       enlist2)))
                          enlist2 (subst (cons 11 intpt1)
                                         (assoc 11 enlist2)
                                         enlist2)
                    )
                  )
                  (progn
                    (setq enlist3 (cons '(0 . "LINE")
                                        (member '(100 . "AcDbEntity")
                                                (subst (cons 10 intpt1)
                                                       (assoc 10 enlist2)
                                                       enlist2)))
                          enlist2 (subst (cons 11 intpt2)
                                         (assoc 11 enlist2)
                                         enlist2)
                    )
                  )
                )

                (entmod enlist2)
                (entmake enlist3)
              )
            )
          )
        )
      )

      (command "_.undo" "_end")
    )

    (prompt "\nNothing selected!")
  )

  (princ)
)
0 Likes
Message 3 of 6

per_hellstrom
Explorer
Explorer

You are a HERO! Thank you!

Message 4 of 6

Brock_Olly
Collaborator
Collaborator

Thank chatGPT not me 🙂

Message 5 of 6

Sea-Haven
Mentor
Mentor

This is how I would save in the dwg the last value used. So next time you open the dwg you have last used  value.

 

(setq osd (vlax-ldata-get "Per" "osd"))
(if = (osd nil)
(setq osd 200)
)

do your thing and reset offval then DO

(vlax-ldata-put "Per" "osd" osd)

 

Message 6 of 6

Kent1Cooper
Consultant
Consultant

@per_hellstrom wrote:

....

I need help to set the default offset distance to 200 ....

And remain the last used value when I use the lisp again.


It seems a little odd to me to use (getcfg) and deal with the offset distance as a text string.  It's a number, and can be handled that way directly if within the same drawing-editing session.

When you say "when I use the lisp again," if you mean again within the same editing session, then it can be done with a simple global variable.

If you mean when you use it again in a different drawing, or after closing a drawing and opening it again later [or even after closing AutoCAD]. then maybe the (getcfg) approach is okay, though I think I would use an Environment Variable [which also has to store it as a text string].

Either way, I think it can be done with fewer steps than in your posted code.

Which "again" do you intend?

Kent Cooper, AIA
0 Likes