Jump to content

Recommended Posts

Posted

Hi,

I have seen lisp to add letter(s) to a text but I could not find a lisp that remove the last letter(s) by windows or crossing them . Would you please help me find one if it already posted or perhaps write one :) for me.

Thank you much.

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • BlackBox

    11

  • Lee Mac

    9

  • Reu

    6

  • Tharwat

    5

Top Posters In This Topic

Posted

Here's a simple example to get you started:

 

(defun c:FOO ( / ss)
 (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
   ((lambda (i / e ed s)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ed (entget e))
        (setq s (assoc 1 ed))
        (setq ed (subst (cons 1 (substr (cdr s) 1 (1- (strlen (cdr s))))) s ed))
        (entmod ed)))
     -1)
   (prompt "\n** Nothing selected ** "))
 (princ))

 

This code can be made more efficient, but I've left the multiple setq's so you can understand what the code is doing at each step.

Posted

That is beautiful.

Thank you RenderMan

Posted

the function *vl-string-right-trim* could also help you with it . :)

e.g.

 

(vl-string-right-trim "456" "123456")

 

Tharwat

Posted
That is beautiful.

Thank you RenderMan

 

You're very welcome. :)

Posted (edited)
the function *vl-string-right-trim* could also help you with it . :)

e.g.

 

(vl-string-right-trim "456" "123456")

 

So could "vl-string-subst" :wink: (

 

(defun c:FOO ( / *error* oldNomutt ss oDoc s)
 (vl-load-com)
 (princ "\rFOO ")
 (defun *error*  (msg)
   (and oldNomutt (setvar 'nomutt oldNomutt))
   (if oDoc (vla-endundomark oDoc))
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
   (princ))
 (prompt "\nSelect text objects to remove last character: ")
 (and (setq oldNomutt (getvar 'nomutt)) (setvar 'nomutt 1))
 (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
   (progn
     (vla-startundomark
       (setq oDoc (vla-get-activedocument (vlax-get-acad-object))))
     (vlax-for x  (setq ss (vla-get-activeselectionset oDoc))
       (setq s (vla-get-textstring x))
       [color=green];|[/color]
[color=green]        (vla-put-textstring[/color]
[color=green]          x[/color]
[color=green]          (vl-string-subst[/color]
[color=green]            ""[/color]
[color=green]            (substr s (strlen s) 1)[/color]
[color=green]            s)))[/color]
[color=green]            |;[/color]
       [color=blue](vla-put-textstring x (substr s 1 (1- (strlen s)))))[/color]
     (vla-endundomark oDoc)
     (vla-delete ss)
     (setvar 'nomutt oldNomutt))
   (progn
     (setvar 'nomutt oldNomutt)
     (prompt "\n** Nothing selected ** ")))
 (princ))

Edited by BlackBox
Code revised
Posted

Renderman, I think you mean:

 

(vl-string-subst "" (substr s (strlen s)) s)

But beware using this method...

 

(setq s "Renderman")
(vl-string-subst "" (substr s (strlen s)) s)

 

vl-string-right-trim would also be unpredictable if you only wanted to remove a specific number of characters.

 

I would use substr, as you have in the first post.

Posted
Renderman, I think you mean:

 

(vl-string-subst "" (substr s (strlen s)) s)

But beware using this method...

 

(setq s "Renderman")
(vl-string-subst "" (substr s (strlen s)) s)

 

vl-string-right-trim would also be unpredictable if you only wanted to remove a specific number of characters.

 

I would use substr, as you have in the first post.

 

Good catch, Lee. :D

 

Code revised.

Posted

Subst and entmod with Annotative text would cause Cad to screw up . :)

 

Nice routine Renderman , and why do not you include the Mtext also to the routine .!

 

Regards,

 

Tharwat

Posted

Subst and entmod with Annotative text would cause Cad to screw up . :)

 

I do not know anyone professionally (i.e., a firm I work with, etc.), that uses annotative objects.

 

Nice routine Renderman , and why do not you include the Mtext also to the routine .!

 

Thanks. :)

 

As for MText, technically, you could add it to the selection set filter given that the point is to trim the last single character. However, and this may just be how I work, but I put different types of data in Text as oposed to MText. I would never have a practical purpose (or at least cannot think of any) where I need to remove the last character of an MText's TextString:

 

;   TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;test}"

 

To each their own.

Posted
I do not know anyone professionally (i.e., a firm I work with, etc.), that uses annotative objects.

 

Agree completely .:)

As for MText, technically, you could add it to the selection set filter given that the point is to trim the last single character. However, and this may just be how I work, but I put different types of data in Text as oposed to MText. I would never have a practical purpose (or at least cannot think of any) where I need to remove the last character of an MText's TextString:

 

;   TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;test}"

To each their own.

 

I did add the MTEXT to the Selection Set and tried it with formatting Mtext , at the first time it does not remove the last character unless you repeat it two times .

 

Regards.

 

Tharwat

Posted

I did add the MTEXT to the Selection Set and tried it with formatting Mtext , at the first time it does not remove the last character unless you repeat it two times .

 

Incorrect; (and this is why I provided an example) the routine *did* remove the last character on the first pass, then removed the resultant's last characte on the second pass. :wink:

 

[color=silver];   TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;tes[/color][color=blue]t[/color][color=red]}[/color]"

Posted
Incorrect; (and this is why I provided an example) the routine *did* remove the last character on the first pass, then removed the resultant's last characte on the second pass. :wink:

 

[color=silver];   TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;tes[/color][color=blue]t[/color][color=red]}[/color]"

 

Cooooooooool Man :lol:

Posted
Incorrect; (and this is why I provided an example) the routine *did* remove the last character on the first pass, then removed the resultant's last characte on the second pass. :wink:

 

[color=silver];   TextString = "{\\C1;This\\P\\C2;is\\P\\C4;a\\P\\C6;tes[/color][color=blue]t[/color][color=red]}[/color]"

 

i.e. the routine screwed up the formatting codes... :ouch: For this to work with MText with formatting you would have to temporarily substitute/remove the formatting codes, operate on the string, then replace the formatting codes in the right places. I had similar issues to deal with when writing my BFind program - 2000 lines of code later and it still has bugs.

Posted
i.e. the routine screwed up the formatting codes... :ouch: For this to work with MText with formatting you would have to temporarily substitute/remove the formatting codes, operate on the string, then replace the formatting codes in the right places. I had similar issues to deal with when writing my BFind program - 2000 lines of code later and it still has bugs.

 

Which is why I left MText out of the original filter; I'm just saying. LoL

Posted
Which is why I left MText out of the original filter; I'm just saying. LoL

 

Oh exactly, I don't blame you, I would too :)

Posted (edited)
Oh exactly, I don't blame you, I would too :)

 

No worries - I didn't think you were suggesting otherwise. I was responding openly to the thread in response to your post, more so than directly responding to it (if that makes sense?).

 

In any event, we're good, bro.

Edited by BlackBox
I always catch the typos AFTER I hit the button!
Posted
1+........

 

I did mean that it is new to me to know that the mtext would behave that way when it is being formatted .

Thanks for the clarification .

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