Excel VBA - run overkill command on selection set

Excel VBA - run overkill command on selection set

cool.stuff
Collaborator Collaborator
2,163 Views
21 Replies
Message 1 of 22

Excel VBA - run overkill command on selection set

cool.stuff
Collaborator
Collaborator

Hi!!

 

i'm trying to run overkill command on a selection set. This is my current code:

 

*Moderator Edit* changed code language to VB

 

        'select all objects of layer "GapPoints"
        Dim tSelSet As AcadSelectionSet
        
        Dim FromLayer As String
        FromLayer = "GapPoints"
        
        Dim pSelSetName As String
        pSelSetName = "mySelSetGapPoints"
        
        'create SelectionSet
        On Error Resume Next
        Set tSelSet = acadDoc.SelectionSets.Item(pSelSetName)
        If (Not (tSelSet Is Nothing)) Then
            tSelSet.Clear
        Else
            Err.Clear
            Set tSelSet = acadDoc.SelectionSets.Add(pSelSetName)
        End If
   
        'create selection filter
        'Filtering SelectionSet
        Dim tDxfCodes(0) As Integer
        Dim tDxfValues(0) As Variant
        tDxfCodes(0) = 8
        tDxfValues(0) = FromLayer
      
        'create selection
        Call tSelSet.Select(acSelectionSetAll, , , tDxfCodes, tDxfValues)
        
        Dim acadcommand As String
        'acadcommand = """" & "_-overkill" & """" & ", tSelSet, " & """" & """" & ", " & """" & """"
        acadcommand = "_-overkill" & vbCr & "tSelSet" & vbCr & vbCr
        
        ' run overkill command on created selection set previously
        acadApp.ActiveDocument.SendCommand acadcommand & vbCr

 

 

Both lines 32 and 33 give error.

 

Does anybody knows to to run overkill command on a selection set via Excel VBA please?

 

Many thanks! 🙂

 

0 Likes
Accepted solutions (1)
2,164 Views
21 Replies
Replies (21)
Message 21 of 22

Ed__Jobe
Mentor
Mentor

It has to do with "scope" You declare tSelSet on line 12, but when you move to RunOverkillOnSelectionset, the tSelSet variable goes out of scope, i.e. it becomes Nothing. By passing only a string to the function, you only get a new ss with the same name. Therefore I changed the signature of RunOverkillOnSelectionset to pass an AcadSelectionSet object. That way the variable doesn't go out of scope. It gets passed by reference to the new function.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 22 of 22

cool.stuff
Collaborator
Collaborator

Many thanks @Ed__Jobe  🙂 quite useful (sorry for the late answer!)

Best regards

0 Likes