Results 1 to 8 of 8

Thread: Making a SelectionSet active in GUI

  1. #1
    Member
    Join Date
    2011-11
    Posts
    2
    Login to Give a bone
    0

    Default Making a SelectionSet active in GUI

    Hello,

    I'm trying to create a selectionset in VBA that highlights blocks that are not close enough to another block, all of which I have done successfully.

    The problem is I want the blocks to be an active selection after the code runs, as if the user had just selected all of them with the mouse, with properties showing up in the properties window. Setting highlight True does not do this.

    Any help would be greatly appreciated.

    I am using AutoCAD 2006 (I know it's old, but it's what I have).

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    Just a hint:
    Try search for ThisDrawing.PickFirstSelectionSet object in the Help file

    ~'J'~

  3. #3
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    560
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    I also can't find to do it in a direct way since ActiveSelection is read-only. But certainly a workaround can achieve the task at hand.

    Code:
    ObjCount = ThisDrawing.SelectionSets("yourSelectionSetName").Count
    ReDim selObjects(0 To ObjCount - 1) As AcadEntity
    
    For i = 0 To ObjCount - 1
        Set selObjects(i) = ThisDrawing.SelectionSets("yourSelectionSetName").Item(i)
    Next
    
    Dim grpTemp As AcadGroup
    Set grpTemp = ThisDrawing.Groups.Add("TEMPGROUP")
    grpTemp.AppendItems selObjects
    
    ThisDrawing.SendCommand "Select" & vbCr & "g" & vbCr & "TEMPGROUP" & vbCr & vbCr
    grpTemp.Delete
    I made a temporary group and select it via SendCommand, then delete the group afterwards.

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    No wonder I skipped VBA for LISP (and am now jumping into .NET), the above VBA code as compared to:

    Code:
    (sssetfirst nil YourSelectionSet)
    LoL... More on SSSETFIRST function.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    560
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    Too bad I skipped Lisp for VBA.

    It could have been
    Code:
    ThisDrawing.SendCommand "Select" & vbCr & "!YourSelectionSet" & vbCr & vbCr
    But unfortunately the "!" prefix for selection sets only work for sets created via Lisp.

  6. #6
    Member
    Join Date
    2011-11
    Posts
    2
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    Thanks for the advice.

    However, these options don't seem to be working as I had hoped. What I really want is a quick select done through VBA.

    pickfirstselectionset is read-only, so I can't add the VBA created selection set to it.

    Arsheil88, your code does seem to select the block I want, but is unselected when the code finishes.

    I'm still at the point of trying to get VBA to put a selection set as the active Pickfirstselectionset, while ending the VBA code and handing control back to the GUI.

    The QSELECT window has an option to 'Append to current selection set'. Is there a way to:
    -set the current selection set to the one I created
    -run QSELECT transparently from VBA
    -have QSELECT do a search that finds nothing, and append it to current selection?

    I've attached roughed up code for what I want below. It's actually part of a much larger piece of code, so I've tried to pull out what is applicable. It's probably pretty inefficient, so suggestions on that too would be helpful. I'm using 2 objEnts arrays so I can pass only fixed number of entities to the selectionset once I find them. I figure there is an easy way to do this, and I just haven't found it yet.

    Thanks to everyone for their help!



    Code:
    Sub SelectCircle()
        Dim objSS As AcadSelectionSet
        Dim objSS1 As AcadSelectionSet
        Dim objEnts1(50) As AcadEntity 'fixed array to find all the blocks in the drawing
        Dim objEnts() As AcadEntity 'dynamic array to be resized  to the actual number of blocks found
        
        Dim ent As AcadEntity 
        Dim k As Integer 'counter to keep track of number of blocks
        
        For Each objSS1 In ThisDrawing.SelectionSets  'check to see if the selectionset already exists
            If objSS1.Name = "Blocks" Then 'if it does exist, set the working selection set equal to it.
                Set objSS = objSS1
                Exit For
            End If
        Next
        
        If objSS Is Nothing Then 'if it is not found, create it
            Set objSS = ThisDrawing.SelectionSets.Add("Blocks")
        End If
        
        objSS.Clear 'clear any previous contents of selection set
        k = 0 'set counter
        For Each ent In ThisDrawing.ModelSpace 'get all objects in drawing
                   
            If ent.ObjectName = "AcDbBlockReference" Then 'check if object is block
                Set objEnts1(k) = ent
                k = k + 1
            End If
            
        Next ent
        
        ReDim objEnts(k - 1) As AcadEntity
        For i = 0 To (k - 1)
            Set objEnts(i) = objEnts1(i)
        Next i
           
        objSS.AddItems objEnts
        
    End Sub

  7. #7
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    560
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    Quote Originally Posted by ncraig122139 View Post
    Thanks for the advice.

    ... your code does seem to select the block I want, but is unselected when the code finishes.
    There must be something that unselects it in your code because it's running fine on my end. Perhaps a Thisdrawing.Regen statement after select command.
    ---
    1. Directly, No, maybe because its read only. Indirectly, yes. My workaround will select it therefore it became the active selection set.
    2. Probably. Why not use filters in Selection sets? Similar to QSelect features. (see sample code below.)
    3. Why append if there's Nothing found?

    By using Filters, your code can be simplified in this way.
    Code:
    Sub SelectBlocks()
    
    Dim sSetBlocks As AcadSelectionSet
    
    On Error Resume Next
    Set sSetBlocks = ThisDrawing.SelectionSets.Add("SSET_BLOCKS")
        If Err Then
            Set sSetBlocks = ThisDrawing.SelectionSets("SSET_BLOCKS")
            sSetBlocks.Clear
         End If   
        Dim FilterType(0) As Integer
        Dim FilterData(0) As Variant
            FilterType(0) = 0
            FilterData(0) = "Insert"
    
    sSetBlocks.Select acSelectionSetAll, , , FilterType, FilterData
    
    End Sub
    This will be faster because there will be no longer a need to iterate all objects and test if it is a block.
    Last edited by arshiel88; 2012-03-14 at 10:56 AM.

  8. #8
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Making a SelectionSet active in GUI

    Read this thread. Don't forget you can search this forum for solutions. There's no need to modify the pfss. You can create up to 255 ss's. Use ss filtering instead of iterating ms or ps. The return is an ss, so you don't need the temp ss's.
    C:> ED WORKING....

Similar Threads

  1. VLisp and Excel: Making Certain Sheet Active
    By freedomonek in forum AutoLISP
    Replies: 7
    Last Post: 2015-12-26, 06:26 PM
  2. Sort Selectionset by X coord
    By ccowgill in forum AutoLISP
    Replies: 10
    Last Post: 2012-03-09, 03:41 PM
  3. SelectionSet are KILLING me
    By jason907238 in forum VBA/COM Interop
    Replies: 22
    Last Post: 2005-07-12, 07:48 PM
  4. Making selected item's workset active
    By narlee in forum Revit - Worksharing/Worksets/Revit Server
    Replies: 5
    Last Post: 2005-06-27, 07:11 PM
  5. SelectionSet Error
    By jason907238 in forum VBA/COM Interop
    Replies: 4
    Last Post: 2005-06-21, 03:18 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
  •