Accessing then setting attributes in a block

Accessing then setting attributes in a block

squire3364
Contributor Contributor
516 Views
3 Replies
Message 1 of 4

Accessing then setting attributes in a block

squire3364
Contributor
Contributor

HI all,

 

I've just started working with LISP within the last week or two so excuse my possibly simple question.

 

I am working on creating a tool that takes the Area of a hatch, converts it from mm2 to m2 then inserts it into a block's attribute with two clicks. 

 

I've gotten as far as getting a value for the area and converting it to m2 however i can't for the life of me figure out how to access a blocks attributes to import the value into it. 

 

I've attached both a my lisp function and a snip of the what i'm getting to. It seems like i need to get into the attributes section, but i'm unsure how

Any insight into what i might need to do?

0 Likes
Accepted solutions (1)
517 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

Look into nentsel this allows you to pick an attribute directly in a block.

0 Likes
Message 3 of 4

ВeekeeCZ
Consultant
Consultant

The simplest is to use (setpropertyvalue e "tag" "value") e is ename of block

0 Likes
Message 4 of 4

pbejse
Mentor
Mentor
Accepted solution

@squire3364 wrote:

HI all,

Any insight into what i might need to do?


(defun C:hatcharea (/ ss atb nobj Tarea eo aream)
  (if (and
	(setq  ss (ssget '((0 . "hatch"))))
	(setq  atb (entsel "\nSELECT ROOM TAG"))
	(setq nobj (car (nentselp (cadr atb))))
	(eq "ATTRIB" (cdr (assoc 0 (setq A_ent (entget nobj)))))
  	)
    (progn
      (setq Tarea 0.0)
	(repeat (sslength ss)
	  (setq eo (ssname ss 0))
	  (setq area (vlax-get (vlax-ename->vla-object eo) 'Area))
	  
	  (setq area (if (eq (rtos (* area 1e-006) 2 2) "0.00")
		   area
		   (* area 1e-006)
		 )
		)
	  (setq Tarea (+ area  Tarea))
	  (ssdel  eo ss)
	 )
  (setq aream (rtos tarea 2 1))
  (setpropertyvalue (Car atb) (Cdr (assoc 2 A_ent)) aream)	  
  (print aream)
      )
    )
  (princ)
)

HTH

0 Likes