Jump to content

Help to edit LISP


Rooster

Recommended Posts

Hi folks. I use the following LISP to add a specified prefix to a bit of text & then delete the corresponding note.

 

Could someone help me edit this to make it more versatile? Rather than adding the same prefix every time I would like to select the note, copy the contents to use as the prefix, add it to the selected text, and then delete the note leaving just the text with its now-added prefix.... Hope that all makes sense :)

 

;ADDS PREFIX OF 'DK:' TO SELECTED TEXT & THEN DELETES ORIGINAL DK NOTE
(defun c:dk (/ tSet dl)
   (vl-load-com)
   (if    (setq tSet (ssget '((0 . "TEXT,MTEXT"))))
   (foreach tx (mapcar 'vlax-ename->vla-object
               (vl-remove-if
               'listp
               (mapcar 'cadr (ssnamex tSet))
               ) ;_  end vl-remove-if
           ) ;_  end mapcar
       (vla-put-TextString
       tx
       (strcat "DK:" (vla-get-TextString Tx))
       ) ;_  end vla-put-TextString
   ) ; end foreach
   ) ; end if
   (setq dl (ssget))
   (command "erase" dl "")
   (princ)
) ; end of c:dk

Link to comment
Share on other sites

Like this?

 

(defun c:ptxt (/ ent pr ss)
 (if (and (setq ent (car (entsel "\nSelect Prefix Text: ")))
          (wcmatch (cdr (assoc 0 (entget ent))) "*TEXT")
          (setq pr (cdr (assoc 1 (entget ent)))))
   (if (setq ss (ssget '((0 . "*TEXT"))))
     (progn
       (mapcar
         (function
           (lambda (x)
             (vla-put-TextString x
               (strcat pr (vla-get-TextString x)))))
         (mapcar 'vlax-ename->vla-object
           (vl-remove-if 'listp
             (mapcar 'cadr (ssnamex ss)))))
       (entdel ent))))
 (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...