Results 1 to 5 of 5

Thread: SelectionSet Error

  1. #1
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default SelectionSet Error

    I have the following Selection Set code. It works great on 3 out of 4 computers. 2 of these computers are identical, but one of these is the one that is giving me the problems. It is not finding the items (some of the time) giving a selection set error. When it does decide to start working, it does not have any problems. I can and have made some changes so that the user does not see a error pop up, it just does not work. This is not what I am trying to do. The items (blocks) are in the drawing and I want to select them.

    Is there something that I need to set on that computer or something that I need to add to my code?

    Thanks in advance,
    Jason

    (the CreateSelectionSet function is the one that is causing the error)
    Code:
    Public Function pullBlockValue(BlockName As String, Field As String) As String
        Dim ssetObj As AcadSelectionSet
        Dim I As Integer, ii As Integer
        Dim myAttribute
        
        ' Create the selection set
        Set ssetObj = pullBlocks(BlockName)
        
        If ssetObj.Count > 0 Then
            'the block is used in the drawing
            myAttribute = ssetObj.Item(0).GetAttributes
            For ii = 0 To UBound(myAttribute)
                If myAttribute(ii).TagString = Field Or _
                    myAttribute(ii).TagString = UCase(Field) Then
                    pullBlockValue = myAttribute(ii).TextString
                 End If
             Next
        End If
    End Function
    
    Public Function pullBlocks(BlockName As String) As AcadSelectionSet
        Dim I As Integer, ii As Integer
        Dim myAttribute
        Dim fType(0 To 1) As Integer
        Dim fData(0 To 1) As Variant
        
        Set pullBlocks = CreateSelectionSet()
        If pullBlocks.Count = 0 Then Exit Function
        
        fType(0) = 0
        fData(0) = "INSERT"
        fType(1) = 2
        fData(1) = BlockName
        
        pullBlocks.Clear
        pullBlocks.Select acSelectionSetAll, , , fType, fData
    
        If pullBlocks.Count = 0 And _
           BlockName = "TITLE_BLOCK" Then
           Set pullBlocks = pullBlocks("tblock_blk")
        End If
    End Function
    
    Public Function CreateSelectionSet(Optional ssName As String = "ss") As  AcadSelectionSet
    
        Dim ss As AcadSelectionSet, I As Integer
    
        On Error Resume Next
        Set ss = ThisDrawing.SelectionSets(ssName)
        If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
        ss.Clear
        Set CreateSelectionSet = ss
        
    End Function
    Last edited by RobertB; 2005-06-20 at 08:55 PM. Reason: Added [ code ] format tags

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: SelectionSet Error

    It looks like this is rather (how do I put this gently?) sloppy.

    Function CreateSelectionSet declares I as an Integer. That variable isn't used in the function.

    Function pullBlocks calls CreateSelectionSet, which is ok. But then you have a test that dumps the function if the newly created selection set has objects in it. I fail to see the value of this test. The CreateSelectionSet function in only going to return a cleared selection set; there will never be anything in it.
    Code:
        Set pullBlocks = CreateSelectionSet()
        If pullBlocks.Count = 0 Then Exit Function
    There are also at least 3 variables declared at the beginning of the function that aren't used.
    You are clearing the selection set that has already be cleared by CreateSelectionSet before populating it.
    Code:
        pullBlocks.Clear
        pullBlocks.Select acSelectionSetAll, , , fType, fData
    Function pullBlockValue once again declares unneeded variables, and one that isn't named well (myAttribute is really an array of arributes, not just one attribute).

    However, unhappily, none of these comments really address your issue.
    Are you running a vertical product? Are you running out of selection set "slots"? (There are only a limited number.)

    For these sort of operations I usually use the PickfirstSelectionSet property on the Document object, which returns a selection set that isn't named, avoiding the whole SelectionSets issue addressed by CreateSelectionSet.

  3. #3
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: SelectionSet Error

    I never said that I was a world class programmer. I am just a guy trying to make my life and the few guys under me a little easier. I try to clean up my routines the best that I could with the other duties that I have to preform too. Most of the reason that this looks "sloppy" is because I shortened some of the functions and have been trying various things trying to fix the problem. I did not take everything out like I should have before posting it here. <<SORRY>>

    The reason for the SelectionSet test is because I had gotten errors that the Selection Set already exists. Therefore I can't just create a new one or just use the old one, I need to do the test. This mainly occurs when a routine is interrupted by the user. If you know another way to fix this, I would be happy to hear it. This was just the easiest way that I figured out how to fix it.

    I don't want the user to select the items. I want to pull all of the items. What I am doing is pushing and pulling information from the Title Blocks. For example. one routine changes the layout name to what the block's Sheet Number is. Another automatically updates the File Name on the Title blocks to it's actual file name and path. Another records information to an external text file. (various info like sheet numbers, sheet descriptions, plot dates, file name, etc..) At the moment, I have a few more routines that access the title block. I want to create more that access other objects in this manor too but I need to get the bugs worked out of this one first.

    Thanks,
    Jason.

  4. #4
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: SelectionSet Error

    Jason, please don't be upset. I know that all of us have "real" jobs. The fact that you post your code shows that you want to learn, which I appreciate. That's why I parenthetically asked "How do I put it gently?" I don't want to discourage you from expanding your skills, or asking questions. I'm sure you want to learn, so that's why I pointed out those items.

    I understand the purpose of CreateSelectionSet, in fact, it looks like code taken from AcadX.com, of which I was a partner.

    I did mention how to avoid the need for such code, by using PickfirstSelectionSet.
    Code:
    Public Sub Test()
      Dim dxfType(0 To 1) As Integer
      Dim dxfData(0 To 1) As Variant
      dxfType(0) = 0: dxfData(0) = "INSERT"
      dxfType(1) = 2: dxfData(1) = "DET"
      
      Dim mySS As AcadSelectionSet
      Set mySS = ThisDrawing.PickfirstSelectionSet
      mySS.Select Mode:=acSelectionSetAll, FilterType:=dxfType, FilterData:=dxfData
      
      MsgBox "I've found " & mySS.Count & " items!"
    End Sub
    I don't know if that will address your issue or not. But there are only a limited number of named selection sets available, and that is likely the issue you are running into.

  5. #5
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: SelectionSet Error

    thanks Robert, I will try that too.

    Ed, look forward to your reply.


    thanks,
    Jason

Similar Threads

  1. Replies: 0
    Last Post: 2015-03-20, 10:57 AM
  2. Making a SelectionSet active in GUI
    By ncraig122139 in forum VBA/COM Interop
    Replies: 7
    Last Post: 2012-03-13, 05:47 PM
  3. Sort Selectionset by X coord
    By ccowgill in forum AutoLISP
    Replies: 10
    Last Post: 2012-03-09, 03:41 PM
  4. Select Block with XDATA by selectionset method
    By ptlong04x1 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2011-07-04, 12:29 PM
  5. SelectionSet are KILLING me
    By jason907238 in forum VBA/COM Interop
    Replies: 22
    Last Post: 2005-07-12, 07:48 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
  •