Author Topic: Using a Selection Set once in ACAD?  (Read 10597 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Using a Selection Set once in ACAD?
« on: December 20, 2007, 11:01:43 AM »

Hi
I created a Selection Set in VBA called "Im" but my question is once in ACAD, can I still refer to that Sset name?
In other words, In ACAD, if I type Select, I realize that I can type P for Previous but is there anyway to type
Select then Im and have that selection set be recognized in ACAD?

Thanks!

Mark

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Using a Selection Set once in ACAD?
« Reply #1 on: December 20, 2007, 11:22:44 AM »
I don't believe so.

I've written a hack (and it was ugly) to be able to use a selection set from a routine as 'previous' after the routine finished writing. I don't have it off had, it may be at the swap somewheres. It involved writing bogus xdata to the objects.

ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #2 on: December 20, 2007, 11:30:15 AM »

Yikes! Sounds scary :)

This is one of those things in ACAD that make absolutely no sense.
We can create all these Selection Sets and filters etc. in VBA however, once we get to ACAD, we can not refer to them by name anymore? That is silly.

I wonder about the group method? I haven't looked at it closely yet.
Also, in ACAD, we can create filters and refer to them by name but I am not sure that we can create one in VBA and then be able to refer to it in ACAD.

There is something I "may" be able to do, but should not have to.

I can possibly send (using a function I have) The ACAD Variable Sset to LISP, then "may be" it (the selection set)will then be recognized at least by using !Sset in ACAD, hummmm.

There must be a way to refer to the named sset in ACAD

Mark

ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #3 on: December 20, 2007, 11:31:57 AM »

Quote
I can possibly send (using a function I have) The ACAD Variable Sset to LISP, then "may be" it (the selection set)will then be recognized at least by using !Sset in ACAD, hummmm.

I meant to say The VBA Variable Sset to LISP

OMG!  :lol:

Mark

Glenn R

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #4 on: December 20, 2007, 05:14:59 PM »

Hi
I created a Selection Set in VBA called "Im" but my question is once in ACAD, can I still refer to that Sset name?
In other words, In ACAD, if I type Select, I realize that I can type P for Previous but is there anyway to type
Select then Im and have that selection set be recognized in ACAD?

Thanks!

Mark

As I and others said in this thread, for all intents and purposes, no.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Using a Selection Set once in ACAD?
« Reply #5 on: December 20, 2007, 06:05:46 PM »
Although with a wee bit of lisp it can be done.....
Quote from: CommandLine
Command: select

Select objects: (getvbss "Im")
<Selection set: 18>
7 found

Select objects:
Command:
Here's the lisp:
Code: [Select]
(defun getVBss (name / ss ssnew)
  (if (not (vl-catch-all-error-p
     (vl-catch-all-apply
       '(lambda ()
  (setq ss (vla-item
     (vla-get-selectionsets
       (vla-get-activedocument
(vlax-get-acad-object)
       )
     )
     name
   )
  )
)
     )
   )
      )
    (progn
      (setq ssnew (ssadd))
      (vlax-for ent ss
(ssadd (vlax-vla-object->ename ent) ssnew)
      )
    )
  )
  ssnew
)
Remember that named SS's are case-sensitive.

ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #6 on: December 20, 2007, 06:41:15 PM »

Jeff

Thanks for the code!
I need to look at it still

Do I have to put that into VLISP and save it to a specific file type?

Hey, do you think it is possible to put that code right into VBA?

With a reference to VLISP
Code: [Select]
Set VL = CreateObject(VL.Application.16)

I'm going to say, yes we can.
Actually this may even work well as a function in VBA

What do you think?

Mark

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Using a Selection Set once in ACAD?
« Reply #7 on: December 20, 2007, 07:30:57 PM »
First, your welcome.

However, I think mixing lisp and VBA is borderline nutzoid..... the VLAX.CLS sortof exemplifies that.

Yes, I showed a way of converting an ActiveX SS to an ename based SS, but it also means that Glenn was right. "For all intents and purposes, no." You cannot get it in Acad as you asked, you need some lisp-trickery to do so.

I would just save it as "getVBss.lsp" and load it via your VBA macro or the Toolbar button you start the macro with, or any number of things before I'd add the lisp code into the DVB.

Dare I ask what the net result of all this is? IOW, why not keep your code in VBA? (Which, btw, is what Glenn has tried to guide you towards.)

ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #8 on: December 21, 2007, 11:39:36 AM »



Quote
First, your welcome.

However, I think mixing lisp and VBA is borderline nutzoid..... the VLAX.CLS sortof exemplifies that.

Yes, I showed a way of converting an ActiveX SS to an ename based SS, but it also means that Glenn was right. "For all intents and purposes, no." You cannot get it in Acad as you asked, you need some lisp-trickery to do so.

I would just save it as "getVBss.lsp" and load it via your VBA macro or the Toolbar button you start the macro with, or any number of things before I'd add the lisp code into the DVB.

Dare I ask what the net result of all this is? IOW, why not keep your code in VBA? (Which, btw, is what Glenn has tried to guide you towards.)

Hi Jeff,

Thanks again! Of course you can ask me; you can ask anything.
If someone just says don't do it, it's crazy without giving some examples, then it will not always deter them.

As to that VLAX Class, I did not use it, nor would I
However, the 2 narrowed down functions that I posted have worked very well for me.
I was able to use the getfiled and setq method with LISP along with my VBA code and I have encountered absolutely 0 problems.

Yes! I do have a version using The Open FIle Dialog method but that is a lot of code for such little return such as prompting the user with a dialog box to pick one file. Of course, I'd rather do it all in VBA when possible and it makes sense. I also use VBScripting code a lot for other reasons but "may be" that is OK; it seems to work fine.

Thank you again for the code; I will do as you suggested; I will make a seperate routine and load it with THe VBA project.
I was planning on coming in this morning and trying it, then all this. OMG!

Jeff, I not the most experienced programmer and I simply asked if it could be incorporated and I do ppreciatte your answer that it would be too difficult and not make sense. I simply though because we can connect to THe VLISP Type Library, that it may be possible; I did not realize I was being nutzoid by asking that, so I apologize.  Therefore, I will not try it and I will go try you .lsp routine.

Thank you

Mark



ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #9 on: December 21, 2007, 12:13:30 PM »

Jeff

I just tried the lisp routine; it is working great!

Thank you again!

Mark

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Using a Selection Set once in ACAD?
« Reply #10 on: December 21, 2007, 01:02:56 PM »
Mark,
While it had nothing to do with selection sets, it had everything to do with the fact you are trying to pass lisp and VBA variables back & forth between the 2. Again, he was trying to steer you away from the inevitable head banging that will occur (is occurring?).

In that thread that Glenn mentioned, you say you don't like the FileOpenDialog code because it's so long. Thing is, it's already written so it's not like you have to rewrite it every time it's used. The same, exact, thing holds true when you use the VL.Application. THAT code is probably much larger than the one you are trying not to use. No, you don't see it, but it's there just the same. So instead of adding one small bit of code to your macro, you reference one which is much larger.

Does that make sense?  Please note I'm not trying to lambast you for doing it the way you have. I'm just trying to explain why others have tried steering you in other directions. Many of them, myself included, have been down the road you are on.

The following should have been placed in that other thread, but I'm typing now so here it is. :-)

And, FWIW, I DO use the VLAX.CLS in all of it's ugliness, in association with another one Frank O put together, the CURVE.CLS, which exposes the (vlax-curve-*) lisp functions to VBA. Sure they are ugly, but they are tools that worked to get the job done without having to reinvent the wheel. However, if there was a VBA specific way to get Curve data without the VLAX.CLS & CURVE.CLS, I sure would've jumped at the chance to use it.

ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #11 on: December 21, 2007, 01:18:55 PM »
Yes, that's cool Jeff! And it makes total sense.
So, at the end of the function, I did set
VL Sym to Nothing and
VL to Nothing.

Even with that, you would say it is still a very bad idea?
I just simply grabbed a string variable set in the getfiled maco and used it in VBA; it seemed harmeless; it was a lousy string of text, no objects involved.

I do realize that we do have to seperate what is cool from what is realistic.

Do these same sort of problems occur from referencing other Type libraries such as Excel or WSH?
I have not encountered any problems, but then again, they are both VB Enabled; may be that is the difference?

I bascially copy and pasted a very long version of THe OpenFile Dialog and made it work
I suppose if I muffled through it, I could shorten it to just what I need?

Thanks Jeff!

Mark



ML

  • Guest
Re: Using a Selection Set once in ACAD?
« Reply #12 on: December 21, 2007, 01:48:41 PM »

Thanks Mark!
I do appreciate that
I have worked very hard to get good at VBA (as others have, I'm sure) and I feel like I am finally starting to get.
This forum and many members of it have been a real blessing to me.
I totally appreciate and respect everyone's knowledge.
I am a very big proponent of not what we are trying to explain but how we explain it.
If anyone has seen my posts; every single post I leave and reply to, I say
Thanks
Mark

That is because I do appreciate (despite whta other's may believe) the fact that people do stop their busy day to try to help me.


I say that we take the original psot question and Jeff's nice piece of code (for other users) to take advantage of; then delete this whole post.
Can we do that?

Thanks Mark!

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Using a Selection Set once in ACAD?
« Reply #13 on: December 21, 2007, 01:52:52 PM »
I bascially copy and pasted a very long version of THe OpenFile Dialog and made it work
I suppose if I muffled through it, I could shorten it to just what I need?
You're welcome Mark.

Why worry about shortening it up? Just use the parts you need and forget the rest is there. If you save (export)the OpenFileDialog (I don't know what version you found of the many that are available out there) to a BAS or CLS file (again, depending on what you found) then you can import it to any future DVB and use it without having to fiddle with "does it do this or that". Just import it, use it and move on.

As for referencing other API's. IMHO, and I am far from an expert on this, you should only reference other API's when you MUST access those objects available in that API. If working with an Excel spreadsheet, use the Excel library. If needing to use the Windows Scripting Host, use it. But I notice you didn't even comment about my suggestion of using Excel's FileOpen method. Why? Probably because you realize that that would add overhead to the macro that is really not necessary. The same holds for the use of (getfiled) in VBA......you are accessing the VL.Application, which access the result of (getfiled) which accesses the Win32 API (this last is a guess....I have no inside knowledge of how Acad actually does this). With VBA you can access the Win32 API directly so why add the 2 intermediate layers to that. Sure it more code, for you, sure it's more difficult to understad (I still don't follow a lot of it), but it will run quicker, not be succeptable to Autodesk changes in their code, and you'll learn something that may benefit you for something bigger down the road.

Now, back to why you need the VBA selection set in Acad. :-) Maybe we can work around that, too, without resorting to lisp.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Using a Selection Set once in ACAD?
« Reply #14 on: December 21, 2007, 01:57:21 PM »
I say that we take the original psot question and Jeff's nice piece of code (for other users) to take advantage of; then delete this whole post.

I did some "house cleaning", how' that?
TheSwamp.org  (serving the CAD community since 2003)