Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get attribute value per layout

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
acwtzwegers
998 Views, 3 Replies

Get attribute value per layout

I have drawings with multiple layouts with the same blocks on them, with the same attributes.... with different values ( which is the reason for the multiple layouts).

 

I've been using the attached code to retrieve values from attribs, but in case of the drawing as discribed above, I just get the same values... of the first layout encountered.

 

What could I change in the following code to make it more layout-specific... as in: only reading attribs in the current layout for example.

 

( defun B_Sub_Attribute_Get ( BS_TAG / B_ITEM B_ENTT BVALUE )
( setq BS_TAG ( strcase BS_TAG ) )
( if
	( ssget "x" '( ( 0 . "insert" ) ( 66 . 1 ) ) )
	( vlax-for B_ENTT
		( vla-get-activeselectionset ( vla-get-activedocument ( vlax-get-acad-object ) ) )
		( foreach B_ITEM ( vlax-invoke B_ENTT 'getattributes )
			( if 
				( = ( vla-get-tagstring B_ITEM ) BS_TAG )
				( setq  BVALUE ( vla-get-textstring B_ITEM ) )
)	)	)	)
( princ BVALUE )
)

 

3 REPLIES 3
Message 2 of 4
_Tharwat
in reply to: acwtzwegers

Try this instead .

 

(defun _princ:atts:value (tg)
;;;		Tharwat 05.01.2014		;;;
  (vlax-for x (vla-get-block
                (vla-get-activelayout
                  (vla-get-activedocument (vlax-get-acad-object))
                )
              )
    (if (and (eq (vla-get-objectname x) "AcDbBlockReference")
             (eq :vlax-true (vla-get-hasattributes x))
        )
      (foreach a (vlax-invoke x 'getattributes)
        (if
          (= (strcase (vla-get-tagstring a)) (strcase tg))
           (princ (strcat "\n " (vla-get-textstring a)))
        )
      )
    )
  )
  (princ)
)
(vl-load-com)

 

Message 3 of 4
Kent1Cooper
in reply to: acwtzwegers


@acwtzwegers wrote:

.... 

I've been using the attached code to retrieve values from attribs, but in case of the drawing as discribed above, I just get the same values... of the first layout encountered.

 

What could I change in the following code to make it more layout-specific... as in: only reading attribs in the current layout for example.

 

....
( ssget "x" '( ( 0 . "insert" ) ( 66 . 1 ) ) ) ....

 


This this in place of the above line:

 

(ssget "x" (list (0 . "insert") ( 66 . 1) (cons 410 (getvar 'ctab))))

 

The CTAB System Variable lists the current Layout Tab, so the above limits the selection to Blocks with Attributes that are in the current Layout.

Kent Cooper, AIA
Message 4 of 4
acwtzwegers
in reply to: acwtzwegers

Thank you both ( especially for the different (Lisp/vla) approaches ).

 

Whenever I add the ctab to the ssget, I get "; error: bad argument type: consp "insert"" but I agree that that way would be shortest.

 

In the end I came up with the following, which also allows to actually target from what layout tab one gets the attrib.

 

( defun B_Sub_Attribute_Get ( BS_TAG B_CTAB / B_FILE B_ITEM B_OBJ BVALUE BSTEMP )
( if ( = B_CTAB nil ) ( setq B_CTAB ( getvar "CTAB" ) ) )
( setq BS_TAG ( strcase BS_TAG ) )
( setq B_FILE ( vla-get-activedocument ( vlax-get-acad-object ) ) )
( if
	( ssget "x" '( ( 0 . "insert" ) ( 66 . 1 ) ) )
	( vlax-for B_OBJ
		( vla-get-activeselectionset B_FILE )
		( setq BSTEMP ( vla-objectidtoobject B_FILE ( vla-get-ownerid B_OBJ ) ) )
			( if ( = ( vlax-get-property BSTEMP "IsLayout" ) :vlax-true )	
				( if
					( = ( strcase B_CTAB ) ( strcase ( vla-get-name ( vla-get-layout BSTEMP ) ) ) )
					( foreach B_ITEM ( vlax-invoke B_OBJ 'getattributes )
						( if 
							( = ( vla-get-tagstring B_ITEM ) BS_TAG )
							( setq  BVALUE ( vla-get-textstring B_ITEM ) )
)	)	)	)	)	)
( princ BVALUE )
)

 

Just for style I am contemplating integrating Tharwat's full-vla selection though 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost