initget and getpoint. a space between words is recognized as ENTER

initget and getpoint. a space between words is recognized as ENTER

Anonymous
Not applicable
1,346 Views
5 Replies
Message 1 of 6

initget and getpoint. a space between words is recognized as ENTER

Anonymous
Not applicable

Hey i'm trying to get a string or a point with the "getpoint" function. The problem is: 

 

If i have a word with a space between the characters (like "It's OK") it interrups at the space and recognize this as a Enter. 
So the qeustion is how do i keep typing with spaces between my words without getting "ENTER".

 

CODE PARTS here:

 

(initget 132 " ")
(setq point (getpoint (strcat "\nType contents of text or click for point and use current text. <current: " OnzichtbareText ">" )))
(if
  (eq (type point) 'STR)
  (progn
    (setq OnzichtbareText point)
    (command "_text" point "0" OnzichtbareText)
    );progn
      
  (progn
    (if (eq (type point) 'LIST)
      (progn
	(command "_text" "s" "ONZICHTBAAR" point "0" OnzichtbareText)
	);progn
      );if	
    );progn
  )

 

0 Likes
1,347 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Only way is use "quotation marks" ...like that.

And I guess your code is just a proposal... the try this modified code...

 

Spoiler
(defun c:test ( / done)

(setq OnzichtbareText "Text")
(while (not done)
  (initget 128)
  (setq point (getpoint (strcat "\nType the text or pick a point and use current '" OnzichtbareText "': " )))
  (cond ((eq (type point) 'STR)
	 (setq OnzichtbareText point))
	(point
	 (command "_text" "s" "ONZICHTBAAR" point "0" OnzichtbareText)
	 (setq done T)))
)
)

notes:

why initget +4? You may think about +1 But don't use it in this case. I does not prevent ENTER anyway and it returns "" when enter (=string)

make sure that you have set some initial value for OnzichtbareText.

make sure done is localized (or set nil before)

dont use <sharp parenthesis> for other function than enter.

Message 3 of 6

Anonymous
Not applicable

So there isn't any other way then "quotation marks" then? There isn't way to put space function off as "enter"? 

below the code,

 

(Defun c:Onztxt (/ oldlayer oldcmdecho oldosmode layer doc point temperr done)

  (setq oldlayer (getvar "CLAYER"))
  (setq oldosmode (getvar "osmode"))
  (setq oldcmdecho (getvar "cmdecho"))
  (setvar "osmode" 0)
  
  (setq temperr *error*)
  (setq *error* trap1)

  (if (tblsearch "LAYER" "4031.Niet.Afdrukbaar")
	    (progn
	      (setq layer "4031.Niet.Afdrukbaar")
	      (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
	      (setq layer (vla-item (vla-get-layers doc) layer))
	      (vla-put-LayerOn layer 1)
	      (vl-catch-all-apply 'vla-put-Freeze (list layer :vlax-false))
	      (vla-put-activeLayer doc layer)
	      )

    )

  (if (not(tblsearch "STYLE" "ONZICHTBAAR"))
    (entmake (list '(0 . "STYLE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbTextStyleTableRecord") '(2 . "ONZICHTBAAR") ;<- Your style name here
		   '(70 . 0) '(40 . 50.0) '(41 . 1.0) '(50 . 0.0) '(71 . 0) '(42 . 50.0) '(3 . "tahoma.ttf") '(4 . "")))

    )


  (if
    (eq OnzichtbareText nil)
    (progn
      (setq OnzichtbareText (getstring T (strcat "\nType contents of text?" )))
      (command "_text" "s" "ONZICHTBAAR" Pause "0" OnzichtbareText)
      (command "_text" "s" "ABICON tabel vet 4" "" "")
      );progn   

    (progn

      (while (not done)  
      (initget 128)
      (setq point (getpoint (strcat "\nType contents of text or click for point and use current: '" OnzichtbareText "'" )))
      (cond ((eq (type point) 'STR)
	     (setq OnzichtbareText point))
	    (point
	     (command "_text" "s" "ONZICHTBAAR" point "0" OnzichtbareText)
	     (command "_text" "s" "ABICON tabel vet 4" "" "")
	     (setq done T)))
	)
	    
      );progn
      

    )
    
  (setq *error* temperr)
  (setvar "cmdecho" oldcmdecho)
  (setvar "CLAYER" oldlayer)
  (setvar "osmode" oldosmode)
  )
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

I was going to suggest using (getstring) and let the "arbitrary input" allowed by the 128 bit argument in (initget) let you pick a point instead, but the 128 bit's arbitrary input needs to be textual, as if it's a keyword.

 

One thing you could do, though it involves an extra step for the User when they want to change the text content, is to have it ask for the point rather than the string, and have setting new text content as an option, something like [untested]:
....

      (initget "Newtext")
      (setq point (getpoint (strcat "\nClick for point and use current: '" OnzichtbareText "' or [Newtext]/<exit>: ")))

      (cond

        ((= point "Newtext") (setq OnzichtbareText (getstring T (strcat "\nType contents of text?" ))))

        ((listp point) ; picked a point

          (command "_text" "s" "ONZICHTBAAR" point "0" OnzichtbareText)
          (command "_text" "s" "ABICON tabel vet 4" "" "")

        ); picked-a-point condition

        ((setq done T)); Enter for <exit> default

      ); cond

....

Kent Cooper, AIA
Message 5 of 6

Anonymous
Not applicable

Good punt Kent,

 

But i came from that point before i posted, so i could do it with less input of the user. 

I made a little workaround that minors the use of a extra button.

It's a bit messy, the code now, but it works.  

 

(vl-load-com)

(defun trap1 (errmsg)					;define function				;undo back
  (setvar "cmdecho" oldcmdecho)
  (setvar "CLAYER" oldlayer)
  (setvar "osmode" oldosmode)
  (setq *error* temperr)				;restore *error*
  (prompt "\nResetting System Variables ")	;inform user
  (princ)
)

 
(Defun c:Onztxt (/ oldlayer oldcmdecho oldosmode layer doc point temperr done TempText)

  (setq oldlayer (getvar "CLAYER"))
  (setq oldosmode (getvar "osmode"))
  (setq oldcmdecho (getvar "cmdecho"))
  (setvar "osmode" 0)
  
  (setq temperr *error*)
  (setq *error* trap1)

  (if (tblsearch "LAYER" "4031.Niet.Afdrukbaar")
	    (progn
	      (setq layer "4031.Niet.Afdrukbaar")
	      (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
	      (setq layer (vla-item (vla-get-layers doc) layer))
	      (vla-put-LayerOn layer 1)
	      (vl-catch-all-apply 'vla-put-Freeze (list layer :vlax-false))
	      (vla-put-activeLayer doc layer)
	      )

    )

  (if (not(tblsearch "STYLE" "ONZICHTBAAR"))
    (entmake (list '(0 . "STYLE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbTextStyleTableRecord") '(2 . "ONZICHTBAAR") ;<- Your style name here
		   '(70 . 0) '(40 . 50.0) '(41 . 1.0) '(50 . 0.0) '(71 . 0) '(42 . 50.0) '(3 . "tahoma.ttf") '(4 . "")))
    )

  (if
    (eq OnzichtbareText nil)
    (progn
      (setq OnzichtbareText (getstring T (strcat "\nType contents of text?" )))
      (command "_text" "s" "ONZICHTBAAR" Pause "0" OnzichtbareText)
      (command "_text" "s" "ABICON tabel vet 4" "" "")
      );progn   

    (progn
      (initget 129)
      (setq point (getpoint (strcat "\nType contents of text or click for point and use current '" OnzichtbareText "' [R]:" )))
      (while (not done)
	
      (cond
	((And (eq point "R")
	      (eq (type point) 'STR))
	 (setq Temptext nil)	 
	 (initget 129 "R")
	 (setq point (getstring T (strcat "\nType contents of text or click for point and use current '" OnzichtbareText "' [R]:" )))
	 (setq TempText point)
	 )
	((And (not (eq TempText nil))
	      (eq (type point) 'STR))
	 (initget 129 "R")
	 (setq point (getpoint (strcat "\nType contents of text or click for point and use current '" OnzichtbareText "' [R]:" TempText " " )))
	 (if (eq (type point) 'STR)
	   (setq TempText (strcat TempText " "point))
	   )
	 );1 COND
	((eq (type point) 'STR)
	 (setq TempText point)
	 );2 COND	    
	(point
	 (if (not (eq TempText nil))
	   (setq OnzichtbareText TempText)
	   )
	 (command "_text" "s" "ONZICHTBAAR" point "0" OnzichtbareText)
	 (command "_text" "s" "ABICON tabel vet 4" "" "")
	 (setq done T)))
	);3 COND
	    
      );progn
      

    )
    
  (setq *error* temperr)
  (setvar "cmdecho" oldcmdecho)
  (setvar "CLAYER" oldlayer)
  (setvar "osmode" oldosmode)
  )

  

 

 

0 Likes
Message 6 of 6

ВeekeeCZ
Consultant
Consultant

why initget +4? You may think about +1 But don't use it in this case. It does not prevent ENTER anyway and it returns "" when enter (=string)

 

I'm not sure if this my note was understood correctly  because of my typo...

Just make sure that this is working correctly in your code (and as you wanted to)

 

if (initget 128)... and you hit enter inside of (getpoint) it returns nil. (my usage)

if (initget 129)... and you hit enter inside of (getpoint) it returns "" ... which IS a STRING. (your code)

 

0 Likes