Author Topic: changing elements in a safearray vs. in a list  (Read 10208 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
changing elements in a safearray vs. in a list
« on: September 15, 2003, 04:21:29 PM »
How often have you taken the lower left coordinates and upper right coordinates that you get from autocad and you want to use them to get the other corners. In a list you'd do it something similar to this:
Code: [Select]

(setq ll (list 0.0 0.0 0.0)
      ur (list 9.0 9.0 0.0)
      ul (list (car ll) (cadr ur) (caddr ll))
)

Not bad, but if you have a safearray of these same coordinates, you might think to do something like convert the safearray's to lists, hack them up and re-convert them back to safearray's. Well, instead of doing this, you could use vlax-safearray-get-element and safearray-put-element. Here is a function I just wrote to do this.
Code: [Select]

;;;-------------------------------------------------------------;
;;;-change elements in a safearray ;
;;; needed: (vla-getBoundingBox ;
;;;     (vlax-ename->vla-object ;
;;;  (car ;
;;;       (entsel) ;
;;;  ) ;
;;;     ) ;
;;;     'll ;
;;;     'ur ;
;;; ) ;returns two safearrays of doubles. ;
;;; usage: (setq upperleft (changeElement ll 1 ur 1)) ;
;;; Returns: A variant 8197, safearray of doubles ;
;;; var and gvar = either ll or ur. Index and gindex = the index;
;;; of the safearray. Similar to car cadr. i.e. 0 = x, 1 = y ;
;;; Of course, a safearray can contain 16 indexes per boundary  ;
;;;-------------------------------------------------------------;
;;; Written by: Daron Rogers ;
;;;-------------------------------------------------------------;
(defun changeElement (var index gvar gindex)
 (vlax-safearray-put-element
      var
      index
      (vlax-safearray-get-element gvar gindex)
 )
     (vlax-make-variant var)
)

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
changing elements in a safearray vs. in a list
« Reply #1 on: September 16, 2003, 07:20:40 AM »
Help me out here Daron. What are all the arguments?

var= variant(?)
index=the number of items in the array(?)
gvar=?
gindex=?

so a sample usage might look like .......... what?
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
changing elements in a safearray vs. in a list
« Reply #2 on: September 16, 2003, 11:03:40 AM »
Sorry for my laziness. Is that better.