PDA

View Full Version : Deselect Some of Selected Objects



Reza.Foroozan769984
2018-07-10, 03:51 PM
Hi,
For a project I need to prevent the user to modify objects which belong to a specific Layer.
below is my VBA code to do this.I used "SelectionChanged" event to trigger the program. I can loop through objects that are selected by user.The problem starts when I want to deselect the objects that are in "Block" layer. Actually, I can't find any way to deselect them.I will be very glad if you can help me.Many thanks in advance

Private Sub AcadDocument_SelectionChanged()

Dim pfSS As AcadSelectionSet
Dim ssobject As AcadEntity
Dim msg As String
msg = vbCrLf

Set pfSS = ThisDrawing.PickfirstSelectionSet

For Each ssobject In pfSS

If ssobject.Layer = "Block" Then

'' Here I dont know how to deselect!!
msg = msg & vbCrLf & ssobject.ObjectName

MsgBox "The Block Object Type Is: " & msg

End If

Next ssobject

End Sub

Ed Jobe
2018-07-10, 06:33 PM
Use the AcadSelectionSet.RemoveItems method. You can't simply execute the method in your For..Each loop because then the selection set will be changing on each loop. Therefore, you need to add the qualifying items to an array of AcadEntity objects. After the For..Each loop completes, then you can run the RemoveItems method and pass it the array of entities to be removed.