SelectionSet VBA -> VLisp

Discussion in 'AutoCAD' started by Maksim Sestic, Dec 13, 2004.

  1. Dear Friends,

    This is not strictly VBA-related question. I have problems generating AcadSelectionSet via VBA and then passing it to VLisp. Recently Jeff Mishler posted a code to this NG solving the same problem, but his solution is not "standardized" enough... My VLISP programming knowledge is _poor_ and I just can't convert VLA-Object (resulting SelectionSet) to Ename. Please see an example below...

    A VBA function code snippet (Class named MyClass):

    'This function passes a SelectionSet to VLISP
    'Result is of type Object to avoid eventual type-conflicts
    Public Function SelSetToLisp() As Object
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Varian
    'CreateSelectionSet creates SelSet neverthless if it exists or not
    Set SelSetToLisp = CreateSelectionSet("TMP_SELSET")
    FilterType(0) = 1001: FilterData(0) = "MYAPP"
    'Here it is - ready to go (to VLISP)...
    SelSetToLisp.Select acSelectionSetAll, , , FilterType, FilterData
    End Function

    VLISP usage of MyClass.SelSetToLisp() function:

    (defun C:TEST ()
    (vl-load-com)
    ;;Create instance of a Class object
    (setq clsMyClass (vlax-create-object "MYDLL.MyClass"))
    ;;Store resulting SelectionSet to variable named ResultVBA
    (setq ResultVBA (vlax-invoke-method clsMyClass 'SelSetToLisp))
    ;;TRICKY PART - Convert resulting VLA-object to Ename typed one
    ;;This is the line where program fails...
    (setq ResultLSP (vlax-vla-object->ename ResultVBA))
    )

    All I want to get is Ename SelectionSet, just like SSGET does. Is there any example of how to convert the VLA-based SelectionSet to Ename-based one? I want to avoid (ssget "P") and calling a named SelSet from VLisp as it's name may vary (Jeff's approach).

    Thanks,
    Maksim Sestic
     
    Maksim Sestic, Dec 13, 2004
    #1
  2. Maksim Sestic

    Jeff Mishler Guest

    OK, Maksim, it took me a few times reading this before it dawned on me what
    you were trying to do. Sorry, just kind of dense lately.....

    I think this is what you want:

    (setq resultLSP (ssadd))
    (vlax-for ent resultVBA
    (ssadd (vlax-vla-object->ename ent) resultLSP)
    )


    --
    Jeff
    check out www.cadvault.com
    Dear Friends,
    <snip>
    VLISP usage of MyClass.SelSetToLisp() function:

    (defun C:TEST ()
    (vl-load-com)
    ;;Create instance of a Class object
    (setq clsMyClass (vlax-create-object "MYDLL.MyClass"))
    ;;Store resulting SelectionSet to variable named ResultVBA
    (setq ResultVBA (vlax-invoke-method clsMyClass 'SelSetToLisp))
    ;;TRICKY PART - Convert resulting VLA-object to Ename typed one
    ;;This is the line where program fails...
    (setq ResultLSP (vlax-vla-object->ename ResultVBA))
    )

    All I want to get is Ename SelectionSet, just like SSGET does. Is there any
    example of how to convert the VLA-based SelectionSet to Ename-based one? I
    want to avoid (ssget "P") and calling a named SelSet from VLisp as it's name
    may vary (Jeff's approach).

    Thanks,
    Maksim Sestic
     
    Jeff Mishler, Dec 14, 2004
    #2
  3. Thanks a lot, Jeff. It's my fault, anyway - I just realized my posting was
    few Kbs in size... Hmm... Now I understand why my approach failed - Lisp
    treats SelectionSet as a list of Enames, and can't be directly converted
    from VLA-typed object via vlax-vla-object->ename.

    Regards,
    Maksim Sestic
     
    Maksim Sestic, Dec 15, 2004
    #3
  4. Have you considered making a temporary GROUP from VBA, then accessing
    that from the Lisp side?

    Terry
     
    Terry W. Dotson, Dec 15, 2004
    #4
  5. Terry,

    Similar approach I was on was creating Variant of objects, actually a
    replica of SelectionSet. In that case I might erase SelSet and free up some
    memory. It might work slower (replica generation), but then I'll be able to
    pass a Variant from VB to Lisp. The rest is up to VLisp's conversion from
    VLA-variant objects group to Ename, and it works fine for me. I'm not sure
    about ACAD's memory management (dis)abilities, presumebly it stores named
    SelectionSets in memory until it's either swapped or ACAD sesstion gets
    terminated.

    ACAD's groups get written permanently and remain in DWG until Lisp-side user
    decides to free them up. My VLispers are spoiled and might forget to perform
    memory cleanup routine :)

    Regards,
    Maksim Sestic
     
    Maksim Sestic, Dec 15, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.