LISP ROUTINE - Setting Dynamic Properties Problem while Inserting Block

LISP ROUTINE - Setting Dynamic Properties Problem while Inserting Block

emreakyazici
Advocate Advocate
1,056 Views
4 Replies
Message 1 of 5

LISP ROUTINE - Setting Dynamic Properties Problem while Inserting Block

emreakyazici
Advocate
Advocate

Hey everyone, thanks to @ВeekeeCZ, I obtained a LISP that inserts blocks by predetermining dynamic properties and attributes. However, I tried a lot and could not set the angle as radians. I always get the error of ; error: lisp value has no coercion to VARIANT with this type: ANG1.

 

Here is the LISP and DWG, I hope you may help.

 

 

 

(vl-load-com)

(defun c:INS123 ( / o dynprops atvalues)

(defun dtr (a)
(* pi (/ a 180.0))
)

(setq ang1 (dtr 25.0)) ; POSSIBLE ERROR POINT!!


  (command-s "_.-insert" "BLOCKNAME1" "_b" "0,-10" "_s" 1 "_r" 0)
  (setq dynprops '(

		   ("Angle1" . ang1) ; POSSIBLE ERROR POINT!!
		   ("Position1 X" . 10)			; all dyn-values are numbers - without ""
		   ("Position1 Y" . 10)

		   ("Position2 X" . 20)			; all dyn-values are numbers - without ""
		   ("Position2 Y" . 20)

		   ("Position3 X" . 30)			; all dyn-values are numbers - without ""
		   ("Position3 Y" . 30)

		   ("Position4 X" . 40)			; all dyn-values are numbers - without ""
		   ("Position4 Y" . 40)

		   )
	
	atvalues '(
			("TAG1" . "VALUE11")
			("TAG2" . "VALUE22")
			("TAG3" . "VALUE33")
			("TAG4" . "VALUE44")

		   ))
	
  (setq o (vlax-ename->vla-object (entlast)))
  (LM:setdynprops o dynprops)
  (LM:vl-setattributevalues o atvalues)
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set Dynamic Block Properties  -  Lee Mac
;; Modifies values of Dynamic Block properties using a supplied association list.
;; blk - [vla] VLA Dynamic Block Reference object
;; lst - [lst] Association list of (( . ) ... )
;; Returns: nil

(defun LM:setdynprops ( blk lst / itm )
    (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst))
    (foreach x (vlax-invoke blk 'getdynamicblockproperties)
        (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
            (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))))))

;; Set Attribute Values  -  Lee Mac
;; Sets attributes with tags found in the association list to their associated values.
;; blk - [vla] VLA Block Reference Object
;; lst - [lst] Association list of (( . ) ... )
;; Returns: nil

(defun LM:vl-setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm)))))

 

 

0 Likes
Accepted solutions (1)
1,057 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Mentor
Mentor
Accepted solution

@emreakyazici ,

 

Try updating this portion of your code:

  (setq dynprops (list

		   (cons "Angle1" ang1) ; POSSIBLE ERROR POINT!!
		   '("Position1 X" . 10)			; all dyn-values are numbers - without ""
		   '("Position1 Y" . 10)

		   '("Position2 X" . 20)			; all dyn-values are numbers - without ""
		   '("Position2 Y" . 20)

		   '("Position3 X" . 30)			; all dyn-values are numbers - without ""
		   '("Position3 Y" . 30)

		   '("Position4 X" . 40)			; all dyn-values are numbers - without ""
		   '("Position4 Y" . 40)

		   )

 

Your error was happening because you are "quoting" which does not evaluate the 'ang1' variable. To prevent this in the future you can read the differences here:

http://www.lee-mac.com/quote.html

 

Best,

~DD

0 Likes
Message 3 of 5

emreakyazici
Advocate
Advocate

Oh, thank you so much. It's working.

 

If you don't mind, I have a second question. I have a basic second command which creates lines according to insert point.

 

How can I merge these commands, according to insert point and previous LISP? I tried a little but, couldn't manage.

 

 

(defun c:S55 ( / p1 p2 p3 p4)
(setq p1 (getpoint "\nLine origin: "))
(setq p2 (mapcar '+ p1 '(5 5 0)))
(setq p3 (mapcar '+ p1 '(0 -5 0)))


(setq p4 (mapcar '+ p3 '(60 0 0)))
(setq p5 (mapcar '+ p3 '(-60 0 0)))



(entmakex (list '(0 . "LINE")(cons 10 p1)(cons 11 p3)))
(entmakex (list '(0 . "LINE")(cons 10 p3)(cons 11 p4)))
(entmakex (list '(0 . "LINE")(cons 10 p3)(cons 11 p5)))

)

 

0 Likes
Message 4 of 5

CodeDing
Mentor
Mentor

@emreakyazici ,

 

Are you trying to merge your S55 command with the INS123 command? Is that what you mean?

0 Likes
Message 5 of 5

emreakyazici
Advocate
Advocate

Yes. I need to add properly S55 to INS123, briefly.

0 Likes