Jump to content

Recommended Posts

Posted

I have a text in drawing and want to delete a part of a it

This is the text

xxxx #xxxx

I want to detect # then delete and all letters after To be like this

xxxx

 

How is this?

 

Thanks

Posted

Use functions substr and entmod before subst 'ing the string ( if that is not annotative text )

Posted

You may need a complete code :lol:

 

(defun c:Test (/ ss)
 ;;; Tharwat 20. May . 2012 ;;;
 (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   ((lambda (inc / sn p ent)
      (while
        (setq sn (ssname ss (setq inc (1+ inc))))
         (if (setq p (vl-position
                       (ascii "#")
                       (vl-string->list
                         (cdr (assoc 1 (setq ent (entget sn))))
                       )
                     )
             )
           (entmod
             (subst (cons 1 (substr (cdr (assoc 1 (entget sn))) 1 p))
                    (assoc 1 ent)
                    ent
             )
           )
         )
      )
    )
     -1
   )
 )
 (princ)
)

Posted

another

(defun RemChar  (ch / ss p str e)
(cond ((and
            (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
            (repeat (sslength ss)
                  (if (setq p (vl-string-position
                            (ascii ch)
                            (setq str  (cdr (assoc 1
                                        (entget (setq e (ssname ss 0))))))))
                        (vla-put-textstring
                              (vlax-ename->vla-object e)
                              (substr str 1 p)
                              ))
                  (ssdel e ss))
            )
      )
     )
(princ))

 

Tharwat, why convert the string to list?

Posted

Tharwat, why convert the string to list?

 

Because the function vl-position needs a list while the ascii "#" would return a numerical value , so both are numbers now . ;)

Posted
Because the function vl-position needs a list while the ascii "#" would return a numerical value , so both are numbers now . ;)

 

[b]vl-string-position 
[/b]Looks for a character with the specified [b]ASCII [/b]code in a [b]string[/b]

 

No need to convert the string to a list my friend.

Posted
[b]vl-string-position 
[/b]Looks for a character with the specified [b]ASCII [/b]code in a [b]string[/b]

 

No need to convert the string to a list my friend.

That's correct if I am using vl-string-position but I am using vl-position

Posted

Instead of vl-position use vl-string-position, same result without the overhead of converting the string

 

just saying.....

Posted
Instead of vl-position use vl-string-position, same result without the overhead of converting the string

 

just saying.....

 

Ok , certainly I will do :)

Posted
another

...

 

Gives this error

; error: bad argument type: stringp nil

Posted

on your example string

 (remchar "#")

 

The code requires a TEXT/MTEXT selection. now if you want to use the fucntion for a string

(setq Remstr
          (lambda (str ch /  p str)
                (if (setq p (vl-string-position
                                  (ascii ch)
                                  str))
                      (substr str 1 p)
                      )
                )
     )

 

( Remstr "xxx#xxxx" "#")

 

 

HTH

Posted
on your example string

 (remchar "#")

That was the trick

(remchar #)

This is the mistake what I did

 

Thanks

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