Jump to content

Extract specific Attribures to text or mtext


ktbjx

Recommended Posts

i found this lisp here on cad tutor. and it works great!

but i was just wondering if i could just extract a specific attributes to text or mtext.

here is the thread:

http://www.cadtutor.net/forum/showthread.php?56833-Display-ATTRIBUTES-as-Text-from-multiple-blocks&highlight=attmt

 

 

i only needed the attributes "Hole_ID"

can someone help?

Attmt.LSP

Link to comment
Share on other sites

Like others here you pick a block and you getattributes looking for tag name = "Hole_id"

 

No error checking just a crude example of picking a block and finding "Hole_id"

(foreach att (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'getattributes)
       (if (= "HOLE_ID" (strcase (vla-get-tagstring att)))
       (alert (strcat "value found is "(vla-get-textstring att )))
       )
)

Link to comment
Share on other sites

Like others here you pick a block and you getattributes looking for tag name = "Hole_id"

 

No error checking just a crude example of picking a block and finding "Hole_id"

(foreach att (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'getattributes)
       (if (= "HOLE_ID" (strcase (vla-get-tagstring att)))
       (alert (strcat "value found is "(vla-get-textstring att )))
       )
)

 

 

thank you sir, i will try to figure out where will i put you code on the lisp... very much help!

Link to comment
Share on other sites

Here is a start, I would recommend adding a check does block have attributes, use entmake better than command for text.

 

(while (setq obj (vlax-ename->vla-object (car(entsel "pick block"))))
  (foreach att (vlax-invoke obj 'getattributes)
       (if (= "HOLE_ID" (strcase (vla-get-tagstring att)))
       (setq txt(vla-get-textstring att ))
       )
  )
 (if (/= txt nil)
 (progn 
   (setq pt (getpoint "pick point for text"))
   (command "text" pt 2.5 90 txt)
 )
 )
)

Link to comment
Share on other sites

Here is a start, I would recommend adding a check does block have attributes, use entmake better than command for text.

 

(while (setq obj (vlax-ename->vla-object (car(entsel "pick block"))))
  (foreach att (vlax-invoke obj 'getattributes)
       (if (= "HOLE_ID" (strcase (vla-get-tagstring att)))
       (setq txt(vla-get-textstring att ))
       )
  )
 (if (/= txt nil)
 (progn 
   (setq pt (getpoint "pick point for text"))
   (command "text" pt 2.5 90 txt)
 )
 )
)

 

 

i did it yey! thank you sir! look that i came up with!

(defun c:attmt(/ obj att txt pt)
(while (setq obj (vlax-ename->vla-object (car(entsel "pick block"))))
  (foreach att (vlax-invoke obj 'getattributes)
       (if (= "HOLE_ID" (strcase (vla-get-tagstring att)))
       (setq txt(vla-get-textstring att ))
       )
  )
 (if (/= txt nil)
 (progn 
   (setq pt (getpoint "pick point for text"))
;    (command "text" pt 1.5 90 txt)
    (entmakex
   (list
     (cons 0   "MTEXT")         
     (cons 100 "AcDbEntity")          
     (cons 100 "AcDbMText")    
     (cons 10 pt)  
     (cons 40 1.5) 
     (cons 7 "Swis721 BlkOul BT")
     (cons 1 txt)
     
   )
       )
         
 )
 )
)
)

the font won't work though >.

Link to comment
Share on other sites

StyleName = "Standard" the cons 7 is probably looking for a style name not the font name. cons 7 "Standard"

 

Entmake will over ride the text height which is good because if you use Command "text" it has two variants with and without text height. The height must be taken into account or code can error. I test but make sure what my text style is set to.

Link to comment
Share on other sites

the font won't work though >.

 

     
(cons 7 "Swis721 BlkOul BT") [color="blue"];; delete or comment it[/color]
(cons 1 (strcat "{\\fSwis721 BdOul BT|b0|i0|c0|p82;" txt "}"))

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