Author Topic: problems with the insertion point argument in vla-insertblock  (Read 1921 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
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:
Code: [Select]
(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
    )
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: problems with the insertion point argument in vla-insertblock
« Reply #1 on: April 14, 2008, 10:26:55 AM »
Mike,
At first glance it appears that the arguments are out of order for vla-InsertBlock.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mkweaver

  • Bull Frog
  • Posts: 352
Re: problems with the insertion point argument in vla-insertblock
« Reply #2 on: April 14, 2008, 11:05:11 AM »
Mike,
At first glance it appears that the arguments are out of order for vla-InsertBlock.


That was it.  It's amazing how easy it is to miss the simple things.

Thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: problems with the insertion point argument in vla-insertblock
« Reply #3 on: April 14, 2008, 12:12:02 PM »
Glad I stumbled into it. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.