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

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

Anonymous
Not applicable
1,561 Views
5 Replies
Message 1 of 6

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

Anonymous
Not applicable

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

0 Likes
1,562 Views
5 Replies
Replies (5)
Message 2 of 6

marko_ribar
Advisor
Advisor
Accepted solution

https://www.cadtutor.net/forum/topic/66097-help-to-modify-lisp-selected-block-name-to-selected-text-...

 

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 6

Anonymous
Not applicable
Accepted solution

But Not working Sir

0 Likes
Message 4 of 6

dbhunia
Advisor
Advisor
Accepted solution

@Anonymous wrote:

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


 

Try this.......

 

(defun c:MT()
(setq entt (car (entsel "\nSelect source text:")))
(setq enttx (entget entt))
(setq txt (cdr (assoc 1 enttx)))
(setq entd (entget (car (entsel "\nSelect Block:"))))
(setq dtx (cdr (assoc 2 entd)))
(if (/= dtx txt)
(progn
(command "_.rename" "_block" dtx txt)
(princ "\nBlock Name Changed")
(princ)
)
(princ "\nBlocks have the same name.")
)
(princ)
)


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

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


 

If I understand correctly, I think some are misinterpreting.  The wording "match ... source ... to ... destination" means, I believe, to take content from  the source object [the Block name] and impose it on  the destination object [the Text], not the other way around as some suggestions appear to work.  If that's right, this does so [in very simplest terms, without verifying selection of the right kinds of things, etc., but all that can be added if it does what you want]:

 

(defun C:BN2T (/ blkname txt); = Block Name {to} Text
  (setq
    blkname
      (vla-get-effectivename
        (vlax-ename->vla-object
          (car (entsel "\nSelect Block whose name is to become {M}Text content: "))
        )
      )
    txt (car (entsel "\nSelect {M}Text to make its content the Block name: "))
  )
  (vla-put-TextString (vlax-ename->vla-object txt) blkname)
)

It assumes a new-enough version of AutoCAD that the EffectiveName property exists for Blocks, whether Dynamic or ordinary.

 

Kent Cooper, AIA
Message 6 of 6

dbhunia
Advisor
Advisor
Accepted solution

Hi Kent,

 

You are right, I became little confused, the requirement ts "selected block name to selected text value".

 


@Anonymous wrote:

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


 

Hi T.Brahmanandam,

 

This is a small modification of your code..... 

 

(defun c:MT()
(setq entd (entget (car (entsel "\nSelect Block:"))))
(setq dtx (cdr (assoc 2 entd)))
(setq entt (car (entsel "\nSelect source text:")))
(setq enttx (entget entt))
(setq txt (assoc 1 enttx))
(setq vij (subst (cons 1 dtx) txt enttx))
(entmod vij)
)

 

 

Now its your choice which one you take ..........

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....