Jump to content

Remove the space from a text


Sweety

Recommended Posts

Hello. :)

 

Hope that someone would tell me how to remove the space from the selected text or mtext .

 

(setq e (car (entsel "\n Select Text :")))
(setq ent (entget e))
(entmod (subst (cons 1 .......

 

Not specifically the contents are known .

 

Thanks GUYS.

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    15

  • alanjt

    14

  • Michaels

    8

  • Sweety

    8

Top Posters In This Topic

Posted Images

(defun c:FOO  (/ ss)
 (vl-load-com)
 (vla-startundomark
   (cond (*activeDoc*)
         ((setq *activeDoc*
                 (vla-get-activedocument (vlax-get-acad-object))))))
 (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
   ((lambda (i / e v s)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq s (vla-get-textstring (setq v (vlax-ename->vla-object e))))
        (while (vl-string-search " " s)
          (setq s (vl-string-subst "" " " s)))
        (vla-put-textstring v s)))
     -1))
 (vla-endundomark *activeDoc*)
 (princ))

Edited by BlackBox
Code re-posted
Link to comment
Share on other sites

FYI Mat, if you are going to edit entities as vla-objects, it's faster to use vla-get-activeselectionset than to step through the selectionset and convert to vla-objects.

Link to comment
Share on other sites

FYI Mat, if you are going to edit entities as vla-objects, it's faster to use vla-get-activeselectionset than to step through the selectionset and convert to vla-objects.

 

Dually noted.

Link to comment
Share on other sites

Thank a lot gentlemen .

 

Renderman your routine works great .

 

Alanjt Please take a look

(defun noSpaces (str)
 (if (eq (type str) 'STR)
   (vl-list->string (vl-remove 32 (vl-string->list str)))
 )
)

(setq e (car (entsel "\n Select Text :")))
(setq ent (entget e))
(setq tt (cdr (assoc 1 ent)))
(noSpaces tt)

 

in the Visual Visp console I see the changes but that does not affect at the selected text.

 

What's wrong in the previous codes.

 

many thanks

Link to comment
Share on other sites

You will need to update the entity with the textstring returned by Alan's function.

 

I wanted to challenge myself to avoid the use of VL:

 

[ Scroll down after you have got something working on your own   ]








































(defun c:nospace ( / nospace ss )

 (defun nospace ( s )
   (
     (lambda ( o )
       (repeat (strlen s)
         (if (/= 32 (ascii s))
           (setq o (strcat o (substr s 1 1)))
         )
         (setq s (substr s 2))
       )
       o
     )
     ""
   )
 )

 (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   (
     (lambda ( i / e )
       (while (setq e (ssname ss (setq i (1+ i))))
         (entupd
           (cdr
             (assoc -1
               (entmod
                 (subst
                   (cons 1
                     (nospace
                       (cdr
                         (assoc 1 (entget e))
                       )
                     )
                   )
                   (assoc 1 (entget e))
                   (entget e)
                 )
               )
             )
           )
         )
       )
     )
     -1
   )
 )

 (princ)
)

Edited by Lee Mac
Link to comment
Share on other sites

If you didn't realize that it would only edit the string and not the object, then you need to learn the basics of editing objects before you go any farther.

Link to comment
Share on other sites

Wow Lee Thank you .

 

I really wanted to see it in Vanilla . your way of looping the codes make me crazy .:)

 

Although with entupd function it's not replacing the text :o

 

(defun noSpaces (str)
 (if (eq (type str) 'STR)
   (vl-list->string (vl-remove 32 (vl-string->list str)))
 )
)
(setq e (car (entsel "\n Select Text :")))
(setq ent (entget e))
(setq tt (cdr (assoc 1 ent)))
(noSpaces tt)
(entupd ent)

Link to comment
Share on other sites

Vanilla and recursive. cheesy.gif

 

(defun noSpaces (str / v)
 (if (eq str "")
   ""
   (if (eq (setq v (substr str 1 1)) " ")
     (noSpaces (substr str 2))
     (strcat v (noSpaces (substr str 2)))
   )
 )
)

Link to comment
Share on other sites

YES , I am sorry now it works OKI.

(defun noSpaces (str)
 (if (eq (type str) 'STR)
   (vl-list->string (vl-remove 32 (vl-string->list str)))
 )
)
(setq e (car (entsel "\n Select Text :")))
(setq ent (entget e))
(setq tt (cdr (assoc 1 ent)))
(entupd (cdr (assoc -1 (entmod (subst (cons 1 (noSpaces tt))(assoc 1 ent) ent)))))

 

Many thanks Alanjt

I am sorry again for misunderstanding.

Link to comment
Share on other sites

You're welcome, glad you got there in the end :)

 

Yeah ... I am so embarrassing with my mistake with (entupd and entmod) they shown me as a stupid .

 

Thanks a lot Lee

Link to comment
Share on other sites

Yeah ... I am so embarrassing with my mistake with (entupd and entmod) they shown me as a stupid .

 

Thanks a lot Lee

A person is only as stupid as they allow themselves to be.

Link to comment
Share on other sites

A person is only as stupid as they allow themselves to be.

 

Not completely , because the lack of informations is not a kind of allowing others to call me that way .

 

Maybe in some situations but not all. :)

Link to comment
Share on other sites

Not completely , because the lack of informations is not a kind of allowing others to call me that way .

 

Maybe in some situations but not all. :)

Well, you were the only one that called yourself stupid.

Also, you just grabbed and used a bit of code provided without studying it first - you would have realized that it only altered the string and did nothing to an object. Any limitations you incurred were of your own accord. I gave you the means to remove the spaces, if you are attempting you edit strings, you should already have a working knowledge of editing objects and not rely on me or anyone else for that.

Link to comment
Share on other sites

BTW, I really like the repeat from the string length idea, Lee. However, why'd you worry with converting the string to an ascii character when (eq s " ") would have sufficed?

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