Author Topic: True Color Filter  (Read 2036 times)

0 Members and 1 Guest are viewing this topic.

chobo

  • Newt
  • Posts: 24
True Color Filter
« on: April 21, 2008, 02:04:10 AM »
I want to select several same ACI color entities and then display grip.
on Drawing...
some entities color = 255,194,10 (True Color)
some entities color = 40 (ACI color)
all these entities are same ACI color 40 (but I want to Filtering True Color entities)
I am trying to following code.. because It seems to be DXF group filter does not support True color

Sub ColorFilter()
    Dim objSelSet As AcadSelectionSet
    On Error Resume Next
    ThisDrawing.SelectionSets("sset").Delete
    On Error GoTo ErrHere
   
    Set objSelSet = ThisDrawing.SelectionSets.Add("sset")
    Dim intGcode(0) As Integer
    Dim varCodeData(0) As Variant
    intGcode(0) = 62
    varCodeData(0) = "40"
    objSelSet.Select acSelectionSetAll, , , intGcode, varCodeData
   
    Dim lngMax As Long
    Dim lngCnt As Long
    Dim objRemove(0) As AcadEntity
    lngMax = objSelSet.Count
    For lngCnt = 0 To lngMax - 1
        Set objRemove(0) = objSelSet.Item(lngCnt)
        If objRemove(0).TrueColor.ColorMethod = acColorMethodByRGB Then
            objSelSet.RemoveItems objRemove
        End If
    Next
    objSelSet.Delete
    ThisDrawing.SendCommand "(sssetfirst nil (ssget " & Chr(34) & "_P" & Chr(34) & ")) "
    Exit Sub
   
ErrHere:
    If Err Then
        Err.Clear
        MsgBox Err.Description
    End If
End Sub
'----------------------------

But, it does not work
and I am trying to http://discussion.autodesk.com/thread.jspa?messageID=415583 with using VLAX instead of above SendCommand..
also end in failure.
Is there any way? or any ideas?

Bryco

  • Water Moccasin
  • Posts: 1860
Re: True Color Filter
« Reply #1 on: April 21, 2008, 10:55:43 AM »
255, 194, 10  =20 for me

chobo

  • Newt
  • Posts: 24
Re: True Color Filter
« Reply #2 on: April 21, 2008, 08:46:50 PM »
Bryco, this is example for me.
draw similar color or different color entities and test it.
my goal is last selectionset -> select entities and set grip
« Last Edit: April 21, 2008, 08:50:55 PM by chobo »

Bryco

  • Water Moccasin
  • Posts: 1860
Re: True Color Filter
« Reply #3 on: April 21, 2008, 11:59:46 PM »
What you want to do is just not good in vba, net would be good.

Jeff_M

  • King Gator
  • Posts: 4030
  • C3D user & customizer
Re: True Color Filter
« Reply #4 on: April 22, 2008, 01:06:55 AM »
Chobo,
Your code was deleting objects from the SelectionSet while iterating it...that is a no-no. Also, you cleared the error in the error handler before reporting what the error was, so it showed nothing in the error MsgBox.

The following code does what you are expecting, I think. I don't like using SendCommand, but without going to the VL class it's the only way I can think of right now.
Code: [Select]
Option Explicit


Sub ColorFilter()
    Dim objSelSet As AcadSelectionSet
    On Error Resume Next
    ThisDrawing.SelectionSets("sset").Delete
    On Error GoTo ErrHere
   
    Set objSelSet = ThisDrawing.SelectionSets.Add("sset")
    Dim intGcode(0) As Integer
    Dim varCodeData(0) As Variant
    intGcode(0) = 62
    varCodeData(0) = "40"
    objSelSet.Select acSelectionSetAll, , , intGcode, varCodeData
   
    Dim lngMax As Long
    Dim lngCnt As Long
    Dim objRemove() As AcadEntity
    Dim objEnt As AcadEntity
    Dim I As Integer
   
    lngMax = objSelSet.Count
    For lngCnt = 0 To lngMax - 1
        Set objEnt = objSelSet.Item(lngCnt)
        If objEnt.TrueColor.ColorMethod = acColorMethodByRGB Then
            ReDim Preserve objRemove(I)
            Set objRemove(I) = objEnt
            I = 1 + I
        End If
    Next
    objSelSet.RemoveItems objRemove
    If objSelSet.Count > 0 Then
        ThisDrawing.SendCommand "(setq ss (ssadd)) "
        For Each objEnt In objSelSet
            ThisDrawing.SendCommand "(ssadd (handent " & Chr(34) & objEnt.Handle & _
                                     Chr(34) & ") ss) "
        Next
    End If
    ThisDrawing.SendCommand "(sssetfirst nil ss) "
    objSelSet.Delete
    Exit Sub
   
ErrHere:
    If Err Then
        MsgBox Err.Description
        Err.Clear
    End If
End Sub

Bryco

  • Water Moccasin
  • Posts: 1860
Re: True Color Filter
« Reply #5 on: April 22, 2008, 10:11:41 AM »
I don't quite get the goal
some entities color = 255,194,10 (True Color)
some entities color = 40 (ACI color)
If you use 40 then you won't get 255,194,10  as it is 20.
So I thought you must be trying to get every item with a true color.
If this is the case there is no need for a selectionset filter.

I'm hoping Jeff has what you want.

Jeff_M

  • King Gator
  • Posts: 4030
  • C3D user & customizer
Re: True Color Filter
« Reply #6 on: April 22, 2008, 11:45:38 AM »
Bryco, create the 4 circles with the colors as chobo shows, then use (entget (car (entsel))) on each of them. The DXF 62 code shows 40 for all but the one that is specified 30, so a Filtered SS (on dxf 62 = 40) gets 3 of the 4. They only want the one which is specifically the ACI color 40.

chobo

  • Newt
  • Posts: 24
Re: True Color Filter
« Reply #7 on: April 22, 2008, 11:57:09 AM »
Sorry about my poor explanation..
my goal is select only ACI color entities
1. select entities use group code "62" (any ACI color as well as 40)
2. subtract True color entities from selectionset because group code "62" is not support True color.
3. selectionset to set grip
Thanks alot Jeff_M, Bryco !!

Bryco

  • Water Moccasin
  • Posts: 1860
Re: True Color Filter
« Reply #8 on: April 22, 2008, 11:36:16 PM »
55, 194, 10  =20 , well I can't make that happen again.
What was I drinking, I mean thinking.