Pause for Text command run from lisp

I use the following code for adding one or more new lines of text below an existing line of text.  In Autocad it works well.  Bricscad does not work the same way.  In Bricscad the last command line text is inserted as the text and I get a "This command is not yet supported" error message.  Adding "pause" to the (command "dtext"...  allows me to enter one line of text, but does not show the text in the drawing while typing.  Adding (while (> (getvar "cmdactive") 0)(command pause)) does not allow adding more lines of text.  Is there a work-around that will allow this to work in Bricscad?

Thanks.

 

(defun c:addtext (/ curlay cursty seltxt insp trot valign tcolor curcol halign sty styht just hl vl tlay txtht q osmod
)
(defun addtexterror (s)
(princ s)
(setvar "cmdecho" 0)
(command "._undo" "end")
(setvar "cecolor" curcol)
(setvar "clayer" curlay)
(setvar "textstyle" cursty)
(setvar "osmode" osmod)
(setvar "cmdecho" 1)
(setq *error* olderr)
(princ)
)
;;;CODE FOR PROGRAM
(setvar "cmdecho" 0)
(command "._undo" "begin")
(setq olderr *error*
*error* addtexterror
)
(setq osmod (getvar "osmode"))
(setq curlay (getvar "clayer"))
(setq cursty (getvar "textstyle"))
(setq curcol (getvar "cecolor"))
(setvar "osmode" 64) ; set insert osnap
(prompt "\nSelect text line to append new text below ... ")
(setvar "osmode" 0) ; osnaps off
(setq q 0)
(while (= q 0)
(progn (setq seltxt (entsel)) ; select the initial text
(setq gettxt (entget (car seltxt))) ; get the entity
(if (= (cdr (assoc 0 gettxt)) "TEXT") ; is it text?
(setq q 1 ; set flag to exit loop
sty (cdr (assoc 7 gettxt)) ; get the text style
halign (cdr (assoc 72 gettxt)) ; get the horizontal alignment
valign (cdr (assoc 73 gettxt)) ; get the vertical alignment
styht (cdr (assoc 40 (tblsearch "style" sty))) ; get the text style
txtht (cdr (assoc 40 gettxt)) ; get the text height
trot (/ (* (cdr (assoc 50 gettxt)) 180.00) PI) ; get the text rotation
tlay (cdr (assoc 8 gettxt)) ; get the text layer
tcolor (cdr (assoc 62 gettxt)) ; get the text color
)
)
)
)
(setvar "clayer" tlay) ; make the text layer current
(cond ((= halign 0) (setq hl "L")) ; set justification flags
((= halign 1) (setq hl "C"))
((= halign 2) (setq hl "R"))
((= halign 4) (setq hl "M"))
)
(cond ((= valign 0) (setq vl ""))
((= valign 1) (setq vl "B"))
((= valign 2) (setq vl "M"))
((= valign 3) (setq vl "T"))
)
(if (= halign valign 0) ; left justification uses 10, all others use 11
(setq insp (cdr (assoc 10 gettxt))) ; set the insertion point
(setq insp (cdr (assoc 11 gettxt)))
)
(setq just (strcat vl hl)) ; assemble justification string
(cond ((= tcolor nil) (setvar "cecolor" "BYLAYER"))
((= tcolor 256) (setvar "cecolor" "BYLAYER"))
((= tcolor 0) (setvar "cecolor" "BYBLOCK"))
((and (> tcolor 0) (< tcolor 255)) (setvar "cecolor" (itoa tcolor)))
(t nil)
)
(setq insp (polar insp (+ trot (* 3.0 (/ pi 2.0))) (* txtht 1.538461539)))
(Prompt "\n\nText: ")
(if (= just "L")
(command "_dtext" "s" sty insp txtht trot)
(command "_dtext" "s" sty "j" just insp txtht trot)
)
(princ)
(setvar "cecolor" curcol)
(setvar "clayer" curlay)
(setvar "textstyle" cursty)
(setvar "osmode" osmod)
(command "._undo" "end")
(setvar "cmdecho" 1)
(setq *ERROR* old-error)
)

 

Comments

  • I´m struggling as well, with much he same problem and haven´t found a workaround.

    Look here : http://www.bricscad.com/common/support/forumthread.jsp?id=11506

    Just one thing : the "dtext" command has changed its´name, its now just "text".

  • I should have had a title for this thread.  If a moderator would like to add a title, please do.  I suggest "Pause for Text command run from lisp".

     

    Jorg,

    I plan to work around this using the data in this thread http://www.theswamp.org/index.php?topic=25412.0  The Swamp requires free registration.  I was the original poster for the thread referenced in post #1 of topic 25412.  I'll post my code when I have it working.

     

    Martin

  • I have tried a variety of approaches to work around the problem.  Here is the best so far.  The attached code calculates insertion points and calls the TEXT command multiple times until a null line is entered.  It appears that the TEXT command available is lisp is the old single line text function that does not place the text on the screen until the user presses Emter.  I tried calling both TEXT and DTEXT and it makes no difference.  Matching the justification of the initialy selectedl code is not working yet. 

    I also tried replacing the "(command _.DTEXT" with the code from The Swamp mentioned in post #3.  This allows seeing the text on the screen, and it is possible to simulate a cursor; however, there is a problem with the arrow keys I could not work around.  In Autocad the arrow keys do not return codes with GRREAD.  In Bricscad they return %, &, ', and ( for left, up, right, and down.  If all had been charcters that required the shift key it might have been possible to trap the keys, but the character returned for right arrow is not a shifted character.   I could live with entering text where I could not move the cursor back in the string to make a correction but instead had to backspace to the point of the error, but I'm not sure I could live with the arrow keys inserting characters.  Using (read-char) may be an option, but I have not had time to explore it.

    You will notice in the code a section starting "(if (= text_style "ENCO3")".  This sets the line to line spacing for the fonts I commonly use.  The factors there were obtained by running the Text command for each font in Autocad and measuring the spacing.  The default is for Arial.TTF.  For SHX fonts I tried to obtain the spacing by reading the .SHX file, but the functions in Bricscad for reading files stop at the first 00 character they encounter.  The code I used will read an entire binary file in Autocad. The SHX format is fairly obvious, and finding the line feed value essentially requires finding the first instance of 00 02 08 00 in the file.  The spacing is the next character.

    If I find a better solution I'll post it.  I'll also hope for an interim release that makes the work-around unnecessary.

    Martin

    (defun c:addtext (/ system_layer system_style initial_text insertion_point text_rotation
    text_vertical_alignment text_color system_color text_horizontal_alignment
    text_style text_style just horizontal_flag vertical_flag text_layer
    text_height loop_flag old_osmode
    )

    (defun addtexterror (s)
    (princ s)
    (if new_text_entity
    (entdel new_text_entity) ; remove empty string entity
    )
    (setvar "cmdecho" 0)
    (command "._undo" "end")
    (setvar "aunits" system_aunits)
    (setvar "auprec" system_auprec)
    (setvar "cecolor" system_color)
    (setvar "clayer" system_layer)
    (setvar "textstyle" system_style)
    (setvar "osmode" old_osmode)
    (setvar "cmdecho" 1)
    (setq *error* old_error)
    (princ)
    )

    (setvar "cmdecho" 0)
    (command "._undo" "begin")
    (setq old_error *error*
    *error* addtexterror
    )
    (setq old_osmode (getvar "osmode"))
    (setq system_layer (getvar "clayer"))
    (setq system_style (getvar "textstyle"))
    (setq system_color (getvar "cecolor"))
    (setq system_aunits (getvar "aunits"))
    (setq system_auprec (getvar "auprec"))
    (setvar "aunits" 3) ; work in radians
    (setvar "auprec" 8)
    (setvar "osmode" 0) ; osnaps off
    (setq loop_flag 0)
    (while (= loop_flag 0)
    (progn
    (setq initial_text (entsel "\nSelect text line to append new text below ... \n"))
    ; select the initial text
    (setq initial_text_entity (entget (car initial_text))) ; get the entity
    (if (= (cdr (assoc 0 initial_text_entity)) "TEXT") ; is it text?
    (setq loop_flag 1 ; set flag to exit loop & get parameters
    text_style (strcase (cdr (assoc 7 initial_text_entity)))
    text_horizontal_alignment (cdr (assoc 72 initial_text_entity))
    text_vertical_alignment (cdr (assoc 73 initial_text_entity))
    text_height (cdr (assoc 40 initial_text_entity))
    text_rotation (cdr (assoc 50 initial_text_entity))
    text_layer (cdr (assoc 8 initial_text_entity))
    text_color (cdr (assoc 62 initial_text_entity))
    )
    )
    )
    )
    (if (= text_color nil)
    (setq text_color 256)
    )
    (cond
    ((= text_horizontal_alignment 0) (setq horizontal_flag "L")) ; set justification flags
    ((= text_horizontal_alignment 1) (setq horizontal_flag "C"))
    ((= text_horizontal_alignment 2) (setq horizontal_flag "R"))
    ((= text_horizontal_alignment 4) (setq horizontal_flag "M"))
    )
    (cond
    ((= text_vertical_alignment 0) (setq vertical_flag ""))
    ((= text_vertical_alignment 1) (setq vertical_flag "B"))
    ((= text_vertical_alignment 2) (setq vertical_flag "M"))
    ((= text_vertical_alignment 3) (setq vertical_flag "T"))
    )
    (setq text_justification (strcat horizontal_flag vertical_flag))
    (if (and (= text_horizontal_alignment 0)
    (= text_vertical_alignment 0)
    )
    (setq insertion_point (cdr (assoc 10 initial_text_entity)))
    (setq insertion_point (cdr (assoc 11 initial_text_entity)))
    )
    (if (= text_style "ENCO3")
    (setq d 1.53843154)
    (if (or (= text_style "ROMANS")
    (= text_style "ENCO_ROMANS")
    (= text_style "ENCO_ROMAND")
    )
    (setq d 1.61904762)
    (if (= text_style "ENCO_BOLD")
    (setq d 1.77777778)
    (setq d 1.60641201)
    )
    )
    )
    (setq data2 "") ; initialize
    (setq direction (+ text_rotation (/ (* pi 3.0) 2.0)))
    (while (> direction (* pi 2.0))
    (setq direction (- direction (* pi 2.0)))
    )
    (setq insertion_point (polar insertion_point ; calculate the insertion point
    direction
    (* text_height d)
    )
    )
    (if (= text_justification "L")
    (command "_.dtext" "J" text_justification
    "S" text_style
    insertion_point
    text_height
    text_rotation
    pause
    ) ; get first line of text
    (command "_.dtext" "S" text_style
    insertion_point
    text_height
    text_rotation
    pause
    ) ; get first line of text
    )
    (setq data1 (cdr (assoc 1 (entget (entlast))))) ; retrieve the string
    (while (/= data1 data2) ; loop condition
    (setq data1 data2) ; set to break loop if no new entry
    (setq insertion_point (polar insertion_point ; calculate the insertion point
    direction
    (* text_height d)
    )
    )
    (if (= text_justification "L")
    (command "_.dtext" "J" text_justification
    "S" text_style
    insertion_point
    text_height
    text_rotation
    pause
    ) ; get next line of text
    (command "_.dtext" "S" text_style
    insertion_point
    text_height
    text_rotation
    pause
    ) ; get next line of text
    )
    (setq data2 (cdr (assoc 1 (entget (entlast))))) ; retrieve the string
    )
    (princ)
    (setvar "aunits" system_aunits)
    (setvar "auprec" system_auprec)
    (setvar "cecolor" system_color)
    (setvar "clayer" system_layer)
    (setvar "textstyle" system_style)
    (setvar "osmode" old_osmode)
    (command "._undo" "end")
    (setvar "cmdecho" 1)
    (setq *ERROR* old-error)
    )

     

     

  • I've found that the text command when run from a script runs as mullti-line.  This test script fills in the blanks properly and pauses for user input of one or more lines:

    text
    J
    C
    12.346,45.456,0.0
    9.0
    0.0

    There is no carriage return after the last line.  If the script is named "stext.scr" and on the search path

    (command "script" "stext")

    at the command line will run the script.   

     

     

  • In case anyone would like to see it here is my "final" code for appending texy below existing text.  Should be good enough until the bug in the text command is fixed.

    (defun c:addtext (/ system_layer system_style initial_text insertion_point text_rotation
    text_vertical_alignment text_color system_color text_horizontal_alignment
    text_style text_style just horizontal_flag vertical_flag text_layer
    text_height loop_flag old_osmode
    )

    (defun addtexterror (s)
    (princ s)
    (if new_text_entity
    (entdel new_text_entity) ; remove empty string entity
    )
    (setvar "cmdecho" 0)
    (command "._undo" "end")
    (setvar "aunits" system_aunits)
    (setvar "auprec" system_auprec)
    (setvar "cecolor" system_color)
    (setvar "clayer" system_layer)
    (setvar "textstyle" system_style)
    (setvar "osmode" old_osmode)
    (setvar "cmdecho" 1)
    (setq *error* old_error)
    (princ)
    )

    (setvar "cmdecho" 0)
    (command "._undo" "begin")
    (setq old_error *error*
    *error* addtexterror
    )
    (setq old_osmode (getvar "osmode"))
    (setq system_layer (getvar "clayer"))
    (setq system_style (getvar "textstyle"))
    (setq system_color (getvar "cecolor"))
    (setq system_aunits (getvar "aunits"))
    (setq system_auprec (getvar "auprec"))
    (setvar "aunits" 3) ; work in radians
    (setvar "auprec" 8)
    (setvar "osmode" 0) ; osnaps off
    (setq loop_flag 0)
    (while (= loop_flag 0)
    (progn
    (setq initial_text (entsel "\nSelect text line to append new text below ... \n"))
    ; select the initial text
    (setq initial_text_entity (entget (car initial_text))) ; get the entity
    (if (= (cdr (assoc 0 initial_text_entity)) "TEXT") ; is it text?
    (setq loop_flag 1 ; set flag to exit loop & get parameters
    text_style (strcase (cdr (assoc 7 initial_text_entity)))
    text_horizontal_alignment (cdr (assoc 72 initial_text_entity))
    text_vertical_alignment (cdr (assoc 73 initial_text_entity))
    text_height (cdr (assoc 40 initial_text_entity))
    text_rotation (cdr (assoc 50 initial_text_entity))
    text_layer (cdr (assoc 8 initial_text_entity))
    text_color (cdr (assoc 62 initial_text_entity))
    )
    )
    )
    )
    (if (= text_color nil)
    (setq text_color 256)
    )
    (cond
    ((= text_horizontal_alignment 0) (setq horizontal_flag "L")) ; set justification flags
    ((= text_horizontal_alignment 1) (setq horizontal_flag "C"))
    ((= text_horizontal_alignment 2) (setq horizontal_flag "R"))
    ((= text_horizontal_alignment 4) (setq horizontal_flag "M"))
    )
    (cond
    ((= text_vertical_alignment 0) (setq vertical_flag ""))
    ((= text_vertical_alignment 1) (setq vertical_flag "B"))
    ((= text_vertical_alignment 2) (setq vertical_flag "M"))
    ((= text_vertical_alignment 3) (setq vertical_flag "T"))
    )
    (setq text_justification (strcat vertical_flag horizontal_flag))
    (if (and (= text_horizontal_alignment 0)
    (= text_vertical_alignment 0)
    )
    (setq insertion_point (cdr (assoc 10 initial_text_entity)))
    (setq insertion_point (cdr (assoc 11 initial_text_entity)))
    )
    (if (= text_style "ENCO3")
    (setq d 1.53843154)
    (if (or (= text_style "ROMANS")
    (= text_style "ENCO_ROMANS")
    (= text_style "ENCO_ROMAND")
    )
    (setq d 1.61904762)
    (if (= text_style "ENCO_BOLD")
    (setq d 1.77777778)
    (setq d 1.60641201)
    )
    )
    )
    (setq data2 "") ; initialize
    (setq direction (+ text_rotation (/ (* pi 3.0) 2.0)))
    (while (> direction (* pi 2.0))
    (setq direction (- direction (* pi 2.0)))
    )
    (setq insertion_point (polar insertion_point ; calculate the insertion point
    direction
    (* text_height d)
    )
    )
    (setq insertion_point (strcat (rtos (car insertion_point) 2 8) ","
    (rtos (cadr insertion_point) 2 8) ","
    (rtos (caddr insertion_point) 2 8)
    )
    )
    (setq text_height (rtos text_height 2 8))
    (setq text_rotation (rtos text_rotation 2 8))
    (setq file (open (strcat "C:\\Autocad temp\\stext.scr") "w"))
    (write-line "_.dtext" file)
    (if (/= text_justification "L")
    (progn
    (write-line "J" file)
    (write-line text_justification file)
    )
    )
    (write-line "S" file)
    (write-line text_style file)
    (write-line insertion_point file)
    (write-line text_height file)
    (setq counter 1)
    (while (<= counter (strlen text_rotation))
    (write-char (ascii (substr text_rotation counter 1)) file)
    (setq counter (1+ counter))
    )
    (close file)
    (command "script" "C:\\Autocad temp\\stext.scr")
    (setvar "aunits" system_aunits)
    (setvar "auprec" system_auprec)
    (setvar "cecolor" system_color)
    (setvar "clayer" system_layer)
    (setvar "textstyle" system_style)
    (setvar "osmode" old_osmode)
    (command "._undo" "end")
    (setvar "cmdecho" 1)
    (setq *ERROR* old-error)
    (princ)
    )
  • I asked Bricsys support about the text-issue. The answer is bad news :

    Bricsys aims for the maximum compatibility with ACAD, now, as the ACAD text-command 

    behaves this way, Bricsys will behave this way too. So, it's not a bug, it's a feature,and it's

    likely that it will remain so.

  • Perhaps a few more details on exactly what aspect of the TEXT command is the same?   I have Autocad 2004 through 2010 here, and running thelisp  code in post #1 in Autocad gives me multi-line text, with the lines properly spaced.  In other words, the TEXT (or DTEXT) command called from lisp works exactly the same as typing TEXT at the command line.  Running the TEXT command at the command line in Bricscad is essentially the same as in Autocad [differences are lack of cursors in BC, AC lets you use the arrow keys to go back in the text to edit the string you are entering where BC only allows backspace to change the text, and AC shows the text on the screen during keyboard entry as left justified then updates to the proper justification when you complete the text command where BC shows the text on the screen properly].  In Bricscad when I run the TEXT command from lisp I get a single line of text and the function exits, just like the operation of the TEXT command in AC2004 when TEXT was for single line entry and DTEXT was for multi-line entry.  There are aspects of the TEXT command that are the same, but on my computers the operation of the TEXT command run from lisp is completely different in Bricscad compared to recent versions of Autocad.

    Martin

  • There isn´t much more to say actually. I told Bricsys support about my struggle with the code below (i.e. only one line of text).


    (defun c:test ( / pt)



    (command "._undo" "begin");öffnen UNDO-Gruppe



    (if (null (tblobjname "Layer" "T__Beschriftungen"))



    (command "_-layer" "_make" "T__Beschriftungen" "_lw" "0.18" "" "")



    (command "_-layer" "_set" "T__Beschriftungen" "")



    );if



    (initget 7)

    (setq pt (getpoint "\nStartpunkt :"))



    (setvar "textsize" 25.0)



    (command "-text" pt "" pause)



    (while (> (getvar "cmdactive") 0)

    (command pause)

    );while



    (command "._undo" "end");schliessen UNDO-Gruppe



    (princ)



    );defun

    The answer is (I hope Bricsys support doesn´t mind me making it public) :

    In fact, your Lisp code worked this way with Bricscad V7 ...
    but since V8, we strictly try to be most Acad compatible, in command and application behaviour.

    If you try your Lisp code with a recent Acad version, you will notice that your Lisp code will also not work in Acad as you expect.

    Solution to get multiple text lines entered sequentially is to widen the loop - each loop cycle will ask for 1 text; and your loop code can then calculate the vertical offset to get the next start point.


    I have no current ACAD version so I trust support on what they say. Still, although the loop is a way to go and that´s what I´m
    working on now, the whole issue puzzles me a bit, what would be the reason to drop the possibility to enter multiple lines
    of text in one go, I just don´t see it.

    Martin, would my code run properly on a current ACAD installation ? If yes, my faith in support would be shattered ;-).

  • Jorg,

    When I run your code in Autocad 2010 I get the following in the history window:

    [snip]

    Command: TEST
    ._undo Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes
    Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
    <1>: begin
    Command: _-layer
    Current layer:  "T__Beschriftungen"
    Enter an option
    [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck
    /Unlock/stAte/Description/rEconcile]: _set
    Enter layer name to make current or <select object>: T__Beschriftungen Enter an
    option
    [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck
    /Unlock/stAte/Description/rEconcile]:
    Command:
    Startpunkt :-text
    Current text style:  "Standard"  Text height:  25.0000  Annotative:  No
    Specify start point of text or [Justify/Style]:
    Specify height <25.0000>:
    Specify rotation angle of text <0>:

    Enter text: \
    Command: ._undo Current settings: Auto = On, Control = All, Combine = Yes,
    Layer = Yes
    Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
    <1>: end
    Command:
    Command: *Cancel*
    [/snip]

    I pressedthe left mouse button once to select the insertion point and once to accept the default text height, so I do not know why the program assumed I had entered '\' as the text string.  I see one \ on the screen and the function exits.  I get the same operation if I change the command call to     (command "_text" pt "" pause)   .  Note the underscore instead of the hyphen.

    I would say that Support is correct in their their statement that your code as written does not work in recent Autocad.  If I run your code in Bricscad V10 I can enter one line of text.  My coding problem is for entering multiple lines of text.  Changing the command call to     (command "_dtext" pt "" pause    works properly in Autocad to enter multiple lines but not in Bricscad.

    I did not clean out all the unnecessary code in my post #5, but I think that creating a script file may be the best approach for multi-line text from lisp in Bricscad at this point.

     

    Martin

     

    I think the best solution for Bricscad at this point is

     

     

  • Thank you Martin for your effort with my code.
    Me too, I try to find a possibility to enter as many lines of text as I wish in one go. From V7 days I have a program
    for appending more lines after you choose a line of text as an origin, I have yet to adapt it to the present conditions
    and then weld that crippled text-command and the append-program together in some way. I will eventually get there.

  • Hi, Jörg and Martin,

    the easiest solution to have multiple text lines entered :
    run a loop, and each loop inserts exactly 1 text entry ... instead of running 1 TEXT command, and multiple texts entrered, run MULTIPLE text commands.

    This should be pretty fine :-)
    Many greetings, Torsten

  • Torsten,

     

    Thank you for the response.  I tried running a loop that inserted one line of text per command call but found that the approach was unusable because the text was not shown on the screen until the Enter key was pressed for each line.  Since the text is not shown on the screen it is very difficult to enter lines of approximately the same length.  I do have a lisp routine which will set a new right boundary for multiple TEXT lines and will re-wordwrap the lines to respect the new right boundary, but running the routine to reset the right boundary is an extra step and takes extra time.

    It appears to me that the lisp implementation of TEXT or DTEXT in V10 is the same as the TEXT command in Autocad 2000, before Autodesk merged the TEXT and DTEXT commands -- the Bricscad lisp implementation gets a single line of text and does not show the characters on the screen until Enter is pressed.  The command line implementation of TEXT or DTEXT in V10 is the same as the DTEXT command in earlier versions of Autocad, where the user can enter multiple lines of text and the text is shown on the screen while it is being typed. 

    At this point Bricscad does not treat (command "TEXT" ... ) the same way that Autocad 2010 does.  I hope that Bricscad can be updated so that a lisp routine gives the same output in Bricscad as it does in Autocad.  Until then I will use the script approach because it lets me see what I'm typing in real time. 

    I would actually prefer to write my own function to enter text so that I could have a cursor on the screen and could use the arrow keys to go back in the text to make corrections without having to retype all the text after the correction; however, that requires that the arrow keys return codes in GRREAD.  In Autocad the arrow keys do not return codes.  In Bricscad the arrow keys return codes, but the codes are the same as for some punctuation characters, and I cannot find a way to determine whether the key actually pressed was an arrow key or %, &, (, or '.  I have reported this as a bug (#22575) but the response I got back did not imply that this would be fixed.  That is unfortunate because if two keys with very different purposes return the same code in GRREAD it makes GRREAD unusable for reading the keyboard because it is not possible to accurately determine what the user intended. 

    Martin

     

     

  • I ran the following and it works as expected, except for the NIL return

    command: (setq sty (getvar "textstyle"))
    "Standard"
    command: (setq txtht 3.0)
    3.0
    command: (setq trot 90.0)
    90.0
    command: (setq insp(getpoint "Locate Insert pt"))
    Locate Insert pt(198.736 46.2706 0.0)
    command: (command "_dtext" "s" sty insp txtht trot)
    command: _dtext
    Text: Style/Align/Fit/Center/Middle/Right/Justify/<Start point>: s
    Text style to use (or '?') <Standard>: Standard
    Text: Style/Align/Fit/Center/Middle/Right/Justify/<Start point>:
    Height of text <3.0000>: 3
    Rotation angle of text <90>: 90
    Text: NIL
    Text: hello
    Text: again
    Text:

    Didn't try using any of the code here except the (command "_dtext" ....), but it prompts for line after line.

    I've been usting a lisp from theswamp that changes text to mtext which I find handy in case I want to do any additional formatting.

  • Hi, Martin, the issue you reported is already fixed - strings as returned from COM can include 0 characters, which usually ends a string - but those strings from COM can include any binary character like 0, as your sample shows.

    This is fixed - I hope my fix will be included in one of the next Bricscad versions.
    Using this fixed Lisp engine, your sample code runs identical in Bricscad as with AutoCAD.

    Many greetings, and many thanks !

  • Ooops - sorry, Martin :-(

    You refered to the GRREAD problem, and I refered to your other support request, regarding strings including 0 characters.
    The GRREAD problem is already in our TaskList.

  • Jerry,

    I ran through the code you posted.  After running the (command "_dtext" ...      line Bricscad reports NIL to the command line.  Entering _dtext after that is running DTEXT from the command line, not from lisp.  DTEXT runs fine from the command line.

    Martin

  • I didnt enter anycommabd after the (command "_dtext" .....).  Bricscad returned Nil then asked for text which I supplied and entered, which kept me in the lisp intiated command for as many lines of text as I wanted.  I guess I'm missing something.

  • PASTE CODE HERE
    (defun txtd()
    (setq sty (getvar "textstyle"))
    (setq txtht 3.0)
    (setq trot 90.0)
    (setq insp(getpoint "Locate Insert pt"))
    (command "_dtext" "s" sty insp txtht trot)
    )
  • Jerry,

    I think there may be a problem with your   

         (command "_dtext" "s" sty insp txtht trot)  

    instruction.  It does not tell the lisp interpreter to pause for user input.  I would expect to see   

         (command "_dtext" "s" sty insp txtht trot pause)   

     

    The NIL return at the command line says that the previous command function returned a value, which implies that the lisp interpreter determined the command was complete.  The next line in your post is

         Command: _DTEXT

    which indicates that DTEXT was run from the command line.  The most likely possibility is that "Enter" or an equivalent (ie., spacebar) was the next user input recognized by the lisp interpreter, which repeated the last command, which was DTEXT.  

     

    Sorry I wasn't clearer in my earlier post.

     

    Martin


  • Thank you Jerry for your code, I see some light on the horizon.

    Contrary to what Martin says I'm able to enter as many lines of text as I want

    without "pause",here's what happend :

    : txtd
    Locate Insert pt
    : _dtext
    Text: Style/Align/Fit/Center/Middle/Right/Justify/<Start point>: s
    Text style to use (or '?') <DIN_6776>: DIN_6776
    Text: Style/Align/Fit/Center/Middle/Right/Justify/<Start point>:
    Height of text <25.0000>: 12.5
    Rotation angle of text <0.0>: 0
    Text:
    Text: sdfgsdgsdg
    Text: sdgsdgsg
    Text: sdfgsdgsg
    Text:

    I changed  "defun" to "defun c:" as well as textheight and rotation.

     

    But there's another problem, I enclose an exerpt of my "dtext"- version.

    The problem is that, after setting "T__Beschriftungen" as the current layer,

    the text wll be placed on layer "0", did anyone of you experience the same ?

    (defun C:test ( / lay pt ptb)

    ;prüfen ob Layer existiert, wenn nein, erstellen
    ;sonst Layer aktuell setzen

    (setq lay (getvar "clayer"))

    (if (null (tblobjname "Layer" "T__Beschriftungen"))

    (command "_-layer" "_make" "T__Beschriftungen" "_lw" "0.18" "" "")

    (command "_-layer" "_set" "T__Beschriftungen" "")

    );if

    (initget 129 "Ausrichten Einpassen Zentrieren Mitte Rechts OL OZ OR ML MZ MR UL UZ UR")
    (setq pt (getpoint "\nStartpunkt :"))

    (cond

    ((= pt "Ausrichten")

    (initget 1)
    (setq pt (getpoint "\nPunkt 1 für Textzeile:"))

    (initget 1)
    (setq ptb (getpoint pt "\nPunkt 2 für Textzeile:"))

    (command "_dtext" "_a" pt ptb)

    );"A"

    ((= pt "Zentrieren")

    (setq pt (getpoint "\nPunkt Zentrieren:"))
    (print (getvar "clayer"))
    (command "_dtext" "_c" pt)
    (print (getvar "clayer"))
    );"Z"

    (T

    (command "_dtext" pt)

    ) ; T

    );cond

    (setvar "clayer" lay)

    (princ)

    );defun
  • Suprised you didn't get a NIL line like I did, but yes it accepts as many lines as you want without touching the spacebar or return.  I figured that the NIL return from lisp was acting as a return keystroke, but notice that it doesn't echo the _dtext command.  Yes I would expect a pause. No, I wouldn't expect a NIL.  But it works.

    I haven't tried setting layers yet.  Like I mentioned I've been using Txt2Mtxt from the swamp which is really pretty neat for aligning existing text or simply changing dtext to mtext where you can obviously do all kinds of text manipulation.

    Will play with your code latter.  Think I'll call the layer "layerTest" so it will have some meaning to me. Is that German or?

  • I should have tested this instead of just going from my experience in Autocad. My appologies if I confused things.

    Since I have a mixed Autocad/Bricscad environment in my office I need a solution that works for both.  If the syntax in Bricscad is different from in Autocad that's a problem.  I'm hesitant to add work-arounds specific to Bricscad because I expect most of the differences to be corrected over time.  One of the reasons I'm converting as much of my office as possible to Bricscad is so that I can stop having to test and rewrite rewrite my custom routines with every release.

  • Wierd!! This is interesting to watch.  I put in a princ before "Startpunkt:" and it return the newly created layer as current, ...but as you say, puts the text on layer 0.

    In the properties list it doesn't change the current layer until after the lisp has ended.  Support request.

    
                            
  • Yes it is weird isn´t it ? Print clayer always returns "T__Beschriftung" (you´re right Jerry, it´s German, it means inscription, lettering)

    as current layer at the various stages of the program, but in the end the text is on layer "0". Thank you for playing with my code and

    it´s as you say : Support request !

  • Try this:

    ;;; Usage (pt en ptb are points):
    ;;; (dyntext nil)
    ;;; (dyntext (list "_align" pt ptb))
    ;;; (dyntext (list "_center" pt))
    ;;; (dyntext (list pt))
    ;;; Note: the list must be in the right order for the text command
    (defun DynText ( inputLst / marker)
    (setq marker (entlast))
    (command "_.text")
    (while inputLst
    (command (car inputLst))
    (setq inputLst (cdr inputLst))
    )
    (while (> (getvar "cmdactive") 0)
    (command pause)
    )
    (setvar "cmdecho" 0)
    (while (not (equal marker (entlast)))
    (setq marker (entlast))
    (command "_.text" "") ; restart text-command
    (princ "Text: ")
    (while (> (getvar "cmdactive") 0)
    (command pause)
    )
    )
    (setvar "cmdecho" 1)
    )

     

     

  • @J&ouml;rg Ehrsam:

    The code in your previous post #21 is faulty. As H Martin Shoemaker already pointed out: your command instruction does not tell the lisp interpreter to pause for user input. What happens is that the command is still running after the lisp function finishes (which is probably why you achieve the "dtext effect"). And as the lisp finishes clayer is reset transparently, explaining the "weird" layer effect. To test this load the lisp of post #21 and then run this small lisp:

    (c:test)
    (command 180 45 "Some text")
  • PASTE CODE HERE
    What I referred to is the weird layer flipping that transpires while running. I put a setvar before the dtext command and it set the layer, then flipped the layer to 0 before asking for text, then flips to the new layer.  Obviously not pausing for input is a bug but the behavior is hard to understand.
  • @Jerry Johnson:

    When I use Jörg's code (#21) I get:
    1. Old layer active
    2. New layer "T__Beschriftungen" is ceated and activated
    3. Prompt for point
    4. Old layer is reset
    5. Prompt for text height (Note: I see this prompt twice, at this point the lisp has been terminated) etc.
    6. Result: text is on the old layer and the old layer is the active layer
    In total I count 2 layer changes and this seems logical.

    Your description:
    > What I referred to is the weird layer flipping that transpires while running.
    > I put a setvar before the dtext command and it set the layer, then flipped the
    > layer to 0 before asking for text, then flips to the new layer. Obviously not
    > pausing for input is a bug but the behavior is hard to understand.

    From your description it seems you get this:
    1. Old layer active
    2. New layer "T__Beschriftungen" is ceated and activated
    3. Prompt for point
    4. Layer 0 is activated (where would this come from?)
    5. Prompt for text
    6. Result: text is on layer 0 and "T__Beschriftungen" is the active layer
    This would mean that you get a total of 3 layer changes. I don't understand this.

    Could you post the lisp that has this result.
    Note: I test using BC 10.2.10

  • @ Roy

    I know that there's a "pause" missing in the code, the funny thing is this way the code works
    in the sense, that you can enter multiple lines of text in one go, the drawback is the layerflipping.
    Add the "pause" and the following happens : the text is now on the proper layer but the command
    terminates after just one line of text. It seems that LISP, text/dtext and pause are not going
    together very well in V10.

  • @J&ouml;rg

    Try my code for DynText (#26). I have used your code (#21) for testing. Just modify all the calls to (d)text as described below:

    old: (command "_dtext" "_a" pt ptb)
    new: (dyntext (list "_align" pt ptb))

    old: (command "_dtext" "_c" pt)
    new: (dyntext (list "_center" pt))

    old: (command "_dtext" pt)
    new: (dyntext (list pt))
This discussion has been closed.