Jump to content

Attribute value to text within a block


DGRL

Recommended Posts

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • DGRL

    13

  • rlx

    10

  • BIGAL

    2

  • SLW210

    2

Top Posters In This Topic

Posted Images

Not sure why you need this either or if there's a better / easier way , but that's not my problem :D

 

 

try this :

(defun C:DGRL ( / err blockname ss blk)(DGRL_Init) (DGRL_Select_Blocks) (DGRL_Exit) (princ))
(defun DGRL_Error (s) (princ s)(DGRL_Exit)(setq *error* err))
(defun DGRL_Init () (vl-load-com) (setq err *error* *error* DGRL_Error blockname "textblock"))
(defun DGRL_Exit ()(princ "\nDone\n"))
(defun SS->Lst (ss) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(defun DGRL_Select_Blocks ( / ss blk obj lst)
 (if (setq ss (ssget "_x" (list (cons 0  "insert") (cons 2 blockname))))
   (progn
     (foreach blk (setq ss (mapcar 'vlax-ename->vla-object (SS->Lst ss)))
(setq lst (vl-catch-all-apply 'vlax-invoke (list blk 'explode)))
  (foreach obj lst (if (not (eq (vla-get-objectname obj) "AcDbMText"))(vla-delete obj))))
     (DGRL_ModifyBlockDefinition blockname)
   )
 )
)

(defun DGRL_ModifyBlockDefinition ( $block / obj e dict )
 (vlax-for obj (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) $block)
   (if (and (eq (vla-get-objectname obj) "AcDbMText") (setq e (entget (vlax-vla-object->ename obj)))
     (setq dict (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") e)))) (dictsearch dict "ACAD_FIELD")) (vla-delete obj))))

gr.Rlx

Link to comment
Share on other sites

I cant give you answer as my post does not appears

Don't know why

Routine does not work it burst the block does not make new one

 

you can buy a program call toolpac it has all the thing you need. it is a addon for autocad

Link to comment
Share on other sites

@rlx

 

Thanks for your reply

WHat does this code do?

Coz all i see now it that block still being present in org state and only mtext ( not containing fields ) "being" copied out of block and placed in model space

Am i correct?

Link to comment
Share on other sites

@rlx

 

Thanks for your reply

WHat does this code do?

Coz all i see now it that block still being present in org state and only mtext ( not containing fields ) "being" copied out of block and placed in model space

Am i correct?

 

ah , think I might have reversed before and after , thought you wanted to separate the mtext from the block and update the block definition (hence the burst burst burst), but you want the attributes become mtext? oh excuse , mtext to become attributes... that's just me being tired. Think its possible to convert mtext to attribute by substitude some dxf codes like in Lee's burst program but in this case I think I agree with bigal , and I would just read the values from the current block and redefine the block by inserting the new block and copying the old values into it. Will see if I can spare some time this weekend else maybe monday when the boss goes on a trip with some colleages..

 

gr. Rlx

dgrl-after.png

dgrl-before.png

Edited by rlx
Link to comment
Share on other sites

hi

 

i wanted the attribute value to become mtext ot text everything else needs to remain the same :-)

 

have to admit fields are complete uncharted territory for me. Have studied and making some progress but very slowly. But would simply redefine the block not be enough? You probably already have the block as you want it to be on disk or in a drawing. In that case wblock it and use it to update every drawing like this :

(defun c:t2 ( / new-block ss old-block ip)
 (if (and (setq new-block (findfile "d:/temp/lisp/Cad-tutor/dgrl/textblock-txt.dwg"))
          (setq ss (ssget "_x" (list (cons 0  "insert") (cons 2 "textblock"))))
          (setq old-block (ssname ss 0) ip (cdr (assoc 10 (entget old-block)))))
   (progn
     (setvar "expert" 3) (entdel old-block) (vl-cmdf ".-insert" (strcat "textblock=" new-block) ip 1 1 0)
   )
 )
 (princ)
)

in my case I saved the version without the attributes as 'textblock-txt' and then above function deletes the attributed one and inserts the new block but the name of the block in the drawing remains the same. I assume the values of the texts are set by means of a custom variable or something?

 

gr. Rlx

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