Jump to content
bono05

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

Recommended Posts

bono05

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

Share this post


Link to post
Share on other sites
ttray33y

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

Share this post


Link to post
Share on other sites
bono05

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.

Share this post


Link to post
Share on other sites
ttray33y
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.

Share this post


Link to post
Share on other sites
bono05

I'm not sure to understand!?

 

How can i make from my text a attribute?

Share this post


Link to post
Share on other sites
ttray33y
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.

Share this post


Link to post
Share on other sites
bono05
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?

Share this post


Link to post
Share on other sites
ttray33y
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

Share this post


Link to post
Share on other sites
bono05

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

Share this post


Link to post
Share on other sites
ttray33y
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.

Share this post


Link to post
Share on other sites
bono05

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.

Share this post


Link to post
Share on other sites
Tharwat

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 .

Share this post


Link to post
Share on other sites
bono05

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.

Share this post


Link to post
Share on other sites
Tharwat

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

Share this post


Link to post
Share on other sites
bono05

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

Share this post


Link to post
Share on other sites
Tharwat

Would you like to delete the Mtext object that would take a place of the attribute ?

Share this post


Link to post
Share on other sites
bono05

Yes please.

Share this post


Link to post
Share on other sites
Tharwat

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)

Share this post


Link to post
Share on other sites
bono05

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"

Share this post


Link to post
Share on other sites
Tharwat
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

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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