See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: ActiveX Selection

  1. #1
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,114
    Login to Give a bone
    1

    Default ActiveX Selection

    I was playing around with ActiveX selection sets and couldn't find a comprehensive library.

    I believe these will work.

    Let me know if you find any bugs.

    The list of dotted pairs is the same as ssget filters.

    These are the modes

    acSelectionSetAll
    acSelectionSetCrossing
    acSelectionSetLast
    acSelectionSetWindow
    acSelectionSetPrevious

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2024 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Abstract: There are two ways of creating selection sets in AutoCAD. One is the ssget expression and
    ; the other involves the selectionsets collection in ActiveX. 
    ; This library uses the ActiveX method to return a list of objects (easier to manipulate than a collection)
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List 
    ;___________________________________________________________________________________________________________|
    
    ;* (ActiveXSelect intMode lstPoint1 lstPoint2 lstOfDottedPairs)
    ;* Function to create an activex selection set and return a list of vla-objects
    
    ;* (SelectionSafeArray intDataType lstData)
    ;* Function to create a safearray from a list of items and object type
    
    ;* (SelectAll lstOfDottedPairs)
    ;* Function to create an activex selection set of all with filter and return a list of vla-objects
    
    ;* (SelectCrossing lstPoint1 lstPoint2 lstOfDottedPairs)
    ;* Function to create an activex selection set of crossing with filter and return a list of vla-objects
    
    ;* (SelectLast)
    ;* Function to create an activex selection set of last object and return a list of a vla-object
    
    ;* (SelectPrevious lstOfDottedPairs)
    ;* Function to create an activex selection set of previous objects and return a list of a vla-objects
    
    ;* (SelectWindow lstPoint1 lstPoint2 lstOfDottedPairs)
    ;* Function to create an activex selection set of window with filter and return a list of vla-objects
    
    ;* (ErrorTrap symFunction)
    ;* Function to trap errors
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create an activex selection set and return a list of vla-objects
    ;___________________________________________________________________________________________________________|
    
    (defun ActiveXSelect  (intMode lstPoint1 lstPoint2 lstOfDottedPairs
                  / lstSelectionSet
                    intMode
                    lstDXFCodes
                    lstDXFValues
                    objActiveDocument
                    objApplication
                    objItem
                    objSelectionSet
                    objSelectionSets
                    safDataCodes
                    safDataCodes                    
                   )
     (if (and (member intMode (list acSelectionSetAll
                                    acSelectionSetCrossing 
                                    acSelectionSetLast
                                    acSelectionSetWindow                                
                                    acSelectionSetPrevious
                              )
              )
              (setq objApplication    (vlax-get-acad-object))
              (setq objActiveDocument (vla-get-ActiveDocument objApplication))
              (setq objSelectionSets  (vla-get-SelectionSets objActiveDocument)) 
              (or (and (setq objSelectionSet (Errortrap '(vlax-invoke objSelectionSets "Item" "SSET")))
                       (or (ErrorTrap '(vlax-invoke objSelectionSet "Clear"))
                           T
                       )
                  )
                  (setq objSelectionSet (vlax-invoke objSelectionSets "Add" "SSET"))
              )
              (or lstOfDottedPairs
                  (setq lstOfDottedPairs (list (cons 0 "*")))
              )
              (setq lstDXFCodes  (mapcar 'car lstOfDottedPairs))
              (setq safDXFCodes  (SelectionSafeArray vlax-vbInteger lstDXFCodes))
              (setq lstDXFValues (mapcar 'cdr lstOfDottedPairs))
              (setq safDXFValues  (SelectionSafeArray vlax-vbVariant lstDXFValues))          
         )
      (progn
       (ErrorTrap '(vla-Select objSelectionSet intMode lstPoint1 lstPoint2 safDXFCodes safDXFValues))
       (vlax-for objItem objSelectionSet
        (setq lstSelectionSet (cons objItem lstSelectionSet))
       )
       (ErrorTrap '(vla-Delete objSelectionSet))
      )
     )
     (Reverse lstSelectionSet)
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create a safearray from a list of items and object type
    ;___________________________________________________________________________________________________________|
    
    (defun SelectionSafeArray (intDataType lstData)
     (if (and (setq intLength (length lstData))
              (setq safData   (vlax-make-safearray intDataType (cons 0 (1- intLength))))          
         )
      (ErrorTrap '(vlax-safearray-fill safData lstData))
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create an activex selection set of all with filter and return a list of vla-objects
    ;___________________________________________________________________________________________________________|
    
    (defun SelectAll (lstOfDottedPairs)
     (ActiveXSelect acSelectionSetAll nil nil lstOfDottedPairs)
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create an activex selection set of crossing with filter and return a list of vla-objects
    ;___________________________________________________________________________________________________________|
    
    (defun SelectCrossing (lstPoint1 lstPoint2 lstOfDottedPairs / safPoint1 safPoint2 )
     (if (and (setq safPoint1 (SelectionSafeArray vlax-vbDouble lstPoint1))
              (setq safPoint2 (SelectionSafeArray vlax-vbDouble lstPoint2)) 
         )
      (ActiveXSelect acSelectionSetCrossing safPoint1 safPoint2 lstOfDottedPairs)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create an activex selection set of last object and return a list of a vla-object
    ;___________________________________________________________________________________________________________|
    
    (defun SelectLast ()
     (ActiveXSelect acSelectionSetLast nil nil nil)
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create an activex selection set of previous objects and return a list of a vla-objects
    ;___________________________________________________________________________________________________________|
    
    (defun SelectPrevious (lstOfDottedPairs)
     (ActiveXSelect acSelectionSetPrevious nil nil lstOfDottedPairs)
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create an activex selection set of window with filter and return a list of vla-objects
    ;___________________________________________________________________________________________________________|
    
    (defun SelectWindow (lstPoint1 lstPoint2 lstOfDottedPairs)
     (if (and (setq safPoint1 (SelectionSafeArray vlax-vbDouble lstPoint1))
              (setq safPoint2 (SelectionSafeArray vlax-vbDouble lstPoint2)) 
         )
      (ActiveXSelect acSelectionSetWindow safPoint1 safPoint2 lstOfDottedPairs)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to trap errors
    ;___________________________________________________________________________________________________________|
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (vl-catch-all-apply '(lambda (X)(set X (eval symFunction)))
                               (list 'result)
          )
         )
      nil    
      Result
     )
    )
    
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,114
    Login to Give a bone
    0

    Default Re: ActiveX Selection

    The nice thing about activex selection sets (as I understand them) is they can have more than 32k entities.

    ssname requires an integer.

    vlax for and foreach can handle more than 32k entities.

    P=
    AutomateCAD

  3. #3
    Member
    Join Date
    2006-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: ActiveX Selection

    Bonjour Peter

    Why do you write that : "they can have more than 32k entities"
    With (ssget) there is no limit of number of entities, is there ?
    I have already done ssget with more entities than that...
    Can you tell more ? Please.

    Amicalement
    Last edited by did-ave; 2024-05-18 at 02:42 PM.

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,114
    Login to Give a bone
    0

    Default Re: ActiveX Selection

    My bad, Maybe there isn't. I just tested it and you are right.

    also I had really never bumped into that limit in my work.

    I remember trying some code (a long time ago) and it choked on large selection sets.

    The command pipe is very fast and ssget is also fast.

    In reactors though the command pipe is usually avoided.

    anyways the code is academic.

    P=
    AutomateCAD

  5. #5
    Member
    Join Date
    2006-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: ActiveX Selection

    Bonjour @peter

    I hope you understand my way of answering, I seek the truth, not sterile polemics.

    I have done tests and I find the following results:

    Test1 : 13 seconds
    Test2 : 30 seconds

    Test1 with SSGET, Test2 with your proposition

    It should be noted that my PC is obsolete, but the comparison is correct, it is the same selection of 1,200,000 points on a single layer.

    Do you find the same time difference?

    Amicalement

    (defun c:test1 ( / time1 time2)
    (setq time1 (getvar "millisecs"))
    (setq ss1 (ssget "_x" (list (cons 0 "POINT"))))
    (setq time2 (getvar "millisecs"))
    (prompt (itoa (/ (- time2 time1) 1000)))
    (princ)
    )
    (defun c:test2 ( / time1 time2)
    (setq time1 (getvar "millisecs"))
    (setq ss2 (SelectAll (list (cons 0 "POINT"))))
    (setq time2 (getvar "millisecs"))
    (prompt (itoa (/ (- time2 time1) 1000)))
    (princ)
    )

  6. #6
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,114
    Login to Give a bone
    0

    Default Re: ActiveX Selection

    In this code I convert the collection to a list.

    I played around with it and found that it was much faster when it just returned the selectionset collection.

    I think it is comparable to ssget that way.
    AutomateCAD

Similar Threads

  1. ActiveX API - Dynamic Graphic Manipulation
    By ntaylor in forum API Wish List
    Replies: 8
    Last Post: 2004-11-29, 12:02 AM
  2. ActiveX API - Layer Filter Manipulation
    By ntaylor in forum API Wish List
    Replies: 6
    Last Post: 2004-09-08, 10:58 PM
  3. Replies: 4
    Last Post: 2004-07-24, 04:18 AM
  4. Purge a particular item by using ActiveX method
    By rajat126 in forum AutoLISP
    Replies: 1
    Last Post: 2004-06-19, 06:42 PM
  5. "AngleToReal" in ActiveX method
    By rajat126 in forum AutoLISP
    Replies: 1
    Last Post: 2004-06-15, 01:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •