Jump to content

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


Recommended Posts

Posted

Hi everybody,

 

I have a plan with 250 blocks with the same name.

and each block has a text with number (001,002,003,...248,249,250)

 

Now i would like to have a lisp to convert those text to attribute in his own block.

 

So maybe a lisp who ask to select a block...then select text....result block+ attribute.

 

Can anyone help me?

 

Many thanks!

 

Bono.

  • 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

Posted

But i really need to re-use my default text on the plan...

001,002,003 was a (bad) sample...In reality is something like that:

 

GFT001->003

GFT004->009

GFT010->013 .......

 

No logical sequence!!

Posted

its easy bono25, but i think you're going about it the wrong way. why not use one attribute block. instead of re-defining all 250 of them.

Can you explain this line ..

 

So maybe a lisp who ask to select a block...then select text....result block+ attribute.

 

The TEXT and BLOCK are a separate entities? or the TEXT is already a part of the block?

Posted

TEXT and BLOCK are a separate entities :cry:

Posted (edited)
TEXT and BLOCK are a separate entities :cry:

 

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

Edited by pBe
Posted

Thanks PBE,

 

I'm waiting this morning a mail with the plan....and i'll test it!!

you'll certainly receive a feed back from me.

Posted

:)

 

(princ "\n Select block with attribute")
'((0 . "INSERT")(66 . 1))

Posted
:)

 

(princ "\n Select block with attribute")
'((0 . "INSERT")(66 . 1))

 

Hi Tharwat,

 

I don't know what to do with your code?

Please explain me?

Posted
:)

 

(princ "\n Select block with attribute")
'((0 . "INSERT")(66 . 1))

 

I'm getting really rusty.. :lol:

 

Good catch Tharwat.

 

Hi Tharwat,

 

I don't know what to do with your code?

Please explain me?

 

Post #4 updated

Posted

I have test both code...i don't see a difference?

 

But it's possible to select block and text at once?

Posted
I have test both code...i don't see a difference?

 

ssget filter modified to select ONLY blocks with attributes

 

But it's possible to select block and text at once?

 

Yes of course. perhaps its better to show a drawing sample for us to provide a suitable code or suggestion.

Posted

I didn´t read all, but maybe help this code to convert a text -> block with attribut

(defun c:t2b ( / n aws obj)
 (setvar "cmdecho" 0)
 (setq os (getvar "osmode"))
 (princ "\nconvert text to block\n")
 (if (not (tblobjname "BLOCK" "YOUR BLOCK"))
   (alert "YOUR BLOCK IS NOT DEFINITION"))
 (setq n 0)
 (setvar "ATTDIA" 0)
 (setvar "ATTREQ" 1)
 (setvar "osmode" 0)
 (if (setq aws (ssget '((0 . "TEXT"))))
   (progn
     (repeat (sslength aws)
   (setq obj (entget (ssname aws n)))
   (command "_.-INSERT" "YOUR BLOCK"
        (cdr(assoc 10 OBJ))
        (getvar "dimscale") (getvar "dimscale") 0
        (rtos(atof (cdr(assoc 1 OBJ)))2 2))
   (setq n (1+ n))
   )
     )
   )
 (setvar "cmdecho" 1)
 (setvar "osmode" os)
 (princ)
 )

Posted (edited)

Here a sample...magenta block will come block with attribute.

Edited by bono05
Posted

Not a good idea using external link. Edit you post and attached the file ;)

Posted

Here you have a quick tool to change Text in Block Attribut

 

 

correctly better so...

(defun c:cha (/ txt blk)
 (if (= (cdr (assoc 0 (entget (setq txt (car (entsel "\nSelect text value ")))))) "TEXT")
   (progn
     (if (and (= (cdr (assoc 0 (entget (setq blk (car (entsel "\nSelect Chapelle block ")))))) "INSERT")
              (= (cdr (assoc 2 (entget blk))) (cdr (assoc 2 (tblsearch "BLOCK" "Chapelle"))))
              )
       (progn
         (entmod (subst (assoc 1 (entget txt)) (assoc 1 (entget (entnext blk))) (entget (entnext blk))))
          (entdel txt)
         )
       )
     )
   (princ "\nSelect a Text ")
   )
 (princ)
 )
       

Posted

Cadplayer,

 

I've tried this lisp....but after selection of block my text is gone and there is no attribute at the chapelle block?

Posted

Do you need TextObject or only TextAttribut ?

 

so delete only (entdel txt)

 

(defun c:cha (/ txt blk)
 (if (= (cdr (assoc 0 (entget (setq txt (car (entsel "\nSelect text value ")))))) "TEXT")
   (progn
     (if (and (= (cdr (assoc 0 (entget (setq blk (car (entsel "\nSelect Chapelle block ")))))) "INSERT")
              (= (cdr (assoc 2 (entget blk))) (cdr (assoc 2 (tblsearch "BLOCK" "Chapelle"))))
              )
       (progn
         (entmod (subst (assoc 1 (entget txt)) (assoc 1 (entget (entnext blk))) (entget (entnext blk))))
;;;           (entdel txt)
         )
       )
     )
   (princ "\nSelect a text ")
   )
 (princ)
 )
       

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