Jump to content

Picking a MTEXT e replace a BLOCK ATTRIBUTE


jr.roberto.santos

Recommended Posts

Greetings everyone, I'm trying a way to select an MTEXT and Replace a block attribute.  
The block name is HDV1_CONVERT (Attributes: TAG1F, DESC1, DESC2, DESC3…)

Best Regards 

Link to comment
Share on other sites

I assumed that you are after replacing all text strings in the selected attributed block HDV1_CONVER to selected string from Mtext so here is a draft to see if this meet your aim of the program.

 

(defun c:Test (/ int sel str ent get)
  ;; Tharwat - 23.Dec.2021	;;
  (and
    (setq sel (car (entsel "\nPick Mtext : ")))
    (or (= (cdr (assoc 0 (entget sel))) "MTEXT")
        (alert "invalid object selected. Try again")
    )
    (setq str (cdr (assoc 1 (entget sel))))
    (princ
      (strcat "\nSelect Blocks to replace < HDV1_CONVERT > to replace < "
              str
              " > with all attributes with :"
      )
    )
    (setq int -1
          sel (ssget "_:L"
                     '((0 . "INSERT") (66 . 1) (2 . "HDV1_CONVERT"))
              )
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (while
        (and (setq ent (entnext ent))
             (not (eq (cdr (assoc 0 (setq get (entget ent)))) "SEQEND"))
        )
         (and (= (cdr (assoc 0 get)) "ATTRIB")
              (entmod (subst (cons 1 str) (assoc 1 get) get))
         )
      )
    )
  )
  (princ)
)

 

  • Like 2
Link to comment
Share on other sites

 

Tharwat

Thank you very much for your collaboration, for the code to be perfect, I just need to filter the attributes.

 

Example: DESC2 and DESC3

 

Please, see attachment with example DWG.

 

Best Regards

 

Sample_Drawing.dwg

Link to comment
Share on other sites

Give this a shot and let me know.

(defun c:Test (/ int sel str ent get)
  ;; Tharwat - 23.Dec.2021	;;
  (and
    (setq sel (car (entsel "\nPick Text or Mtext : ")))
    (or (wcmatch (cdr (assoc 0 (entget sel))) "MTEXT,TEXT")
        (alert "invalid object selected. Try again")
    )
    (setq str (cdr (assoc 1 (entget sel))))
    (princ
      (strcat "\nSelect Blocks to replace < HDV1_CONVERT > to replace < "
              str
              " > with all attributes with :"
      )
    )
    (setq int -1
          sel (ssget "_:L"
                     '((0 . "INSERT") (66 . 1) (2 . "HDV1_CONVERT"))
              )
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (while
        (and (setq ent (entnext ent))
             (not (eq (cdr (assoc 0 (setq get (entget ent)))) "SEQEND"))
        )
         (and (wcmatch (cdr (assoc 2 get)) "DESC2,DESC3")
              (entmod (subst (cons 1 str) (assoc 1 get) get))
         )
      )
    )
  )
  (princ)
)

 

Edited by Tharwat
You can select Text or Mtext now
  • Like 1
Link to comment
Share on other sites

As a beginner, I must also thank you.

 

Tharwat thanks so much for the help, the response was instantaneous!

Best Regards

J. Roberto

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