I get the following error in the attached code. It sure looks to me like it should work. Any suggestions welcome:
Error:(vl-catch-all-error-message obj3)
"lisp value has no coercion to VARIANT with this type: #<variant 8197 ...>"\
The error location is marked in the code:
(defun c:test()
(setq
ent1 (entsel "\nFirst tag: ")
ent2 (entsel "\nSecond tag: ")
)
(SwapTag (car ent1) (car ent2) AttMap)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Procedure: Swaptag ;;;
;;; Purpose: Replace an insertion of Ent1 with an insertion of Ent2 while maintaining;;;
;;; attribute values. ;;;
;;; Arguments: ent1 - ename, the entity name for the tag to be replaced ;;;
;;; ent2 - ename, the entity name for the replacement tag ;;;
;;; AttMap - nested list as follows: ;;;
;;; ((ent2tagstring1 . ent1tagstring1) ;;;
;;; (ent2tagstring2 . ent1tagstring2) ;;;
;;; ... ;;;
;;; ) ;;;
;;; If AttMap is nil, then the attributes are mapped 1 to 1, in the ;;;
;;; sequence returned by vla-getattributes ;;;
;;; Returns: Ent2 on success, nil on failure ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SwapTag(ent1 ent2 AttMap / )
(setq
doc (vla-get-activedocument(vlax-get-acad-object))
obj1 (vlax-ename->vla-object ent1)
obj2 (vlax-ename->vla-object ent2)
;;Get the list of attributes for the tag being replaced
Atts1 (vla-getattributes obj1)
Atts1 (vlax-safearray->list (vlax-variant-value atts1))
Atts1 (mapcar
(function(lambda (a) (cons (vla-get-tagstring a) a))
)
Atts1
)
;;Get the list of attributes for the replacement tag
Atts2 (vla-getattributes obj2)
Atts2 (vlax-safearray->list (vlax-variant-value atts2))
Atts2 (mapcar
(function(lambda (a) (cons (vla-get-tagstring a) a))
)
Atts2
)
;;Build the attribute map, or use the one supplied
AttMap (if AttMap
AttMap
(mapcar
(function (lambda (A1 A2)
(cons (car A2) (car A1))
)
)
Atts1
Atts2
)
)
)
;;Insert the replacement tag
(setq
obj1owner (vla-get-ownerid obj1)
;;Insert the replacement block
;;(InsertionPoint, Name, Xscale, Yscale, ZScale, Rotation [, Password])
obj3 (vl-catch-all-apply
'vla-insertblock
(list
(vla-objectidtoobject doc obj1owner)
(vla-get-effectivename obj2)
[color=red](vla-get-insertionpoint obj1);;<<< Error occurs with this value[/color]
(vla-get-xscalefactor obj1)
(vla-get-yscalefactor obj1)
(vla-get-zscalefactor obj1)
(vla-get-rotation obj1)
)
)
Atts3 (vla-getattributes obj3)
Atts3 (vlax-safearray->list (vlax-variant-value atts3))
Atts3 (mapcar
(function(lambda (a) (cons (vla-get-tagstring a) a))
)
Atts3
)
)
;;Transfer the attribute values
(mapcar
(function (lambda (a)
(setq
obj3 (cdr (assoc (car a) Atts3))
obj2 (cdr (assoc (cadr a) Atts2))
)
(vla-put-textstring
obj3
(vla-get-textstring obj2)
)
)
)
AttMap
)
)