Jump to content

Need some help with getstring


pmxcad

Recommended Posts

I have a lisp routine from Tharwat. I customized something so I can use setq variables (through getstring). But the code does not work, nothing happens. The input can be numbers and letters. What am I doing wrong?

Does anyone have an idea?

 

(defun c:test (/ ss)
 ;; Tharwat 15.12.2015    ;;

[color=red](setq str1 (getstring T "\nIDnr: "))
(setq str2 (getstring T "\nROOMnr: "))[/color]

 (setq lst '([color=red]("TEXT1" str1)[/color]
               [color=red] ("TEXT2" str2)[/color] ;; -> add more list of (tag . value) as you want
            )
 )
 (princ "\nSelect the Attributed block(s):")
 (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
   ((lambda (i / obj e f)
      (while (setq obj (ssname ss (setq i (1+ i))))
        (while
          (= "ATTRIB"
             (cdr (assoc 0 (setq e (entget (setq obj (entnext obj))))))
          )
           (if
             (setq f (assoc (cdr (assoc 2 e)) lst))
              (entupd (cdr (assoc -1 (entmod (subst (cons 1 (cadr f)) (assoc 1 e) e)))))
           )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Thanks in advance.

 

 

 

; error: bad DXF group: (1 . STR1)

Link to comment
Share on other sites

Hi,

 

Can you please try this untested modified codes and let me know?

(defun c:test (/ str1 str2 lst ss)
 ;; Tharwat 01.11.2017    ;;
(and (/= (setq str1 (getstring T "\nIDnr: ")) "")
     (/= (setq str2 (getstring T "\nROOMnr: ")) "")
     ;; -> add more list of (tag . value) as you want
     (setq lst (list (list "TEXT1" str1) (list "TEXT2" str2))) 
     (princ "\nSelect the Attributed block(s):")
     (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
     ((lambda (i / o e f)
        (while (setq o (ssname ss (setq i (1+ i))))
          (while (= "ATTRIB" (cdr (assoc 0 (setq e (entget (setq o (entnext o)))))))
            (if (setq f (assoc (cdr (assoc 2 e)) lst))
              (entupd (cdr (assoc -1 (entmod (subst (cons 1 (cadr f)) (assoc 1 e) e)))))
              )
            )
          )
        )
       -1
       )
  )
 (princ)
 )

Link to comment
Share on other sites

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...