using autolisp prompt to populate dynamic block attribute

using autolisp prompt to populate dynamic block attribute

Anonymous
Not applicable
2,638 Views
22 Replies
Message 1 of 23

using autolisp prompt to populate dynamic block attribute

Anonymous
Not applicable

Below is my lisp program and attached is the sample dwg.

It works fine - but I can't figure out how to have the input information (How many Joists?, What size joists?, What is the piecemark?) to populate the dynamic block attributes - "Qty", "Size", "Mark" - respectively.

 

Is this possible?

any ideas?

 

;-------------------------------------------------------------------------------------;;;
;;; ;;;
;;; Joist Multiple function ;;;
;;; Description: Labels multiple joists and inserts "joist Multiple" block ;;;
;;; ;;;
;;;-------------------------------------------------------------------------------------;;;


(defun C:JM (/ p1 p2 qty size mark oldlayer oldsnap olddim)

;; Save Current Layer
;; Set Current Layer and Object Snap settings
(setq oldlayer (getvar "clayer")
oldsnap (getvar 'osmode)
olddim (getvar "dimstyle"))
(command "_dimstyle" "_r" "piecemarks")
(setvar "osmode" 640)
(command "clayer" "joist marks")

;; get poinTs & insert block
(setq p1 (getpoint "\nPick point: ")
p2 (getpoint "\nPick Second point: ")
qty (getreal "\nHow many joists?: ")
size (getstring "\nWhat size joists?: ")
mark (getstring "\nWhat is the piecemark?: "))

(setq str (strcat (rtos qty 2 0) "-" size "-" mark))

(command "dimaligned" p1 p2 "text" str "@0,0")

(command "_.insert" "joist multi" p1 "" """" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")


;; Reset Layer, OS, and Dimstyle

(setvar "clayer" oldlayer)
(setvar "osmode" 233)
(command "_dimstyle" "_r" olddim)
(princ)
)

;;; End function ;

0 Likes
Accepted solutions (4)
2,639 Views
22 Replies
Replies (22)
Message 21 of 23

_gile
Consultant
Consultant

@Anonymous wrote:

Giles,

thanks again!

works great.

It does have this error message coming up at the end - "Error: ADS request error".

 

the only thing I did was to run "battman" to rearrange the order of the attributes.

 


"Error: ADS request error" is thrown by the setpropertyvalue function.

As you can see, this function uses the attribute tags ("QTY", "SIZE", "MARK") or the dynamic property name ("Distance1") and has nothing to do with the attribute order.

       (setpropertyvalue (entlast) "QTY" (itoa qty))
       (setpropertyvalue (entlast) "SIZE" size)
       (setpropertyvalue (entlast) "MARK" mark)
       (setpropertyvalue (entlast) "AcDbDynBlockPropertyDistance1" (distance p1 p2))

 

The attribute order could affect @dbhunia 's codes because passing the attribute values in the (command "_.insert" ...) expression is related to the attribute order.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 22 of 23

dbhunia
Advisor
Advisor

Hi @_gile  do not take it other way ..........

 

I personally prefer like.....

 

(foreach att (vlax-invoke Obj 'GetAttributes)
	(if (= (vla-get-Tagstring att) (strcase TAG)) 
	    (vla-put-Textstring att "XYZ")
	);if
);foreach

But as @Anonymous  is a beginner ...... that's why I just followed that way ....... which he can understand

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 23 of 23

dbhunia
Advisor
Advisor

Hi @Anonymous  check this.......

 

(defun C:JM (/ *error* p1 p2 qty size mark oldlayer oldsnap olddim ang)
	(defun *error* ( msg )
		(setvar "clayer" oldlayer)
		(setvar "osmode" oldsnap)
		(setvar "dimstyle" olddim)
		(setvar 'attreq 1)
		(setvar 'cmdecho 1)
		(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
			(princ (strcat "\nOops an Error : " msg " occurred."))
		)
		(princ)
	)
	(defun LM:getdynpropvalue ( blk prp )
		(setq prp (strcase prp))
		(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
			(vlax-invoke blk 'getdynamicblockproperties)
		)
	)
	(defun LM:setdynpropvalue ( blk prp val )
	   (setq prp (strcase prp))
	   (vl-some
		  '(lambda ( x )
			   (if (= prp (strcase (vla-get-propertyname x)))
				   (progn
					   (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
					   (cond (val) (t))
				   )
			   )
		   )
		   (vlax-invoke blk 'getdynamicblockproperties)
	   )
	)
	(setq oldlayer (getvar "clayer")
		  oldsnap (getvar 'osmode)
		  olddim (getvar "dimstyle")
	)
	(setvar 'cmdecho 0)
	(setvar "osmode" 640)
	(setvar 'attreq 0)
    (setq p1 (getpoint "\nPick point: ")
		p2 (getpoint p1 "\nPick Second point: ")
		qty (getreal "\nHow many joists?: ")
		size (getstring "\nWhat size joists?: ")
		mark (getstring "\nWhat is the piecemark?: ")
	)
	(if (and p1 p2 qty size mark)
		(progn
			(command "_dimstyle" "_r" "piecemarks")
			(command "clayer" "joist marks")
			(setq str (strcat (rtos qty 2 0) "-" size "-" mark))
			(setq ang (/ (* (angle p1 p2) 180) pi))
			(command "dimaligned" p1 p2 "text" str "@0,0")
			(command "_.insert" "joist multi" "_none" p1 "" "" ang)
			(foreach att (vlax-invoke (vlax-ename->vla-object (entlast)) 'GetAttributes)
				(cond ((= (vla-get-Tagstring att) "QTY") (vla-put-Textstring att qty))
					((= (vla-get-Tagstring att) "SIZE") (vla-put-Textstring att size))
					((= (vla-get-Tagstring att) "MARK") (vla-put-Textstring att mark))
				)
			)
			(LM:setdynpropvalue (vlax-ename->vla-object (entlast)) "Distance1" (rtos (distance p1 p2) 2 0))
		)
	)
	(setvar "clayer" oldlayer)
	(setvar "osmode" oldsnap)
	(setvar "dimstyle" olddim)
	(setvar 'attreq 1)
	(setvar 'cmdecho 1)
	(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....