Jump to content

HELP TO MODIFY LISP (SELECTED BLOCK NAME TO SELECTED TEXT VALUE)


Recommended Posts

Posted

Dear All,

a small modification to be done in followig code. The below code can match the sorce text value to destination text value. The modifcation I need is to match block name value to selected text value.
 


Lisp Code 1 for reference:
(defun c:MT() (setq entt (car (entsel "Select source text:")))

                        (setq enttx (entget entt))

                        (setq txt (assoc 1 enttx))

                        (setq entd (entget (car (entsel "Select destination DIMENSION:"))))

                        (setq dtx (assoc 1 entd))

                        (setq vij (subst txt dtx entd))

                        (entmod vij))

Or other code I have, that can match text value to block name value.

(defun c:RNB

       (/ *error* _strip ssText ssBlock newBlockName blockName acDoc)

 

  (defun *error* (msg)

    (if     acDoc

      (vla-endundomark acDoc)

    )

    (cond ((not msg))                                                                                 ; Normal exit

              ((member msg '("Function cancelled" "quit / exit abort")))       ; <esc> or (quit)

              ((princ (strcat "\n** Error: " msg " ** ")))                           ; Fatal error, display it

    )

    (princ)

  )

 

  (defun _strip      (string)

    (foreach char '("<" ">" ":" "\"" "/" "\\" "|" "?" "*")

      (while (vl-string-search char string)

            (setq string (vl-string-subst "" char string))

      )

    )

    string

  )

 

  (while

    (and

      (princ "\nSelect text: ")

      (setq ssText (ssget ":S:E" '((0 . "MTEXT,TEXT"))))

      (princ "\nSelect block to rename: ")

      (setq ssBlock (ssget ":S:E" '((0 . "INSERT"))))

      (/= (setq      newBlockName

                         (strcat

                           ""

                           (_strip (vla-get-textstring

                                         (vlax-ename->vla-object (ssname ssText 0))

                                       )

                           )

                         )

              )

              (setq    blockName (vla-get-effectivename

                                        (vlax-ename->vla-object (ssname ssBlock 0))

                                      )

              )

      )

      (not (tblsearch "block" newBlockName))

    )

     (progn

       (vla-startundomark

             (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))

       )

       (vla-put-name

             (vla-item (vla-get-blocks acDoc) blockName)

             newBlockName

       )

       (prompt (strcat "\nBlock \""

                               blockName

                               "\" renamed to \""

                               newBlockName

                               "\" "

                   )

       )

     )

  )

)

Regards,
T.Brahmanandam

Posted (edited)

Simply...

 

(defun c:BN2TXT ( / bl txt bln )

  (vl-load-com)

  (while
    (or
      (not (setq bl (car (entsel "\nPick block to implement its name to text entity..."))))
      (if bl
        (or
          (/= (cdr (assoc 0 (entget bl))) "INSERT")
          (= (vla-get-isxref (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (vla-get-name (vlax-ename->vla-object bl)))) :vlax-true)
        )
      )
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (while
    (or
      (not (setq txt (car (entsel "\nPick destination text entity..."))))
      (if txt
        (not (wcmatch (cdr (assoc 0 (entget txt))) "*TEXT"))
      )
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (setq bln (vla-get-effectivename (vlax-ename->vla-object bl)))
  (vla-put-textstring (vlax-ename->vla-object txt) bln)
  (princ)
)

 

Edited by marko_ribar
Posted

Dear Sir,

I am getting error as below. Please help me.

; error: bad argument type: numberp: nil

Command: Bn2txt
Unknown command "BN2TXT".  Press F1 for help

 

Posted
1 hour ago, tnvsb said:

Dear Sir,

I am getting error as below. Please help me.

; error: bad argument type: numberp: nil

Command: Bn2txt
Unknown command "BN2TXT".  Press F1 for help

 

 

I don't receive such an error...

Please retest it again...

If someone else has an issue with error, then something's wrong, but on my PC it works just fine...

 

M.R.

Posted

Thank you sir,

 

Now it's working fine, I don't know what happened earlier.

 

Regards,

T.Brahmanandam

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