Jump to content

Block + Mtext---> convert to Block + attribute


bono05

Recommended Posts

Hello,

 

I have a block "Detector" with already an attribute "DI"

+ mtext (wich is adress of detector) ---- See dwg sample in attachment

 

I would like to convert that mtext to a attribute in the block?

Idea is that i can manually select 1 block and his mtext...to convert it.

 

I hope there is a solution for this. o:)

 

Thanks!

block and mtext.dwg

Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • bono05

    12

  • Tharwat

    7

  • ttray33y

    5

  • AIberto

    2

Top Posters In This Topic

Posted Images

I would suggest, modify your block with specific attribute tag > attsync > redefine/ re-insert the block to your drawings > attsync > update you attribute value.

Link to comment
Share on other sites

Manually one by one...a lots of work isn't?

This is a sample with ony 3 blocks, but the fact is that i have more than 100 by plan.

Link to comment
Share on other sites

Manually one by one...a lots of work isn't?

This is a sample with ony 3 blocks, but the fact is that i have more than 100 by plan.

 

yes i understand, however your block share the same name, and adding an attrbiute in there will make every block the same as the other when syncing the attribute inserted.

Or we can wait Lee, Thar & Pbe advice.

Link to comment
Share on other sites

I'm not sure to understand!?

 

How can i make from my text a attribute?

 

I have a lisp that converts text/mtext to attribute + insert them to an existing block.

i already test it with your drawing.

Link to comment
Share on other sites

I have a lisp that converts text/mtext to attribute + insert them to an existing block.

i already test it with your drawing.

 

Great...but can you post it here please?

Link to comment
Share on other sites

Great...but can you post it here please?

 

Detecteur incendie mc.dwg

 

Alternative workaround.

Updated your block see (Detecteur incendie mc.dwg), test file (block and mtext.dwg), test LISP (txt2att.lsp).

 

open the test file attached, appload txt2att.lsp and invoke test1.

hint: it will convert the nearest text.

txt2att.lsp

block and mtext.dwg

Link to comment
Share on other sites

Waow!!!! congratulations!!!

 

Now because i have 3 of 4 differents blocks into my drawing can i just add an attribute COOR to another blocks. Or it's working only with block " Detecteur incendie mc".

 

ANd just to understand ...why tag name "COOR"? I don't see any link into the lisp.

 

OR can i add some blocknames here:

 

(setq blk (ssget "_X" '((0 . "INSERT") (2 . "Detecteur incendie mc") (66 . 1) (410 . "Model"))))

Link to comment
Share on other sites

Waow!!!! congratulations!!!

 

Now because i have 3 of 4 differents blocks into my drawing can i just add an attribute COOR to another blocks. Or it's working only with block " Detecteur incendie mc".

 

ANd just to understand ...why tag name "COOR"? I don't see any link into the lisp.

 

OR can i add some blocknames here:

 

(setq blk (ssget "_X" '((0 . "INSERT") (2 . "Detecteur incendie mc") (66 . 1) (410 . "Model"))))

 

exactly, it will only convert text nearest to the block Detecteur incendie mc. and will insert the text value to the first attribute it detect within your block which is COOR, of course you can add any attribute definition in your other block as long as that Attdef is at the top.

Link to comment
Share on other sites

It's possible to put more than one block into the script, not only "Detecteur incendie mc"??

So i can make all the plan at once.

Link to comment
Share on other sites

Add a new attribute object to every attributed block that you want to add the nearest mtext string to it then it would take less codes to write a routine to replace the nearest mtext string to

the new added attribute object as text string .

 

NOTE: if you want to add the mtext as a multiple lined text string , so that should be considered while adding the new attribute object in its mode .

Link to comment
Share on other sites

Add a new attribute object to every attributed block that you want to add the nearest mtext string to it

It's done

then it would take less codes to write a routine to replace the nearest mtext string to

the new added attribute object as text string

Need to change something in this code?

 

NOTE: if you want to add the mtext as a multiple lined text string , so that should be considered while adding the new attribute object in its mode .

One line is ok for me.

Link to comment
Share on other sites

Since that it is done , what is the new tag name that you added to each block ?

 

Upload a real drawing to avoid guessing and modifying the codes for several times . :)

Link to comment
Share on other sites

So i add a new attribute on each block (COOR)

 

Those are the different blockname:

Detecteur incendie mc

Detecteur incendie mc sol (this one have now 3 attributes)

efp02

EL001

EL003

Sirene incendie

P_R1.dwg

Link to comment
Share on other sites

All right , this should do the trick in one shot :)

 

(defun c:Test (/ il ml s i sn en v d lst)
 ;;------------------------------------;;
 ;;	Tharwat 28.4.2015		;;
 ;;------------------------------------;;
 (princ "\nSelect Attributed Blocks with Mtexts:")
 (if (setq s (ssget "_:L"
                    '((-4 . "<OR")
                      (-4 . "<AND")
                      (0 . "INSERT")
                      (66 . 1)
                      (-4 . "AND>")
                      (0 . "MTEXT")
                      (-4 . "OR>")
                     )
             )
     )
   (progn
     (repeat (setq i (sslength s))
       (setq sn (ssname s (setq i (1- i)))
             en (entget sn)
       )
       (if (eq (cdr (assoc 0 en)) "INSERT")
         (setq il (cons (list (cdr (assoc 10 en)) sn) il))
         (setq ml (cons (list (cdr (assoc 10 en)) sn) ml))
       )
     )
     (mapcar
       '(lambda (u)
          (mapcar
            '(lambda (p)
               (setq
                 lst (cons (list (distance (car u) (car p)) (cadr p))
                           lst
                     )
               )
             )
            ml
          )
          (setq v (vl-sort lst '(lambda (j k) (< (car j) (car k)))))
          (mapcar '(lambda (o)
                     (if (eq (strcase (vla-get-tagstring o)) "COOR")
                       (progn
                         (vla-put-textstring
                           o
                           (vl-string-subst
                             ""
                             "\\P"
                             (cdr (assoc 1 (entget (cadar v))))
                           )
                         )
                         (setq d (cons (cadar v) d))
                       )
                     )
                   )
                  (vlax-invoke
                    (vlax-ename->vla-object (cadr u))
                    'getattributes
                  )
          )
          (setq v   nil
                lst nil
          )
        )
       il
     )
     (mapcar 'entdel d)
   )
 )
 (princ)
)(vl-load-com)

Link to comment
Share on other sites

Exactly!!!

 

BIG thanks to you and ttray33y.

 

If i want to use this code for the future on another plan it's possible? Or the blockname present in this plan are important? And attribute name need always to be "COOR"

Link to comment
Share on other sites

Exactly!!!

 

BIG thanks to you and ttray33y.

 

Great , :)

 

 

If i want to use this code for the future on another plan it's possible? Or the blockname present in this plan are important? And attribute name need always to be "COOR"

 

 

You can use it with any attributed block name and the most important thing is that the tag name that should be included in the selected blocks.

 

Good luck .

 

Tharwat

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