Author Topic: having difficulty adding choice of input to lisp  (Read 1201 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
having difficulty adding choice of input to lisp
« on: May 18, 2016, 03:32:48 PM »
Hi

I am trying to edit a lisp so that some annotation can either be added by text input or by clicking on the text in the drawing.
I have found Lee's function https://www.theswamp.org/index.php?topic=39042.0
LM:SelectionOrText
but am having difficulty integrating it as I am a bit of a lisp U grader.

The function returns the entity name, whereas I want the text contents (cdr (assoc 1 ent)) ??
All I need is the text if manually entered or the selected text entities contents saved to a variable, bit I'm damned if I can do it..

Here is the lisp, any help would be appreciated.

P

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2. ;; Routine to convert level block attributes to text levels with annotation
  3. ;;
  4. ;;
  5.  
  6. ;;
  7. (defun C:LEV2LEV()
  8. ;;
  9.  
  10. (SETQ DFLT 0)
  11. (SETQ TXTHG (GETVAR "textsize"))
  12. (PRINC "\nText Height: <")
  13. (PRIN1 TXTHG)
  14. (PRINC ">: ")
  15. (SETQ THGT (GETDIST))
  16. (IF (= THGT nil)
  17. (SETQ THGT TXTHG)
  18. )
  19.  
  20. (setq ent7 (car (entsel "\nPick the Level:"))); single pick
  21.  
  22. (if ent7
  23.         (progn
  24.         (setq elist7 (entget ent7)); get a List of that entity
  25.         (setq atr7 (entnext ent7)); get 1st attribute entity
  26.         (setq en7 (entget atr7)); get a List of attribute entity
  27.         (setq val7 (cdr (assoc 1 en7))); get the attrib's value
  28.         (setq num7 (atof val7)); make a number of val
  29.  
  30.  
  31.    (prompt (strcat "\nLEVEL=" val7)); display on Command Line
  32.  
  33.  
  34. ;(SETVAR "cmdecho" 0)
  35. ;(COMMAND "units" "" 2 "" "" "" "")
  36.  
  37.   (setq LEV (rtos num7 2 2))
  38.  
  39. ;(COMMAND "units" "" 3 "" "" "" "")
  40. ;(SETVAR "cmdecho" 1)
  41.  
  42. ;   (prompt (strcat "\nLEVEL=" LEV)); display on Command Line
  43.  
  44.  
  45.  ); progn
  46.  ); if
  47.  
  48.  
  49.  
  50.  
  51. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  52.  
  53. ;;;;;(SETQ ANNOT (GETSTRING "\nAnnotation: "))
  54.  
  55.  
  56.  
  57.  
  58. (setq annottxt (LM:SelectionOrText "\nSelect text: " '((0 . "TEXT"))))    ;;;;  if text is manually inputed selected then everything is fine and I can save it to annot, but it text selected it returns the entity name.
  59. ;(setq annot (cdr (assoc 1 ent)))
  60.  
  61.  
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  63.  
  64.  
  65. (SETQ LEV1 (STRCAT ANNOT " " LEV))
  66. (SETQ LEV2 (STRCASE LEV1))
  67.  
  68.  
  69. ;;(SETQ PTXT (GETPOINT "\nLocate Text: "))
  70.  
  71. (setq old_layer (getvar "clayer")); Get current Layer
  72.  
  73. (SETVAR "cmdecho" 0)
  74.  
  75. (setq PTXT (getvar "viewctr"))
  76.  
  77. (COMMAND "layer" "se" "text" "")
  78. (COMMAND "text" PTXT THGT "<<0" LEV2)
  79. (command "move" "last" "" PTXT pause)
  80.  
  81.  
  82. (setq CLASHING "CLASHING_LEVELS")
  83.  
  84.  
  85. (if (not (tblsearch "layer" CLASHING))
  86. (command "_layer" "M" CLASHING ""); Make the Layer, and set it current
  87. ); if
  88.  
  89. (command "_change" ent7 "" "_P" "_LA" CLASHING "")
  90.  
  91. (command "_layer" "S" old_layer ""); reset Layer
  92.  
  93.  
  94. (SETVAR "cmdecho" 1)
  95.  
  96.  (princ)
  97. ); function LEV2LEV
  98.  
  99.  
  100. ;;;;https://www.theswamp.org/index.php?topic=39042.0
  101.  
  102. (defun LM:SelectionOrText ( msg filter / g1 g2 gr res ss ) (princ msg) (setq res "")
  103.     (while
  104.         (progn
  105.             (setq gr (grread nil 14 2)
  106.                   g1 (car  gr)
  107.                   g2 (cadr gr)
  108.             )
  109.             (cond
  110.                 (   (= 3 g1)
  111.                     (if (ssget g2)
  112.                         (if (setq ss (ssget g2 filter))
  113.                             (progn (setq res (ssname ss 0)) nil)
  114.                             (princ (strcat "\nInvalid Object Selected." msg))
  115.                         )
  116.                         (princ (strcat "\nMissed, Try Again." msg))
  117.  
  118.                     )
  119.                 )
  120.                 (   (= 2 g1)
  121.                     (cond
  122.                         (   (<= 32 g2 126)
  123.                             (setq res (strcat res (princ (chr g2))))
  124.                         )
  125.                         (   (= 13 g2)
  126.                             nil
  127.                         )
  128.                         (   (and (= 8 g2) (< 0 (strlen res)))
  129.                             (setq res (substr res 1 (1- (strlen res))))
  130.                             (princ (vl-list->string '(8 32 8)))
  131.                         )
  132.                         (   t   )
  133.                     )
  134.                 )
  135.                 (   (= 25 g1)
  136.                     nil
  137.                 )
  138.                 (   t   )
  139.             )
  140.         )
  141.     )
  142.     res
  143. )
  144.  



Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: having difficulty adding choice of input to lisp
« Reply #1 on: May 18, 2016, 06:07:09 PM »
I would suggest something along the lines of the following:
Code - Auto/Visual Lisp: [Select]
  1. (if (= 'ename (type annottxt))
  2.     (setq str (cdr (assoc 1 (entget annottxt))))
  3.     (setq str annottxt)
  4. )

I'm pleased that you find that old function useful!

Pad

  • Bull Frog
  • Posts: 342
Re: having difficulty adding choice of input to lisp
« Reply #2 on: May 18, 2016, 06:38:52 PM »
Ah yes! Nice one that's done it. Thanks.



Pad

  • Bull Frog
  • Posts: 342
Re: having difficulty adding choice of input to lisp
« Reply #3 on: May 18, 2016, 06:40:13 PM »
Its a great function.  I don't understand quite how it works, but it does a good job.  Cheers P