TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Columbia on September 27, 2005, 03:56:35 PM
-
Here we go experts of the unknown and arcane knowledge of VLISP/VBA named selection sets.
Here's what I want to do:
I want to create a named selection set, then populate it with an entity. That selection set would then be able to be accessed by a VBA routine with a nice pretty front dialog form. I can get AutoCAD to generate the selection set, but I'm having trouble with populating it with AddItems.
Here's my code:
(defun BuildArray (ename / arraySpace sArray)
(setq arraySpace
(vlax-make-safearray
vlax-vbVariant
(cons 0 0)
)
)
(setq sArray (vlax-safearray-fill arraySpace (list (vlax-ename->vla-object ename))))
(vlax-make-variant sArray)
)
(vla-addItems new_selSet (BuildArray enameBlock))
Any ideas folks?
-
Do you need to do it with VL? Could you do it with just plain ol Autolisp?
-
I need to do it in VLISP because standard AutoLISP can not add a "named" selection set that VBA can then access. At least not that I know of...
-
You can name a selection set? (I did not know that.) ...anyways; let me play arround a bit and ill see what i come up with.
-
nice pretty front dialog form.
pretty is as pretty does. [/gump]
You CAN do selections in VBA you know, or do you just want the 'pretty' from VBA and the grunt from VLisp.
-
or do you just want the 'pretty' from VBA and the grunt from VLisp
Exactly. To give a little more hint as to a broader view of the whole proggie, this thing is part of an elaborate reactor that VBA just can't do, without being overly complicated.
-
So you expect to call a VBA routine from a Lisp reactor callback, and then return to Vlisp. .. and maintain synchronicity. ?
-
Which functionality do you want from the VBA Form that you cant get from DCL [ or objectDCL ] ?
-
It's a whole lot more likely, then trying calling LISP from VBA and expecting it to happen in the same sequence. I've had a good deal of luck with LISP calling VBA forms from outside of a Reactor, and since the VBA form is outside of the command stream, there shouldn't be too much of a problem.
-
One (of many) features that I want to use VBA for is a multiline edit/textbox. And I don't want to pay out the nose for a license to use (and then half to learn) ObjectDCL. I've looked at ObjectDCL quite a few times, but I just couldn't get too, too excited about it. If I'm going to that trouble, I'll move to ARX once they update to .NET 2003.
-
Not ignoring Kerry's astute comments, but visual lisp gives you theses functions documented in the vba help:
vla-get-activeselectionset
vla-get-gripcolorselected
vla-get-gripcolorunselected
vla-get-objectsortbyselection
vla-get-pickfirstselectionset
vla-get-selection
vla-get-selectionsets
vla-put-gripcolorselected
vla-put-gripcolorunselected
vla-put-objectsortbyselection
vla-select
vla-selectatpoint
vla-selectbypolygon
vla-selectonscreen
...
-
I need to do it in VLISP because standard AutoLISP can not add a "named" selection set that VBA can then access. At least not that I know of...
Note that VBA can access the most recent SS obtained in Lisp with the ActiveSelectionSet property of the Document. To test this in Acad type:
(setq ss (ssget "x"))
(sslength ss)
Note the result. Now go to the VBAIDE and in the Immediate window type:
? thisdrawing.ActiveSelectionSet.Count
Note that both results are the same......
Jeff
-
Check out selectionsetToArray on acadx.com under VisualLisp
(defun selectionsetToArray (ss / c r)
(vl-load-com)
(setq c -1)
(repeat (sslength ss)
(setq r (cons (ssname ss (setq c (1+ c))) r))
)
(setq r (reverse r))
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
(cons 0 (1- (length r)))
)
(mapcar 'vlax-ename->vla-object r)
)
)
-
And to create a named SS from a lisp SS:
;;Must pass a valid standard selection set from lisp, and a name
(defun ss2vbaSS (ss name / doc ssets vlss idx ss_list)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
ssets (vla-get-selectionsets doc)
)
;;check for, and remove if found, SS with supplied name
(vl-catch-all-apply '(lambda ()
(vla-delete (vla-item ssets name))
)
)
(setq vlss (vla-add ssets name)
idx -1)
(while (< (setq idx (1+ idx)) (sslength ss))
(setq ss_list (cons (vlax-ename->vla-object (ssname ss idx)) ss_list))
)
(vlax-invoke vlss 'additems (reverse ss_list))
)
-
or ...
added:
.. though it doesn't use additems [ see Jeff's and Tom's post ] this < the attached > is just another way to make the selection set.
-
Thanks, Jeff_M! That did the trick!