Jump to content

Lisp to eliminate the nth character of an attribute


itacad

Recommended Posts

Hi, I did a search but couldn't find anything...

Has anyone ever developed a topic regarding deleting a character in an attribute?

Let me explain better, I have attributes compiled with a numerical code 001,002...099...but it is required to delete the first character in such a way as to transform the text into 01,02...99.

I didn't succeed with the find and replace because there are many other codes that I don't have to change and the combinations I tried also consider these codes.

I would need a lisp that when launched deletes the nth character of the attributes that are clicked...nth because in my example it is the first character from the left, but it could be that in another example it is the second character, it depends on the situation.

Thanks for any reports, in the meantime I'll start deleting one by one...

 

 

Link to comment
Share on other sites

Do you have specific name of an attribute or you mean to do this nth removal on all blocks with attributes and all attributes residing those blocks...?

Link to comment
Share on other sites

Here try this code, though it's untested, but should work...

 

(defun c:test ( / n txt int sel ent get k )
  (initget 5)
  (setq n (getint "\nRemove char - nth : "))
  (setq int -1)
  (setq sel (ssget '((0 . "INSERT") (2 . "BLK-01"))));BLK-01
  (while (setq int (1+ int)
               ent (ssname sel int)
         );setq
    (while (/= (cdr (assoc 0 (setq get (entget (setq ent (entnext ent)))))) "SEQEND")
      (if (= (cdr (assoc 2 get)) "ATT-01");ATT-01
        (setq txt (cdr (assoc 1 get)))
        (setq txt (vl-list->string (vl-remove nil (mapcar (function (lambda ( x ) (setq k (if (not k) 0 (1+ k))) (if (/= k n) x))) (vl-string->list txt)))))
        (entupd (cdr (assoc -1 (entmod (subst (cons 1 txt) (assoc 1 get) get)))))
      );if
    );while
  );while
);defun

 

HTH.

M.R.

Edited by marko_ribar
Link to comment
Share on other sites

Thanks for now!
I would like to perform the operation on the attributes of the blocks that I click on, without knowing the block name, attribute name, etc. a priori. (I don't have the chance).
Like this lisp that I attach to you as a model that allows me to delete all the text of the attributes that I select in the way that I explained to you.
I tried your lisp but it gives me syntax error...

svuotatt.lsp

Link to comment
Share on other sites

Like this, though I don't know from where comes syntax error...

 

(defun c:test ( / att n get txt k )
  (setq att (car (nentsel "\nPick an attribute...")))
  (initget 5)
  (setq n (getint "\nRemove char - nth : "))
  (setq get (entget att))
  (setq txt (cdr (assoc 1 get)))
  (setq txt (vl-list->string (vl-remove nil (mapcar (function (lambda ( x ) (setq k (if (not k) 0 (1+ k))) (if (/= k n) x))) (vl-string->list txt)))))
  (entupd (cdr (assoc -1 (entmod (subst (cons 1 txt) (assoc 1 get) get)))))
  (princ)
)

 

M.R.

Link to comment
Share on other sites

Just thinking quickly,

nentsel or nentselp will get the entity name of the attribute from clicking on it, might need (last (nentsel )) though

 

After that it is just an entmod routine on the modified text.

Link to comment
Share on other sites

I discovered the syntax error...I had translated the page with Google Translate and taken the "translated" code...be patient!

Lisp is fine, but it has a somewhat slow procedure for what I need to do... don't classify me as insatiable, but I would need it to work like this:
- Selection which nth character to remove, the first (which I would like to correspond to 1 not 0)
- After this setting, have the command always active until the end of the attributes that I see and modify by clicking on them.
If you can, thanks, if not, patience but thanks anyway

Link to comment
Share on other sites

Like this :

 

(defun c:rem_num_chr_att-txt ( / att get txt k )
  (if (setq att (car (nentsel "\nPick an attribute or text entity...")))
    (progn
      (setq get (entget att))
      (setq txt (cdr (assoc 1 get)))
      (if *n* ;;; *n* - global variable
        (progn
          (prompt (strcat "\nSelected number for char removal : " (itoa (1+ *n*)) " - left click for new number or any key to proceed..."))
          (while (= (car (grread)) 3)
            (initget 7)
            (setq *n* (1- (getint (strcat "\nRemove char - number from 1 to " (itoa (strlen txt)) " : "))))
          )
        )
        (progn
          (initget 7)
          (setq *n* (1- (getint (strcat "\nRemove char - number from 1 to " (itoa (strlen txt)) " : "))))
        )
      )
      (setq txt (vl-list->string (vl-remove nil (mapcar (function (lambda ( x ) (setq k (if (not k) 0 (1+ k))) (if (/= k *n*) x))) (vl-string->list txt)))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 1 txt) (assoc 1 get) get)))))
    )
  )
  (princ)
)

 

HTH.

M.R.

Edited by marko_ribar
Link to comment
Share on other sites

Maybe you just saved my Saturday!

We'll talk to you after Easter, in the meantime, thanks again and best wishes!

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