Jump to content

Looking for a lisp that lets me pick a prefix then enter a height


Recommended Posts

Posted

Looking for a lisp that lets me pick a prefix then enter a height for example (Palisade Fence 1.80m)  but I'd only have to enter the value. In an ideal world I'd like to be able to select two points on a line to set the rotation beforehand but that's not a necessity and that's obviously that's likely to get quite complicated (I'm relatively new to lisp). Anyone know of existing routines that I could attempt to merge.

Thanks 

Posted

So you want to pick text then add a height ? A very simple example can be made to repeat etc.

 

(defun c:T+ ( / ent ht str)
(setq ent (entget (car (entsel "\nPick text "))))
(setq str (cdr (assoc 1 ent)))
(setq ht (getstring "\nEnter new ht in full eg 1.80 "))
(setq str (strcat str " " ht))
(entmod (subst (cons 1 str)(assoc 1 ent) ent))
(princ)
)

 

Posted
9 hours ago, BIGAL said:

So you want to pick text then add a height ? A very simple example can be made to repeat etc.

 

(defun c:T+ ( / ent ht str)
(setq ent (entget (car (entsel "\nPick text "))))
(setq str (cdr (assoc 1 ent)))
(setq ht (getstring "\nEnter new ht in full eg 1.80 "))
(setq str (strcat str " " ht))
(entmod (subst (cons 1 str)(assoc 1 ent) ent))
(princ)
)

 

Not really.  I want to be able to pick a prefix (USB, retaining wall, C/B Fence) for example.  Then be asked to enter the hight so the end product looks like "C/B Fence  1.8m" the cherry on top of the cake would being able to define the rotation of the text by picking two points on a line. 

Posted

Where do you pick the prefix from? Like BigAl says, quite easy but you might need to give a few more details.

Posted


(DEFUN c:test (/ op height mens)
  (SETVAR "cmdecho" 0)
  (IF op0
    ()
    (SETQ op0 "USB")
  )
  (SETQ mens
         (STRCAT
           "\nSelect option [USB/Wall/Fence] <"
           op0
           ">: "
         )
  )
  (INITGET "USB Wall Fence")
  (IF (SETQ op (GETKWORD mens))
    ()
    (SETQ op op0)
  )
  (SETQ op0 op)

  (IF height0
    ()
    (SETQ height0 0.05)
  )
  (SETQ mens (STRCAT "\nEnter height <"
                     (RTOS height0 2 2)
                     ">: "
             )
  )
  (INITGET (+ 2 4))
  (IF (SETQ height (GETDIST mens))
    ()
    (SETQ height height0)
  )
  (SETQ height0 height)

  (PRINC (STRCAT "\noption = " op))
  (PRINC (STRCAT "\nheight = " (RTOS height 2 2)))
  (SETVAR "cmdecho" 1)
  (PRIN1)
)

Posted
2 hours ago, Steven P said:

Where do you pick the prefix from? Like BigAl says, quite easy but you might need to give a few more details.

Good question could it be written into the lisp to pop up as a dynamic input box or would i need some kind of dcl file?

Posted
35 minutes ago, elyosua said:


(DEFUN c:test (/ op height mens)
  (SETVAR "cmdecho" 0)
  (IF op0
    ()
    (SETQ op0 "USB")
  )
  (SETQ mens
         (STRCAT
           "\nSelect option [USB/Wall/Fence] <"
           op0
           ">: "
         )
  )
  (INITGET "USB Wall Fence")
  (IF (SETQ op (GETKWORD mens))
    ()
    (SETQ op op0)
  )
  (SETQ op0 op)

  (IF height0
    ()
    (SETQ height0 0.05)
  )
  (SETQ mens (STRCAT "\nEnter height <"
                     (RTOS height0 2 2)
                     ">: "
             )
  )
  (INITGET (+ 2 4))
  (IF (SETQ height (GETDIST mens))
    ()
    (SETQ height height0)
  )
  (SETQ height0 height)

  (PRINC (STRCAT "\noption = " op))
  (PRINC (STRCAT "\nheight = " (RTOS height 2 2)))
  (SETVAR "cmdecho" 1)
  (PRIN1)
)

wow okay this is exactly along the lines I was thinking however it doesn't seem to produce the text at the end.

Posted (edited)

Ahh, right up BigAls street - he will direct you to his multiradio buttons LISP in the downloads above, to give a pop-up box, changing these lines in his code I guess to run it and get the result as a string:

 

(setq ent (entget (car (entsel "\nPick text "))))
(setq str (cdr (assoc 1 ent)))

 

Would you want to enter the text height in the same pop-up box as well, or the command line? I'd maybe go for the pop-up too (not sure if multivals does that as it is or need a small change?)

 

 

and then the last question is finishing off to modify an existing text or to add in a new text?

 

Edited by Steven P
Posted
19 minutes ago, Jamesclark64 said:

wow okay this is exactly along the lines I was thinking however it doesn't seem to produce the text at the end.

 

I don't know if this what you want


(DEFUN c:test (/ op height mens)
  (SETVAR "cmdecho" 0)
  (IF op0
    ()
    (SETQ op0 "USB")
  )
  (SETQ mens
         (STRCAT
           "\nSelect option [USB/Wall/Fence] <"
           op0
           ">: "
         )
  )
  (INITGET "USB Wall Fence")
  (IF (SETQ op (GETKWORD mens))
    ()
    (SETQ op op0)
  )
  (SETQ op0 op)

  (IF height0
    ()
    (SETQ height0 0.05)
  )
  (SETQ mens (STRCAT "\nEnter height <"
                     (RTOS height0 2 2)
                     ">: "
             )
  )
  (INITGET (+ 2 4))
  (IF (SETQ height (GETDIST mens))
    ()
    (SETQ height height0)
  )
  (SETQ height0 height)

  (PRINC (STRCAT "\nText = " op " " (RTOS height 2 2) "m"))
  (SETVAR "cmdecho" 1)
  (PRIN1)
)

Posted

Another one here, just waiting for BIgAl and his pop-ups

 

Run with testthis

 

Modify your list "MyList" to be what you want

Modify your text height as required, you can also do some stuff to snap your inserted text to a grid and alter the fonts in the text making part, but this will do for now

 

 

 

(defun c:testthis ( / dcl des dch x Height Prefix)

;;Setup
  (setq TextHeight 2.5)
  (setq MyList (list "SP" "Was" "Here"))
;;End Setup


;; Sub Functions
  (defun MakeText ( MyText TextPoint textHeight / ) ; Sub Function
    (entmake (list
      '(0 . "TEXT")
      '(100 . "AcDbEntity")
      '(8 . "0")
      '(100 . "AcDbText")
      (cons 10 TextPoint)
      (cons 40 textheight)
;;      '(46 . 0.0)
      (cons 1 MyText)
      '(50 . 0.0)
      '(41 . 1.0)
      '(51 . 0.0)
;;      (cons 7 font)
      '(71 . 0)
      '(72 . 0)
      '(11 0.0 0.0 0.0)
      '(210 0.0 0.0 1.0)
      '(100 . "AcDbText")
      '(73 . 0)
    ));end list, entmake
  )
;; End Sub Functions



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  create DCL pop up box   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (if
    (and
      (setq dcl (strcat (getvar "TEMPPREFIX") "DCL.dcl"))
      (setq des (open dcl "w"))
      (foreach x
        '(
"         pass : dialog { key = \"DialogueKey\";  label = \"Dialogue Label\"; " 
"           spacer;"

;;;;; Add DCL tiles here ;;;;;
"  : boxed_column { label = \"\"; width = 60; "
"  : text { key = \"ListTitle\";}"
"  : list_box {key = \"ListBox\"; label = \"list Box\"; height = 12; fixed_height = true; width = 38; }"
"  : text { key = \"EditTitle\";}"
"  : edit_box { key = \"EditBox\"; label = \"Edit Box\"; width = 25; fixed_width = true;}"
"  : spacer { fixed_height = true; height = 5; }"
"  : row {alignment = top; wisth = 30; "
"  : button { key = \"OK\"; label = \"OK\"; is_default = true; is_cancel = true; fixed_width = true; width = 20; }"
"  : button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 20; }"
"  }"
"  }"
;;;;; End DCL tiles here;;;;;

;;;;; DCL Stuff ;;;;;;;;;;;;;
"         }"               ;; End pass : dialog
        )                  ;; end '(
        (write-line x des)
      )                    ;;end foreach x
      (not (setq des (close des)))
      (< 0 (setq dch (load_dialog dcl)))
      (new_dialog "pass" dch)
    )                      ;;End of DCL 'and'
;;;;; End DCL Stuff ;;;;;;;;;;

    (progn
;;;;; Add Tile actions here ;;;;;;
      (set_tile "ListTitle" "Select Prefix Text:")
      (set_tile "EditTitle" "Enter Height Text")

      (start_list "ListBox")(mapcar 'add_list MyList)(end_list)

      (action_tile "ListBox"  "(setq Prefix (get_tile \"ListBox\"))")
      (action_tile "EditBox"  "(setq Height (get_tile \"EditBox\"))")
      (action_tile "OK" "(done_dialog 1)") ;;can change variables here or run other code
      (action_tile "cancel" "(done_dialog 0)")
;;;;;end tile actions here;;;;;

      (start_dialog)
    ) ;;end of DCL 'progn' above
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of DCL 'if' above
  (vl-file-delete dcl) ;;delete the temp DCL file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;    End DCL pop up box    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Add rest of code here   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (if (= Prefix nil)(setq Prefix ""))
  (if (= Height nil)(setq Height ""))
  (setq MyText (strcat (nth (atoi Prefix) MyList) " " Height))
  (setq Pt (getpoint "Text Insert Point"))
  (MakeText MyText Pt TextHeight)
  (princ) ; exit silently
)

 

 

Posted
7 hours ago, Steven P said:

Ahh, right up BigAls street - he will direct you to his multiradio buttons LISP in the downloads above, to give a pop-up box, changing these lines in his code I guess to run it and get the result as a string:

 

(setq ent (entget (car (entsel "\nPick text "))))
(setq str (cdr (assoc 1 ent)))

 

Would you want to enter the text height in the same pop-up box as well, or the command line? I'd maybe go for the pop-up too (not sure if multivals does that as it is or need a small change?)

 

 

 

 

I tried the multi buttons routine last week it was very slick but for some reason it never seemed to output actual text at the end.

 

"Would you want to enter the text height in the same pop-up box as well, or the command line?"

 

I'd prefer the command line as I know it would be easier to use with a Bluetooth disto imput and its generally less clicks. 

 

"and then the last question is finishing off to modify an existing text or to add in a new text?" 

 

New text. Old text I have covered by Lee macs bfind lisp.

 

Any thoughts on the picking two points for rotation? I'll mostly be on site with a tablet so the less imput with windows onscreen keyboard the better.  

 

I realise I'm asking quite a lot here. Thanks for all the help ive received so far.

Posted (edited)

Quick answer is just that ANS is the variable that holds the string returned when you select a button. Sometimes you want a different answer to the please choose string, so you can alos use BUT it is the number of the button selected so you can use it with a cond and set a variable to a different value than shown.

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= ahdef nil)(setq ahdef 1))
(setq ans (ah:butts ahdef "V" '("Choose type" "USB" "WALL" "FENCE" "CEILING" "WINDOW" "DOOR" "7" "8" "9" "10")))
(setq ahdef but)

This will set the default button to the last picked so just press ok say wall, wall, wall. Makes easier to repeat.

 

(princ ans) = "WINDOW"

 

Ok part 2 use Multi getvals.lsp to pop a dcl and enter distance.

OK part 3 as suggested redo the dcl so includes the distance.

 

image.png.8af8ae5fe8850e096fb906d254a3e6da.png

 

Ok start by changing this line and run once. It will write all the dcl code for you for the multi radio. 

(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))

(setq fo (open (setq fname "D:\\acadtemp\\temp.dcl") "w")) ; change output directory to one you have.

You need to edit this dcl "temp" to add the extra column of getval.  If you don't know how post.

 

Last comment I found a convert DCL to lisp so once you get the dcl working can add it to the lisp code so no need for the DCL file.

 

Multi GETVALS.lsp

Edited by BIGAL
  • Like 1
Posted
On 09/02/2023 at 13:01, Steven P said:

Another one here, just waiting for BIgAl and his pop-ups

 

Run with testthis

 

Modify your list "MyList" to be what you want

Modify your text height as required, you can also do some stuff to snap your inserted text to a grid and alter the fonts in the text making part, but this will do for now

 

 

 

(defun c:testthis ( / dcl des dch x Height Prefix)

;;Setup
  (setq TextHeight 2.5)
  (setq MyList (list "SP" "Was" "Here"))
;;End Setup


;; Sub Functions
  (defun MakeText ( MyText TextPoint textHeight / ) ; Sub Function
    (entmake (list
      '(0 . "TEXT")
      '(100 . "AcDbEntity")
      '(8 . "0")
      '(100 . "AcDbText")
      (cons 10 TextPoint)
      (cons 40 textheight)
;;      '(46 . 0.0)
      (cons 1 MyText)
      '(50 . 0.0)
      '(41 . 1.0)
      '(51 . 0.0)
;;      (cons 7 font)
      '(71 . 0)
      '(72 . 0)
      '(11 0.0 0.0 0.0)
      '(210 0.0 0.0 1.0)
      '(100 . "AcDbText")
      '(73 . 0)
    ));end list, entmake
  )
;; End Sub Functions



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  create DCL pop up box   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (if
    (and
      (setq dcl (strcat (getvar "TEMPPREFIX") "DCL.dcl"))
      (setq des (open dcl "w"))
      (foreach x
        '(
"         pass : dialog { key = \"DialogueKey\";  label = \"Dialogue Label\"; " 
"           spacer;"

;;;;; Add DCL tiles here ;;;;;
"  : boxed_column { label = \"\"; width = 60; "
"  : text { key = \"ListTitle\";}"
"  : list_box {key = \"ListBox\"; label = \"list Box\"; height = 12; fixed_height = true; width = 38; }"
"  : text { key = \"EditTitle\";}"
"  : edit_box { key = \"EditBox\"; label = \"Edit Box\"; width = 25; fixed_width = true;}"
"  : spacer { fixed_height = true; height = 5; }"
"  : row {alignment = top; wisth = 30; "
"  : button { key = \"OK\"; label = \"OK\"; is_default = true; is_cancel = true; fixed_width = true; width = 20; }"
"  : button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 20; }"
"  }"
"  }"
;;;;; End DCL tiles here;;;;;

;;;;; DCL Stuff ;;;;;;;;;;;;;
"         }"               ;; End pass : dialog
        )                  ;; end '(
        (write-line x des)
      )                    ;;end foreach x
      (not (setq des (close des)))
      (< 0 (setq dch (load_dialog dcl)))
      (new_dialog "pass" dch)
    )                      ;;End of DCL 'and'
;;;;; End DCL Stuff ;;;;;;;;;;

    (progn
;;;;; Add Tile actions here ;;;;;;
      (set_tile "ListTitle" "Select Prefix Text:")
      (set_tile "EditTitle" "Enter Height Text")

      (start_list "ListBox")(mapcar 'add_list MyList)(end_list)

      (action_tile "ListBox"  "(setq Prefix (get_tile \"ListBox\"))")
      (action_tile "EditBox"  "(setq Height (get_tile \"EditBox\"))")
      (action_tile "OK" "(done_dialog 1)") ;;can change variables here or run other code
      (action_tile "cancel" "(done_dialog 0)")
;;;;;end tile actions here;;;;;

      (start_dialog)
    ) ;;end of DCL 'progn' above
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of DCL 'if' above
  (vl-file-delete dcl) ;;delete the temp DCL file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;    End DCL pop up box    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Add rest of code here   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (if (= Prefix nil)(setq Prefix ""))
  (if (= Height nil)(setq Height ""))
  (setq MyText (strcat (nth (atoi Prefix) MyList) " " Height))
  (setq Pt (getpoint "Text Insert Point"))
  (MakeText MyText Pt TextHeight)
  (princ) ; exit silently
)

 

 

Hello Steven I'm really loving this routine works exactly how I wanted it to. However I do have a question.  What would I need to change to get the text to come out at whatever rotation I've got my base angle (angbase) set as? Currently it seems to be locked on 0.

Cheers 

Posted
10 hours ago, Jamesclark64 said:

Hello Steven I'm really loving this routine works exactly how I wanted it to. However I do have a question.  What would I need to change to get the text to come out at whatever rotation I've got my base angle (angbase) set as? Currently it seems to be locked on 0.

Cheers 

 

if you can find the angle you need, for example call it MyAngle and then change these 3 lines:

 

(MakeText MyText Pt TextHeight)

(near the end of the code)
to

(MakeText MyText Pt TextHeight MyAngle

 

(defun MakeText ( MyText TextPoint textHeight / )

(near the start)
to

(defun MakeText ( MyText TextPoint textHeight MyAngle / )

 

and

 

'(50 . 0.0)

(just after the last one)
to

(cons 50 MyAngle)

 

Noting that the angle is in radians and not degrees so you might need to convert that - see DTR online for a sub routine to add to do that

 

Posted
On 12/02/2023 at 09:23, Steven P said:

 

if you can find the angle you need, for example call it MyAngle and then change these 3 lines:

 

(MakeText MyText Pt TextHeight)

(near the end of the code)
to

(MakeText MyText Pt TextHeight MyAngle

 

(defun MakeText ( MyText TextPoint textHeight / )

(near the start)
to

(defun MakeText ( MyText TextPoint textHeight MyAngle / )

 

and

 

'(50 . 0.0)

(just after the last one)
to

(cons 50 MyAngle)

 

Noting that the angle is in radians and not degrees so you might need to convert that - see DTR online for a sub routine to add to do that

 

Thank you for the help. The problem I have is the angles of the lines are constantly changing. I made a little routine to set the base angle by selecting two points along a  line with the intention of running the routine you made me after but whatever I do  text comes out facing north (so to speak).  

Posted
18 hours ago, Jamesclark64 said:

Thank you for the help. The problem I have is the angles of the lines are constantly changing. I made a little routine to set the base angle by selecting two points along a  line with the intention of running the routine you made me after but whatever I do  text comes out facing north (so to speak).  

 

If you can post your LISP it should be fairly easy to make it work.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...