Jump to content

Convert block+text -----> block + attribute


bono05

Recommended Posts

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

  • bono05

    24

  • pBe

    12

  • Lee Mac

    8

  • cadplayer

    7

Top Posters In This Topic

Posted Images

I believe you are experiencing problems because there are groups of Text objects in your drawing with no attributed blocks associated, however, such Text objects are closer to other attributed blocks associated with other Text objects, for example:

 

badtext.png

 

Here, the Text objects in the lower half of the image have no attributed blocks associated with them, however they are closer to some of the blocks in the middle of the image.

Link to comment
Share on other sites

I also thing so...

I'll will isolante all block 'Chapelle' on a new dwg and than lisp.

I'll make this test tomorrow and will give feedback.

Link to comment
Share on other sites

After isolating all blocks "chapelle"...

 

There are always problem with numbers...

 

This is right back side of the plan view, and i have numbers 07B, 07C en 07D...normally only 07A.

He takes numbers from other side of the plan??

 

I'm really sorry about the result.

Link to comment
Share on other sites

Hi pBe (and others who can help me),

 

I'll using certainly your lisp for my problem...but it's possible to make that the selected text stay on his own position on the plan (position and rotation)?

 

Many thanks!

 

Bono.

I see, and i suppose the TEXT entities are not always on the same spot in relation with the block? then you really need to do the transformation one by one, but then again, use one (1) attribute block.

 

Redefine the block [250 blocks with the same name.] to include the attribute entity.

Use a code to copy TEXT string to attribute.

 

(defun c:cst (/ txt blk)
 ;; copy string
(vl-load-com)
 (prompt "\nSelect Text to transfer:")
 (if (and (setq txt (ssget "_+.:S:E" '((0 . "*TEXT"))))
   (princ "\nSelect block with attribute")
   (setq blk (ssget ":S" '((0 . "INSERT")(66 . 1))))
     )
   (vla-put-textstring
     (car (vlax-invoke
     (setq blk (vlax-ename->vla-object (ssname blk 0)))
     'GetAttributes
   )
     )
     (cdr (assoc 1 (entget (ssname txt 0))))
   )
 )(princ)
)

 

The code can be modified to target a specific TAG. but with the absence of a sample block, you going to have to deal with it yourself.

 

HTH

Link to comment
Share on other sites

Hi pBe (and others who can help me),

 

I'll using certainly your lisp for my problem...but it's possible to make that the selected text stay on his own position on the plan (position and rotation)?

 

Many thanks!

 

Bono.

 

You mean the Attribute will inherit the TEXT rotation and insertion point and delete the selected text entity?

Link to comment
Share on other sites

Try this

 

(defun c:cst (/ ss data txt atr)
;; copy string ;;
(vl-load-com)
 (prompt "\nSelect Text And Chapelle Block:")
 (if
   (and (setq ss (ssget "_:L"
	  '((-4 . "<OR") (-4 . "<AND")
	    (0 . "INSERT") (2 . "Chapelle")
	    (-4 . "AND>") (0 . "TEXT") (-4 . "OR>"))))
 (= (sslength ss) 2)
 (setq data (mapcar '(lambda (x)
		      (list (cdr (assoc 0 (setq en (entget x))))
			    (cdr (Assoc 1 en))
			    x)
		    )
		   (vl-remove-if
		     'listp
		     (mapcar 'cadr (ssnamex ss))
		   )
	   )
)
(/= (Caar data)(caadr data)))
   (progn
     (setq txt (vlax-ename->vla-object (last (assoc "TEXT" data)))
    atr (car (vlax-invoke
	       (vlax-ename->vla-object (last (assoc "INSERT" data)))
	       'GetAttributes)
	     )
	)
        (foreach itm '("Alignment"	 "Height"
	     "InsertionPoint"	 "Rotation"
	     "StyleName"	 "TextAlignmentPoint"
	    )
(vlax-put atr itm (Vlax-get txt itm))
     )
     (vla-put-textstring atr (cadr (assoc "TEXT" data)))
     (vla-delete txt)
   )
 )(princ)
)

 

Select both TEXT and BLOCK and see what happens

Link to comment
Share on other sites

I can't believe it! :D

 

So if i need to use it for another block...i just need to replace this line with the right block name?

(0 . "INSERT") (2 . "Chapelle")

Link to comment
Share on other sites

I can't believe it! :D

 

So if i need to use it for another block...i just need to replace this line with the right block name?

(0 . "INSERT") (2 . "Chapelle")

 

Yep, you can, otherwise use this to make it generic

 

(setq ss (ssget "_:L"
	  '((-4 . "<OR") (-4 . "<AND")
	    (0 . "INSERT") [b][color="blue"](66 . 1)[/color][/b]
	    (-4 . "AND>") (0 . "TEXT") (-4 . "OR>"))))

Link to comment
Share on other sites

  • 9 months later...
I see, and i suppose the TEXT entities are not always on the same spot in relation with the block? then you really need to do the transformation one by one, but then again, use one (1) attribute block.

 

Redefine the block [250 blocks with the same name.] to include the attribute entity.

Use a code to copy TEXT string to attribute.

 

(defun c:cst (/ txt blk)
 ;; copy string
(vl-load-com)
 (prompt "\nSelect Text to transfer:")
 (if (and (setq txt (ssget "_+.:S:E" '((0 . "*TEXT"))))
      (princ "\nSelect block with attribute")
      (setq blk (ssget ":S" '((0 . "INSERT")(66 . 1))))
     )
   (vla-put-textstring
     (car (vlax-invoke
        (setq blk (vlax-ename->vla-object (ssname blk 0)))
        'GetAttributes
      )
     )
     (cdr (assoc 1 (entget (ssname txt 0))))
   )
 )(princ)
)

 

The code can be modified to target a specific TAG. but with the absence of a sample block, you going to have to deal with it yourself.

 

HTH

 

This one works great for a similar situation I have!! Would it be possible to get a sample that shows how it can be modified to target a specific TAG?

 

Try this

 

(defun c:cst (/ ss data txt atr)
;; copy string ;;
(vl-load-com)
 (prompt "\nSelect Text And Chapelle Block:")
 (if
   (and (setq ss (ssget "_:L"
         '((-4 . "<OR") (-4 . "<AND")
           (0 . "INSERT") (2 . "Chapelle")
           (-4 . "AND>") (0 . "TEXT") (-4 . "OR>"))))
    (= (sslength ss) 2)
    (setq data (mapcar '(lambda (x)
                 (list (cdr (assoc 0 (setq en (entget x))))
                   (cdr (Assoc 1 en))
                   x)
               )
              (vl-remove-if
                'listp
                (mapcar 'cadr (ssnamex ss))
              )
          )
   )
   (/= (Caar data)(caadr data)))
   (progn
     (setq txt (vlax-ename->vla-object (last (assoc "TEXT" data)))
       atr (car (vlax-invoke
              (vlax-ename->vla-object (last (assoc "INSERT" data)))
              'GetAttributes)
            )
       )
        (foreach itm '("Alignment"     "Height"
            "InsertionPoint"     "Rotation"
            "StyleName"     "TextAlignmentPoint"
           )
   (vlax-put atr itm (Vlax-get txt itm))
     )
     (vla-put-textstring atr (cadr (assoc "TEXT" data)))
     (vla-delete txt)
   )
 )(princ)
)

 

Select both TEXT and BLOCK and see what happens

 

Yep, you can, otherwise use this to make it generic

(setq ss (ssget "_:L"
'((-4 . " (0 . "INSERT") [b][color=blue](66 . 1)[/color][/b]
(-4 . "AND>") (0 . "TEXT") (-4 . "OR>"))))

 

I can't get this version to work using the block specifc code or the generic code. AutoCAD returns "; error: AutoCAD.Application: Not applicable" in the command line after I select the objects (text and attributed block)... I realize this thread is pretty old but any help would be greatly appreciated!!!

Link to comment
Share on other sites

... I realize this thread is pretty old but any help would be greatly appreciated!!!

 

indeed it is, Don't even understand the code myself :lol: i've have a look see later sjc924, but i'm guessing you already found a solution. Anyhoo, if you're still interested send me a PM.

 

Cheers

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