Jump to content

Is it possible to retrieve only one specific value of a block as a text depending of another value? (if, then)


stlo

Recommended Posts

Hi everyone! I'm wondering if it's possible to retrieve one value of a block depending on what another value of that same block is and show that value as a text over that same block? I would be kind of an isolated value of the BURST command I guess but keeping the Block as a Block. I'm joining a dwg with details in it and a screen capture! I hope it's enough clear! :) Thank you very much!

list of attributes.png

Lisp request.dwg

Link to comment
Share on other sites

Build a selection set of blocks with attributes.

for each block

step thought each attribute and save the "type" and "manufacturer_code"

if type is a matches a predefined list '("Base Cabinets" "Wall Cabinets" "Tall Cabinets")

then get a bounding box of the current block.

calculate the mid point

and create text with the "manufacturer_code" at the mid point.

 

;;----------------------------------------------------------------------------;;
;; Pull Manufacturer_Code for cabinets and input them center of block
(defun C:CAB-Label (/ Drawing ss blk atts att typ man minpt maxpt MPT)
  (vl-load-com)
  (setq i 0)
  (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object))))
  (prompt "\nSelect Blocks: ")
  (while (setq ss (ssget '((0 . "INSERT") (66 . 1)))) ;allows user to make multiple selections
    (setvar 'cmdecho 0)
    (foreach blk (mapcar 'vlax-Ename->Vla-Object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
      (setq atts (vlax-invoke blk 'getattributes))
      (setq typ "" man "")
      (foreach att atts
        (cond
          ((= (vla-get-tagstring att) "Type")
              (setq typ (vla-get-textstring att))
          )
          ((= (vla-get-tagstring att) "Manufacturer_Code")
              (setq man (vla-get-textstring att))
          )
        )
      )
      (if (member typ '( "Base Cabinets" "Wall Cabinets" "Tall Cabinets")) ;update list for other blocks
        (progn
          (vla-GetBoundingBox blk 'minpt 'maxpt)
          (setq MPT (mapcar '/ (mapcar '+ (vlax-safearray->list minpt) (vlax-safearray->list maxpt)) '(2 2 2)))
          (entmake (list '(0 . "TEXT") (cons 10 MPT) (cons 11 MPT) (cons 40 (getvar 'textsize)) (cons 1 man) '(62 . 1) '(72 . 1) '(73 . 2)))
          (setq i (1+ i))
        )
      )
    )
  )
  (prompt (strcat "\n" (itoa i) " Cabinets labeled")) ;message at the end
  (vla-endundomark Drawing)
  (setvar 'cmdecho 1)
  (princ)
)

 

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

Hi mhupp!! Wow! This is awesome! Thank you very much! This is exactly what I was thinking about! 

It's very helpful! 

Have a great day!

Link to comment
Share on other sites

@mhuppFWIW

;; This
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
;; Returns the same as this
(setq atts (vlax-invoke blk 'getattributes))
;; At least in AutoCAD

 

  • Like 2
Link to comment
Share on other sites

45 minutes ago, ronjonp said:

@mhuppFWIW

;; This
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
;; Returns the same as this
(setq atts (vlax-invoke blk 'getattributes))
;; At least in AutoCAD

 

@ronjonp Would you, please.   BLK shal be a vl-obj or an entity? and last but not least which properties can be call form VLAX-INVOKE? 

Thanks in advance 

 

Link to comment
Share on other sites

57 minutes ago, devitg said:

@ronjonp Would you, please.   BLK shal be a vl-obj or an entity? and last but not least which properties can be call form VLAX-INVOKE? 

Thanks in advance 

 

It needs to be a VLA object. I'd imagine any vla-get* could be called but not certain.

 

vla-getX.txt

Edited by ronjonp
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...