TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Columbia on September 27, 2005, 03:56:35 PM

Title: vla-AddItems Help...
Post 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:
Code: [Select]
(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?
Title: Re: vla-AddItems Help...
Post by: JohnK on September 27, 2005, 04:08:13 PM
Do you need to do it with VL? Could you do it with just plain ol Autolisp?
Title: Re: vla-AddItems Help...
Post by: Columbia on September 27, 2005, 04:09:39 PM
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...
Title: Re: vla-AddItems Help...
Post by: JohnK on September 27, 2005, 04:14:37 PM
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.
Title: Re: vla-AddItems Help...
Post by: Kerry on September 27, 2005, 04:15:14 PM
Quote
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.




Title: Re: vla-AddItems Help...
Post by: Columbia on September 27, 2005, 04:18:36 PM
Quote
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.
Title: Re: vla-AddItems Help...
Post by: Kerry on September 27, 2005, 04:23:55 PM
So you expect to call a VBA routine from a Lisp reactor callback, and then return to Vlisp. .. and maintain synchronicity. ?
Title: Re: vla-AddItems Help...
Post by: Kerry on September 27, 2005, 04:26:11 PM
Which functionality do you want from the VBA Form that you cant get from DCL [ or objectDCL ] ?
Title: Re: vla-AddItems Help...
Post by: Columbia on September 27, 2005, 04:27:09 PM
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.
Title: Re: vla-AddItems Help...
Post by: Columbia on September 27, 2005, 04:29:34 PM
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.
Title: Re: vla-AddItems Help...
Post by: MP on September 27, 2005, 04:30:29 PM
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

...
Title: Re: vla-AddItems Help...
Post by: Jeff_M on September 27, 2005, 05:14:55 PM
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
Title: Re: vla-AddItems Help...
Post by: Tom on September 27, 2005, 05:25:39 PM
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)
  )
)

Title: Re: vla-AddItems Help...
Post by: Jeff_M on September 27, 2005, 05:36:46 PM
And to create a named SS from a lisp SS:
Code: [Select]
;;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))
  )
Title: Re: vla-AddItems Help...
Post by: Kerry on September 27, 2005, 05:37:35 PM
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.
Title: Re: vla-AddItems Help...
Post by: Columbia on October 03, 2005, 10:37:01 AM
Thanks, Jeff_M!  That did the trick!