Jump to content

LISP to check all text strings in DWG and remove data readings if they exist...


tmelancon

Recommended Posts

I am in need of a LISP that will be used in a batch I will be running for a client on thousands of drawings before turning them over.

 

Essentially I am trying to develop a LISP that would search all TEXT/MTEXT entities in a drawing and if it includes what we call "data readings" on the end (e.g., .128, .220, .000) then they need to be removed, else do nothing. Some very old drawings may not have the thousandths, only tenths and hundredths (e.g. .12, .07, 34...) but I need the LISP to ultimately remove the decimal and anything after it if it exist in the drawing.

 

There are multiple instances of these within each drawings so they will all have different location names to which they are referring to on the pipe (e.g., PIPE, TEE, ELBOW, etc....), and also some may or may not have readings. The LISP would just skip those that do not have these readings.

 

EXAMPLE (Datapoint Locations with data readings):

#18.1- W-NIPPLE-D

#19.9- PIPE .000

#26- TEE .318

#22.1- CUPS-PIPE .178

 

EXAMPLE RESULT AFTER SAID LISP RUNS (Datapoint Locations WITHOUT data readings):

#18.1- W-NIPPLE-D            [IGNORED BY LISP BECAUSE NO DATA READING WAS DETECTED]

#19.9- PIPE                          [PROCESSED BY LISP AND .000 WAS REMOVED]

#26- TEE                               [PROCESSED BY LISP AND .318 WAS REMOVED]

#22.1- CUPS-PIPE              [PROCESSED BY LISP AND .178 WAS REMOVED]

....continue for remaining 

 

Please see the sample images I have provided of a drawing before and after the LISP I am trying to develop. I thank you in advance for even giving my post the time of day and as always you guys rock and I appreciate you.

Data Readings Remove Reading-Drawing1.png1591675818_DataReadingsRemoveReading-Drawing2(2).thumb.png.6378b15be181e2e493b3e3da50d65ac0.png

 

Edited by tmelancon
Link to comment
Share on other sites

How is your LISP programming? I haven't looked at this yet however if you can make up a LISP routine then the following might make some sense?

 

Thinking quickly, Lee Mac has a string to List LISP, perhaps if you can use ssget to get the text and mtexts into a selection set (and perhaps other text types, dimensions or whatever if necessary). Loop through the selection set and use Lee Macs string to List using a '.' as the deliminator, checking the last list item - a check for string length (should be 3 characters long), and a check to see if it is a number (atoi ? ) - if it is not an error the last 4 characters of the text string is a number ".xyz".. maybe look for stringsearch to delete that or, since you have a list all ready strcat the list items with a '.' (the deliminator) between each.. apart from the last list item.. which will give the new text string, then something like vl-put-textstring or entmod that text item from the selection set.

 

Hope that makes sense and might give you a way to go?

 

 

Got stuff to do this evening, else might be tempted to have a go for you,

  • Like 1
Link to comment
Share on other sites

@devitg our normal standard is text that contains a normal reading falls under the LOCAL-LINE-DATA blue layer. However, if we have a failing reading it defaults to LOCAL-LINE-HIGH red layer to stand out more. I am not totally concerned about specifying exact layers to look at which is simply why I want to look at all text and mtext entities but I guess we could add something like this to account for MTEXT and TEXT on layers ending in DATA and HIGH:

 

    (if (setq s (ssget "X" '((0 . "TEXT,MTEXT")(8 . "*DATA,*HIGH"))))

 

I really appreciate you responding and helping me. I hope this answered your question.

Link to comment
Share on other sites

@Steven P I will certainly consider all of your helpful information and apply this towards developing and testing something to achieve what I am looking for! Thanks for posting here I truly appreciate it! 

 

Hey if you take a stab at it and succeed then more power to you! Kudos to you for being awesome! I will keep at it on and off throughout my day when I have time. Will post updates as they come along.

 

Cheers

  • Like 1
Link to comment
Share on other sites

Try this ... does not check for locked layers.

(defun c:foo (/ a i o s)
  (if (setq s (ssget "_X" '((0 . "TEXT") (1 . "* .#,* .##,* .###"))))
    (foreach e (mapcar 'cadr (ssnamex s))
      (setq a (vla-get-textstring (setq o (vlax-ename->vla-object e))))
      (setq i (vl-string-position 32 a 0 t))
      (vla-put-textstring o (substr a 1 i))
    )
  )
  (princ)
)

 

Edited by ronjonp
  • Like 4
Link to comment
Share on other sites

5 minutes ago, ronjonp said:

Try this ... does not check for locked layers.

(defun c:foo (/ a i o s)
  (if (setq s (ssget "_X" '((0 . "TEXT") (1 . "* .#,* .##,* .###"))))
    (foreach e (mapcar 'cadr (ssnamex s))
      (setq a (vla-get-textstring (setq o (vlax-ename->vla-object e))))
      (setq i (vl-string-position 32 a 0 t))
      (vla-put-textstring o (substr a 1 i))
    )
  )
  (princ)
)

 

 

BRUHH!!! THIS IS EXACTLY WHAT I NEEDED! I am so grateful for your service to me and this website. I will research each line of code and reverse engineer it to learn more about what is taking place during each function. God bless you RONJONP !!

Link to comment
Share on other sites

4 minutes ago, tmelancon said:

 

BRUHH!!! THIS IS EXACTLY WHAT I NEEDED! I am so grateful for your service to me and this website. I will research each line of code and reverse engineer it to learn more about what is taking place during each function. God bless you RONJONP !!

Glad you could make use it. 🍻

 

Definitely test it out before shredding a directory of drawings. 

 

The filter will only grab end numbers up to 3 digits long so if there are any longer than that just keep adding # like so separated by commas:

(1 . "* .#,* .##,* .###,* .####,* .#####")

 

  • Like 2
Link to comment
Share on other sites

Hahaha 

 

Quote

Definitely test it out before shredding a directory of drawings. 

 

That's spot on! Love that comment! So accurate. I will definitely test a handful individually/manually, and also on a small test directory so I ensure the end product is exactly what I want. You totally rock man! 😍 💯

Edited by tmelancon
  • Like 1
Link to comment
Share on other sites

12 hours ago, BIGAL said:

Backup Backup Backup that is all I will say. USB sticks are cheap.

 

BIGAL KNOWS! Hahaha True experts know ALWAYS BACKUP!!!!! Thanks big dog! Cheers! 

Link to comment
Share on other sites

On 6/1/2022 at 4:42 AM, tmelancon said:

Hahaha 

 

 

That's spot on! Love that comment! So accurate. I will definitely test a handful individually/manually, and also on a small test directory so I ensure the end product is exactly what I want. You totally rock man! 😍 💯

 

Searches the text with (1 . "* .#,* .##,* .###,* .####,* .#####") format 

then finds where the ascii code 32 (space bar) is

and fetches only the text before it.

So, what to test for this complete and concise code is 

 

1. are there any spaces after the decimal point in your drawing

like "PIPE .123 ", "PIPE .123  ", "PIPE . 123"

 

This will be filtered out by the ssget filter. But it's hard to see on thousands of drawings 

 

2. or it will be or you used MTEXT, or the lock or freeze layer contains text

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