×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA selection set only sees lines if they are redrawn
2

VBA selection set only sees lines if they are redrawn

VBA selection set only sees lines if they are redrawn

(OP)
I have a VBA program that selects lines on certain layers in a drawing. It almost always works correctly, but every once in a while it will not select some of the lines. If I delete the lines and redraw them, they then can be selected. Any idea what could cause a line to NOT be selected, but then to later be selected if the line is redrawn on the same layer?

RE: VBA selection set only sees lines if they are redrawn

Could you post some code so we can take a look? Thanks.

http://mechcad-insider.blogspot.com/
 
"The fear of the Lord is the beginning of wisdom"

RE: VBA selection set only sees lines if they are redrawn

Also note that VBA has a hard time selecting entities that are not shown in the current view. Does it miss the lines when you can see them in the window?

RE: VBA selection set only sees lines if they are redrawn

(OP)
Here is the selection set part of the code.

For i = 1 To 8
    '''''activate the proper layer
    If i = 1 Then Layername = "MESA2_UX1100"
    If i = 2 Then Layername = "MESA3_UX1400"
    If i = 3 Then Layername = "MESA4_UX1500"
    If i = 4 Then Layername = "MESA5_UX1600"
    If i = 5 Then Layername = "MESA6_UX1700"
    If i = 6 Then Layername = "MESA7_UX1800"
    If i = 7 Then Layername = "BX1100"
    If i = 8 Then Layername = "BX1200"

    intCode(0) = -4: varCodeValue(0) = "<AND"
    intCode(1) = 0: varCodeValue(1) = "LINE"
    intCode(2) = -4: varCodeValue(2) = "<OR"
    intCode(3) = 8: varCodeValue(3) = Layername
    intCode(4) = -4: varCodeValue(4) = "OR>"
    intCode(5) = 67: varCodeValue(5) = "0"
    intCode(6) = -4: varCodeValue(6) = "AND>"
 
    '''''select all lines on current layer above a certain line
    '''''that is located at Pt1 to Pt2

   On Error Resume Next
    ThisDrawing.SelectionSets("TEMP").Delete
    Set objSS = ThisDrawing.SelectionSets.Add("TEMP")
    objSS.Select 1, Pt1, Pt2, intCode, varCodeValue

    If objSS.count > 0 Then
        For Each objLine In ThisDrawing.ActiveSelectionSet
            LineCount = LineCount + 1
            objLine.Highlight True
            StPoint = objLine.EndPoint
            EndPoint = objLine.StartPoint
        Next objLine
    End If
Next i

RE: VBA selection set only sees lines if they are redrawn

My first suspect is the type of selection you are doing. It appears to be a window. If this is so, then are all the entities within this window? Would a crossing window work better?

http://mechcad-insider.blogspot.com/
 
"The fear of the Lord is the beginning of wisdom"

RE: VBA selection set only sees lines if they are redrawn

Hi jrice174,

Borgie's right, you're using a window which won't see everything until it's regened, or if you're lucky, just redrawn.  If you must have the window, you'll need to insert a regen before your selection statement if not, change your select statement from:

CODE

objSS.Select 1, Pt1, Pt2, intCode, varCodeValue

To:

CODE

objSS.Select Mode:=acSelectionSetAll, FilterType:=intCode, FilterData:=varCodeValue

and see if that doesn't help a bit.

HTH
Todd

RE: VBA selection set only sees lines if they are redrawn

(OP)
I turns out that the engineer used polylines instead of lines. I was selecting lines. As you can see my filterdata is only set up to look for lines. I don't have a good grasp of the logic used in the FilterData array. Can you help?

RE: VBA selection set only sees lines if they are redrawn

It looks like you know what you are doing. This would get all polylines or lines on your layername and in your space.

intCode(0) = -4:   varCodeValue(0) = "<AND"
intCode(1) = 0:    varCodeValue(1) = "<OR"
intCode(2) = 0:    varCodeValue(2) = "LINE"
intCode(3) = 0:    varCodeValue(3) = "POLYLINE"
intCode(4) = -4:   varCodeValue(4) = "OR>"
intCode(5) = 8:    varCodeValue(5) = Layername
intCode(6) = 67:   varCodeValue(6) = "0"
intCode(7) = -4:   varCodeValue(7) = "AND>"

http://mechcad-insider.blogspot.com/
 
"The fear of the Lord is the beginning of wisdom"

RE: VBA selection set only sees lines if they are redrawn

(OP)
Fantastic thanks

RE: VBA selection set only sees lines if they are redrawn

Certain filtering values can be stacked to allow for more compact code, plus additional functionality is available with the Wildcard operator "*".

    intCode(0) = -4:   varCodeValue(0) = "<AND"
   intCode(1) = 0:    varCodeValue(1) = "LINE,LWPOLYLINE,POLYLINE"
   intCode(2) = 8:    varCodeValue(2) = "MESA*,BX*"
   intCode(3) = -4:   varCodeValue(3) = "<NOT"
   intCode(4) = 8:    varCodeValue(4) = "MESA_UX1200,MESA_UX1300"
   intCode(5) = -4:   varCodeValue(5) = "NOT>"
   intCode(6) = 67:   varCodeValue(6) = "0"
   intCode(7) = -4:   varCodeValue(7) = "AND>"

RE: VBA selection set only sees lines if they are redrawn

(OP)
Great! That helps a lot

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources