Author Topic: vla-AddItems Help...  (Read 5629 times)

0 Members and 1 Guest are viewing this topic.

Columbia

  • Guest
vla-AddItems Help...
« 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?

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: vla-AddItems Help...
« Reply #1 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?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Columbia

  • Guest
Re: vla-AddItems Help...
« Reply #2 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...

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: vla-AddItems Help...
« Reply #3 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.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-AddItems Help...
« Reply #4 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.




kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Columbia

  • Guest
Re: vla-AddItems Help...
« Reply #5 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-AddItems Help...
« Reply #6 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. ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-AddItems Help...
« Reply #7 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 ] ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Columbia

  • Guest
Re: vla-AddItems Help...
« Reply #8 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.

Columbia

  • Guest
Re: vla-AddItems Help...
« Reply #9 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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vla-AddItems Help...
« Reply #10 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

...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-AddItems Help...
« Reply #11 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

Tom

  • Guest
Re: vla-AddItems Help...
« Reply #12 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)
  )
)


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-AddItems Help...
« Reply #13 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))
  )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-AddItems Help...
« Reply #14 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.
« Last Edit: September 27, 2005, 06:05:54 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Columbia

  • Guest
Re: vla-AddItems Help...
« Reply #15 on: October 03, 2005, 10:37:01 AM »
Thanks, Jeff_M!  That did the trick!