Selection Set Error

Selection Set Error

Anonymous
Not applicable
555 Views
5 Replies
Message 1 of 6

Selection Set Error

Anonymous
Not applicable
I'm not sure why this error exists, any help much appreciated!

[code]
Option Explicit

Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

Dim ss As AcadSelectionSet

On Error Resume Next
Set ss = ThisDrawing.SelectionSets(ssName)
ss.Select acSelectionSetAll
ThisDrawing.Wblock strQueryName ss ; compile error, expected end of statement
If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
ss.Clear
Set CreateSelectionSet = ss

End Function
[/code]

Thanks in advance
Rob
0 Likes
556 Views
5 Replies
Replies (5)
Message 2 of 6

GTVic
Advisor
Advisor
On the Wblock line:

- strQueryName is not defined
- a comma is needed after strQueryName
- should use ' after ss not ; for a comment 🙂
0 Likes
Message 3 of 6

Anonymous
Not applicable
This is the entire routine and I thought "strQueryName" was being defined here: Public Function QueryLoad(strQueryName As String) As Boolean

Any help appreciated!


Option Explicit

Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

Dim ss As AcadSelectionSet

On Error Resume Next
Set ss = ThisDrawing.SelectionSets(ssName)
ss.Select acSelectionSetAll
ThisDrawing.Wblock strQueryName, ss
If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
ss.Clear
Set CreateSelectionSet = ss


End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Option Explicit

Public Sub Main_RunQueries()

QueryLoad ("C:\RAD\CC_GIS\Page01.qry")
QueryLoad ("C:\RAD\CC_GIS\Page02.qry")
QueryLoad ("C:\RAD\CC_GIS\Page03.qry")
'etccc...

End Sub

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Option Explicit

'Function to call and run an External Query
'
' Required Parameters
' strQueryName - Full name of query file, including Path
' Additional function calls:
' None
Public Function QueryLoad(strQueryName As String) As Boolean
Dim AMap As AcadMap
Set AMap = GetObject(, "AutoCAD.Application").GetInterfaceObject("AutocadMap.Application")
Dim Result As Boolean

ThisDrawing.ActiveSpace = acModelSpace
AMap.Projects(0).DrawingSet.ZoomExtents
Result = AMap.Projects.Item(0).RunExternalQuery(strQueryName)
If (Not Result) Then
QueryLoad = False
GoTo EndFn
End If
Set AMap = Nothing

EndFn:
Exit Function
End Function 'QueryLoad
0 Likes
Message 4 of 6

GTVic
Advisor
Advisor
strQueryName is only defined inside QueryLoad.

Maybe you should show how CreateSelectionSet is called? Also, what is the error you are getting, is it still the same as before? What is the purpose of WBlock? You have an On Error statement and then 3 more statements before you check for an error. Which line are checking for an error?

Here is some code that works but I'm not sure what you are trying to accomplish because you haven't shown a link between QueryLoad and CreateSelectionSet, they don't seem to interact.

[code]
Option Explicit
Public Function WBlockAll(strFileName As String, ss As AcadSelectionSet) As Boolean

Dim Ok As Boolean

On Error Resume Next
Err.Clear
ss.Select acSelectionSetAll
Ok = (Err.Number = 0)
On Error GoTo 0

If Ok And ss.Count > 0 Then
On Error Resume Next
ThisDrawing.Wblock strFileName, ss
WBlockAll = (Err.Number = 0)
On Error GoTo 0
ss.Clear
Else
WBlockAll = False
End If

End Function
Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

Dim ss As AcadSelectionSet, Ok As Boolean

On Error Resume Next
Err.Clear
Set ss = ThisDrawing.SelectionSets(ssName)
Ok = (Err.Number = 0)
On Error GoTo 0

If Not Ok Then
On Error Resume Next
Err.Clear
Set ss = ThisDrawing.SelectionSets.Add(ssName)
Ok = (Err.Number = 0)
On Error GoTo 0
End If

If Ok Then
Set CreateSelectionSet = ss
Else
Set CreateSelectionSet = Nothing
End If

End Function
Private Sub Test()

Dim ssTest As AcadSelectionSet

Set ssTest = CreateSelectionSet("test")
ssTest.Clear
If ssTest Is Nothing Then
MsgBox "CreateSelectionSet Failed", vbInformation, "Message"
Else
WBlockAll "c:\Test.dwg", ssTest
End If

End Sub
[/code]
0 Likes
Message 5 of 6

Anonymous
Not applicable
Please take a good look at your code.

You use On Error Resume Next, and when this
line is reached:

Set ss = ThisDrawing.SelectionSets(ssName)

An error occurs. Then, the next line executes (the
call to the Select method), and another error occurs,
because the ss variable is not yet assigned to a
valid selection set object.

Change your code to ensure that you have a valid
selection set first, before you try to use it:

On Error Resume Next
Set ss = ThisDrawing.SelectionSets(ssName)
If Err Then
Err.Clear
Set ss = ThisDrawing.SelectionSets.Add(ssName)
End If
On Error Goto 0

// Got the selection set, now use it.

ss.Select acSelectionSetAll
ThisDrawing.Wblock strQueryName ss ...

Also, note that there is some danger to taking the
approach above, without examining the Err object,
to see if it was the 'Key not found' or equivalent
error. If there's a possiblity that it can be another
type of error, it will go undetected.

Good programming technique dictates that when
you're expecting a specific error to occur, you make
sure that it is the one one you expected, and if it
wasn't then you let the program fail.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4933956@discussion.autodesk.com...
I'm not sure why this error exists, any help much appreciated!

[code]
Option Explicit

Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

Dim ss As AcadSelectionSet

On Error Resume Next
Set ss = ThisDrawing.SelectionSets(ssName)
ss.Select acSelectionSetAll
ThisDrawing.Wblock strQueryName ss ; compile error, expected end of statement
If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
ss.Clear
Set CreateSelectionSet = ss

End Function
[/code]

Thanks in advance
Rob
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks Vic,
I'm trying to query map data using 67 different external query files, so I need to run specified query file, zoom extents, wblock all, query next, repeat.

Option Explicit

Public Sub Main_RunQueries()

QueryLoad ("C:\RAD\CC_GIS\Page01.qry")
QueryLoad ("C:\RAD\CC_GIS\Page02.qry")
QueryLoad ("C:\RAD\CC_GIS\Page03.qry")
'etccc...

End Sub


I need to set this up so that it will run continuous until it steps through all query files.
I need each wblock to be named after the query file, Page01, Page02, etc....
I posted this here in hopes that someone would be more familiar with this than I am.
I wrote this using LISP, but couldn't get all three commands to execute properly and thought someone could pull it off using VBA.
Help much appreciated!
Rob
0 Likes