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

attribute tag

6 REPLIES 6
Reply
Message 1 of 7
jsnortin
170 Views, 6 Replies

attribute tag

is there a way to select a block and add a new tag? I have a block called "address" with the tags "street", "p/s#", "node", "active" i would like to change these blocks on a dwg by dwg basis to add the tag "zipcode" to the block.
6 REPLIES 6
Message 2 of 7
EC-CAD
in reply to: jsnortin

Look into 'refedit' and 'attsnyc' commands.

Or, in Lisp, you could just 'rename' your block, get a selection
set of renamed blocks, grab existing attribute values - by tagname,
erase each old block, insert a new block with zipcode, and fill-in
all of the old attribute values.

Bob
Message 3 of 7
Anonymous
in reply to: jsnortin


Hi
size=3>JSNORTIN,

 

This is someting to get you started. The code is
build with the assumption that the attributes are placed vertically and being
equidistantly (evenly ?) placed by the Y axis. If you ever have some
other configuration for the attributes, then you should recalculate the
insertion point for the new one. I also assume that:

 

1) none of the four modes (invisible, constant,
verify and preset) is selected,

2) there is no initial value for the
attribute

3) the new prompt is "Enter the ZIP
code:"

 

but if any of these is different, it's up to
you to you can change it.

 

HTH

 

(defun add_attribute (
/
                              
adress_block_object


size=2>                              
index
                              
last_attribute
                              
previous_attribute
                              
last_attribute_insertion_point
                              
new_attribute_object
                            
)

 

  (setq
adress_block_object
   
(vla-item
     
(vla-get-blocks
       
(vla-get-activedocument
         
(vlax-get-acad-object)
       
)
      )
     
"address"
    )
  )

 

  (setq index 0)

 

  (vlax-for item
adress_block_object
    (if (= (vla-get-objectname item)
"AcDbAttributeDefinition")
      (setq index (1+
index))
    )
  )

 

  (setq last_attribute (vla-item block_object
index))

 

  (setq previous_attribute (vla-item
block_object (- index 1)))

 

  (setq
last_attribute_insertion_point
    (vlax-get last_attribute
'insertionpoint)
  )

 

  (if
   
(not
     
(vl-catch-all-error-p
        (setq
new_attribute_object
         
(vl-catch-all-apply
           
'vla-addattribute
           
(list

             
adress_block_object
             
(vla-get-height
last_attribute)
             
0
             
"Enter the ZIP
code:"
             
(vlax-3d-point
               
(list
                 
(car
last_attribute_insertion_point)
                 
(-
                   
(cadr
last_attribute_insertion_point)
                   
(abs
                     
(-
                       
(cadr (vlax-get last_attribute
'insertionpoint))
                       
(cadr (vlax-get previous_attribute
'insertionpoint))
                     
)
                   
)
                 
)
                 
(cadr
last_attribute_insertion_point)
               
)
             
)
             
"ZIPCODE"
             
""
           
)
         
)
       
)
      )
   
)
    new_attribute_object
    nil
 
)
)


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
is
there a way to select a block and add a new tag? I have a block called
"address" with the tags "street", "p/s#", "node", "active" i would like to
change these blocks on a dwg by dwg basis to add the tag "zipcode" to the
block.
Message 4 of 7
jsnortin
in reply to: jsnortin

i couldn't get it to work the block "address" actually is set up with the attributes like this
ADDRESS
STREET
ACTIVE
P/S#
NODENAME
i missed the one attribute "ADDRESS" in my original post. I don't know if that affects the lisp or not but I tried it and it did not work.
Message 5 of 7
Anonymous
in reply to: jsnortin


I tested the code with a dummy drawing, where I
created a block with your initial description and it works for me. Maybe it's a
better ideea to post here an demo drawing that contains the block, so I can test
it in "real life" conditions.

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
i
couldn't get it to work the block "address" actually is set up with the
attributes like this ADDRESS STREET ACTIVE P/S# NODENAME i missed the one
attribute "ADDRESS" in my original post. I don't know if that affects the lisp
or not but I tried it and it did not work.
Message 6 of 7
jsnortin
in reply to: jsnortin

I'm sorry that i didn't mention that the only attribute value visible is the ADDRESS tag the rest are invisible.i can't get anything to attach to this message but my email is billj@cable-services.com if you get ahold of me i'll send you a dwg .
Message 7 of 7
Anonymous
in reply to: jsnortin


Here is the last version, based on the drawing that
you sent me. Is tested and it works here, with the same drawing. I posted
it here because somebody else might need this code one day.

 


size=2>;;;=============================================

(defun add_attribute (
/
                               adress_block_object
                              
attribute_node
                              
attribute_active
                              
last_attribute_inspoint
                              
new_attribute_object
                            
)
  (vl-load-com)

 

  (setq
adress_block_object
   
(vla-item
     
(vla-get-blocks
       
(vla-get-activedocument
         
(vlax-get-acad-object)
       
)
      )
     
"ADDRESS"
    )
  )

 

  (setq index 0)
  (vlax-for item
adress_block_object
    (if (= (vla-get-objectname item)
"AcDbAttributeDefinition")
      (setq index (1+
index))
    )
  )

 

  (setq last_attribute (vla-item
adress_block_object (- index 1)))
  (setq previous_attribute (vla-item
adress_block_object (- index 2)))

 

  (setq
last_attribute_inspoint
    (vlax-get last_attribute
'insertionpoint)
  )

 

  (if
   
(not
     
(vl-catch-all-error-p
        (setq
new_attribute_object
         
(vl-catch-all-apply
           
'vla-addattribute
           
(list

             
adress_block_object
             
(vla-get-height
last_attribute)
             
acAttributeModeInvisible
             
"ZIPCODE"
             
(vlax-3d-point
               
(list
                 
(car
last_attribute_inspoint)
                 
(-
                   
(cadr
last_attribute_inspoint)
                   
(abs
                     
(-
                       
(cadr (vlax-get last_attribute
'insertionpoint))
                       
(cadr (vlax-get previous_attribute
'insertionpoint))
                     
)
                   
)
                 
)
                 
(cadr
last_attribute_inspoint)
               
)
             
)
             
"ZIPCODE"
             
""
           
)
         
)
       
)
      )
   
)
    new_attribute_object
    nil
 
)
)



size=2>;;;=============================================

 

HTH


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I'm
sorry that i didn't mention that the only attribute value visible is the
ADDRESS tag the rest are invisible.i can't get anything to attach to this
message but my email is billj@cable-services.com if you get ahold of me i'll
send you a dwg .

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

Post to forums  

Autodesk Design & Make Report

”Boost