Jump to content

Find a text string inside a block that could change depending on job and insert a block accordingly


Recommended Posts

Posted

I am trying to write something that will look inside the ROFSHT block, if it exists, for a text string that contains "ZL24".  The ROFSHT block may not contain "ZL24" so it needs to check for that as well.  If it does have a text string that contains "ZL24" it won't always be the same exact string.  For example the full string in one drawing could be "PANELS:  24 Ga. ZL24 - GALVALUME" but in another the "GALVALUME" portion could be different.

 

I don't know if I am going about it the correct way but I have a portion of lisp that creates a list of all text entities in the ROFSHT block if it exists.

(if
  (setq ent (tblobjname "BLOCK" "ROFSHT"))
  (while (setq ent (entnext ent))
    (if (= (cdr (assoc 0 (entget ent))) "TEXT")
      (setq textList (cons (cdr (assoc 1 (entget ent))) textList))
    )
  )
)

 

This returns a list looking like this:

("PANELS: 24 Ga. ZL24 - GALVALUME" "ROOF SHEETING PLAN" "PANELS: 24 Ga. ZL24 - GALVALUME" "ROOF SHEETING PLAN" " OUT-TO-OUT OF STEEL" "100'-0\"" "5\"" "5\"" "25'-0\"" "25'-0\"" "25'-0\"" "25'-0\"" "4" "3" "2" "5" "1" "50'-0\" OUT-TO-OUT OF STEEL" "A" "D" "1" "25'-0\"" "25'-0\"")

 

Do I need to iterate through the list and use wcmatch with a pattern of "*ZL24*" and if the condition is T it will insert the block I tell it to?

Or

Do I need to add wcmatch to the code above?

Or

Is there a different way to achieve this?

 

At any rate I'm lost on how to accomplish this the rest of the way.

I have attached a sample drawing that has the ROFSHT block in it.

 

Thanks

RoofDwg2.dwg

Posted

After looking at the dwg I am confused why is the  ROFSHT even a block ? Why not a roof layout on its own and the label could be a 2 line attribute block.

 

Did you copy and paste from another dwg ? When pasting don't use the paste as block option. 

 

The quickest answer is EXPLODE !!

 

For me I would look at using a label block when doing this type of thing this way it has a name, text style,  a color and a layer.

 

 

Posted

After you get that list, you can test to see if there is a string containing "ZL24 "

  (foreach l1 textList
    (cond
      ((wcmatch l1 "*ZL24*") (princ (strcat l1 " OK\n")))
      )
    )

On the other hand, assuming that the program doesn't need textList for something else, you could test the texts as you get them, something like:

(if
  (setq ent (tblobjname "BLOCK" "ROFSHT"))
  (while (setq ent (entnext ent))
    (if (= (cdr (assoc 0 (setq el (entget ent)))) "TEXT")
	  (cond
	    ((wcmatch (setq txt1 (cdr (assoc 1 el)) "*ZL24*") (princ (strcat txt1 " OK\n")))
      )
    )
  )
)

 

Posted

Or maybe a little bit simpler:

(defun c:pp()
 (if
  (setq ent (tblobjname "BLOCK" "ROFSHT"))
  (while (setq ent (entnext ent))
    (setq el (entget ent) a0 (cdr (assoc 0 el)))
    (cond
      ((and (= a0 "TEXT") (wcmatch (setq txt1 (cdr (assoc 1 el))) "*ZL24*")) (princ txt1))
      )
    )
  )
  (princ)
  )

 

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