Author Topic: lisp to create text  (Read 479 times)

wt198609 and 1 Guest are viewing this topic.

CraigP

  • Mosquito
  • Posts: 12
lisp to create text
« on: February 19, 2024, 08:49:01 PM »
Why does this not show a text edit cursor on screen the same as when the command is entered on the command line?

(command "TEXT" "j" "tc" PAUSE "3.5" "0" PAUSE)


Or is there a better way to create text?
I also set the textstyle and layer prior to this.


cheers
Craig
BricsCAD V24.1.08

VMichl

  • Mosquito
  • Posts: 8
Re: lisp to create text
« Reply #1 on: February 20, 2024, 03:06:15 AM »
Maybe:

(command "_DTEXT" "_j" "_tc" PAUSE "3.5" "0" PAUSE)

CraigP

  • Mosquito
  • Posts: 12
Re: lisp to create text
« Reply #2 on: February 20, 2024, 07:11:36 PM »
Thanks for the reply, but no difference.

Maybe:

(command "_DTEXT" "_j" "_tc" PAUSE "3.5" "0" PAUSE)

CraigP

  • Mosquito
  • Posts: 12
Re: lisp to create text
« Reply #3 on: February 21, 2024, 06:10:41 PM »
Got my answer on another forum, for anyone that is interested...

Code: [Select]
  (setq pt (getpoint "\nText insertion point: "))
  (if pt
    (progn
      (setq tx_ent (entmakex (list
                               (cons 0 "TEXT")
                               (cons 10 pt)
                               (cons 11 pt)
                               (cons 1 "")
                               (cons 40 3.5)
                               (cons 72 1)  ;Horizontal Alignment 0-Left, 1-Center, 2-Right, 3-Aligned, 4-Middle, 5-Fit
                               (cons 73 3)  ;Vertical Alignment 0-Baseline, 1-Bottom, 2-Middle, 3-Top
                             )
                   )
      )
      (vle-edittextinplace tx_ent)
    )
  )

PrinceLISPalot

  • Newt
  • Posts: 36
  • perfectionist trapped inside the mind of an idiot.
Re: lisp to create text
« Reply #4 on: February 26, 2024, 04:24:20 AM »
Be aware that your solution can generate empty strings if the user picks outside the text box, presses enter, or hits the spacebar repeatedly. While you can use the PURGE command to get rid of empty text entities, it's better to avoid creating them in the first place.

The following code adds a check on the edited text and deletes the text entity if it's an empty string or is made up of spaces.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:CreateText ( / pt tx_ent txt)
  2.     (setq pt (getpoint "\nText insertion point: "))
  3.       (cond
  4.         (pt
  5.             (setq tx_ent (entmakex (list
  6.                                     (cons 0 "TEXT")
  7.                                     (cons 10 pt)
  8.                                     (cons 11 pt)
  9.                                     (cons 1 "")
  10.                                     (cons 40 3.5)
  11.                                     (cons 72 1)
  12.                                     (cons 73 3)
  13.                                   )
  14.                         )
  15.                 )
  16.            
  17.             (setq txt (vle-edittextinplace tx_ent)) ; capture generated text
  18.             ;If the created text is an empty string or is made up of spaces
  19.             (if (= (strlen txt) (1- (length (vle-string-split " " txt))))
  20.                 (entdel tx_ent) ; delete the text entity
  21.             )
  22.         )
  23.       )
  24.     (prin1)
  25. )
  26.  

Should also state that this LISP is intended for use in BricsCAD. The VLE functions are native to BricsCAD but Bricsys provide vle-extension.lsp which contains emulation functions for other CAD platforms that support LISP. This lisp file is available from here https://boa.bricsys.com/applications/a/?lisp-developer-support-package-(ldsp)-a720-al1176
« Last Edit: February 26, 2024, 04:36:56 AM by PrinceLISPalot »