Author Topic: Replacing text string  (Read 4048 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Replacing text string
« on: January 13, 2005, 09:34:56 AM »
I have a load of text strings that include room names and the area of the room, in the format :-

Code: [Select]
Room 1
General Classroom
87sqm


bearing in mind that every room has a different area, how can I remove the room areas from these strings.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #1 on: January 13, 2005, 09:46:07 AM »
What about "find and replace"?
TheSwamp.org  (serving the CAD community since 2003)

hudster

  • Gator
  • Posts: 2848
Replacing text string
« Reply #2 on: January 13, 2005, 09:49:41 AM »
tried that but it deletes the room numbers as well as thw sqm.

can i use wildcards in find and replace?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

M-dub

  • Guest
Replacing text string
« Reply #3 on: January 13, 2005, 09:52:08 AM »
Try a filter on Text Value with *sqm*, then erase?

might sound like a stupid idea, but it's an idea, anyway...:?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #4 on: January 13, 2005, 09:52:43 AM »
Is this mtext or text?
TheSwamp.org  (serving the CAD community since 2003)

M-dub

  • Guest
Replacing text string
« Reply #5 on: January 13, 2005, 09:53:05 AM »
I don't think you can use wildcards...
There might be a lisp routine out there that allows for wildcards in a find and replace, but none that I currently know of.

hudster

  • Gator
  • Posts: 2848
Replacing text string
« Reply #6 on: January 13, 2005, 09:54:30 AM »
all mtext.  I can't explode them as dtext is not allowed under our CAD standards.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

M-dub

  • Guest
Replacing text string
« Reply #7 on: January 13, 2005, 09:58:55 AM »
I guess the filter thing won't work then.  You couldn't explode, then convert back to mtext?  Sounds like a lot of work, but...?

CADaver

  • Guest
Replacing text string
« Reply #8 on: January 13, 2005, 10:07:38 AM »
Where's CAB when you need him, right?

Assuming the lines are hard returns (\P) you can use (substr to isolate the text between the hard returns and remove it.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #9 on: January 13, 2005, 10:51:22 AM »
try this.
Code: [Select]

(defun c:trash_sqm (/ ss cntr ent st entlst)
  (prompt "\nSelect Room tags: ")
  (setq ss (ssget '((0 . "MTEXT"))))
  (setq cntr 0)
  (while (setq ent (ssname ss cntr))
         (setq entlst (entget ent)
               st (cdr (assoc 1 entlst))
               )
         (if (wcmatch st "*sqm")
           (progn
             (setq entlst
                   (subst
                     (cons 1 (vl-string-right-trim "sqm1234567890" st))
                     (assoc 1 entlst)
                     entlst
                     )
                   )
             (entmod entlst)
             )
           )
         (setq cntr (1+ cntr))
         ); while
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

hudster

  • Gator
  • Posts: 2848
Replacing text string
« Reply #10 on: January 13, 2005, 10:55:38 AM »
excellent.

Can I make some changes to this?

When I find time I want to alter this to enable me to delete a user defined string.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

whdjr

  • Guest
Replacing text string
« Reply #11 on: January 13, 2005, 11:07:44 AM »
AAAGGGGHHHH!!!!!!!
MMMMAAAARRRRKKKK!!!!
 :evil:  :evil:  :evil:
 :D  :D  :D
You beat me again.  That's ok though.  I couldn't get mine to work although it should.  Can someone tell me why?
Code: [Select]
(defun c:no-area (/ ss len enl ent str num inc)
  (if (setq ss (ssget "X" '((0 . "mtext") (1 . "*\\P*SQM*"))))
 ;remove "X" if you omly want selected mtext
    (repeat (setq len (sslength ss))
      (setq len (1- len))
      (setq ent (ssname ss len))
      (setq enl (entget ent))
      (setq str (cdr (assoc 1 enl)))
      (setq num 0)
      (while
(setq inc (vl-string-search "\\P" str num))
(if inc
  (setq num (1+ inc))
)
      )
      (setq enl (subst (cons 1 (substr str 1 (1- num)))
                    (cons 1 str)
                     enl
                    )
       )
      (entmod enl)
      (entupd ent)
    )
  )
  (princ)
)

***edited***
Added a setq to the sust statement.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #12 on: January 13, 2005, 11:11:48 AM »
Quote from: Hudster
excellent.

Can I make some changes to this?

When I find time I want to alter this to enable me to delete a user defined string.

by all means, have at it. :D
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #13 on: January 13, 2005, 11:13:47 AM »
Quote from: whdjr
Can someone tell me why?

at first glance I'd say it's in the line.
Code: [Select]
(ssget "X" '((0 . "mtext") (1 . "*\\P*SQM*"))))

 :twisted:  :twisted:   :D
TheSwamp.org  (serving the CAD community since 2003)

whdjr

  • Guest
Replacing text string
« Reply #14 on: January 13, 2005, 11:14:48 AM »
No.  The whole routine works when you step through it in the VLIDE.  Just it doesn't update when you do the entmod.