Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Returning a selectionset from a function?

19 views
Skip to first unread message

David Mulligan

unread,
Feb 6, 1999, 3:00:00 AM2/6/99
to
If anyone knows how to return a selectionset, entity, or an array from a
function in VBA please give me a few lines of code showing how.

Thanks,
David

Kenneth Tam

unread,
Feb 6, 1999, 3:00:00 AM2/6/99
to
The selectionset you obtain from one of select method of it will give you an
array like object, just need to iterate through it. may be I'm clear of what
you are after

Ken

David Mulligan wrote in message <79it76$ph...@adesknews2.autodesk.com>...

David Mulligan

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
Thanks for responding but let me try to be more clear. Say you have a Sub
routine that Calls a function this function is going to be your selectionset
function how do you get the function to return a SelectionSet Object.

Public Sub MainProgram() 'sub routine

Dim ReturnedSelectionSet Object

ReturnedSelectionSet Object = MakeSelection() 'call my function

End Sub


MakeSelection()As ? 'function

MakeSelection = returnSelectionSetObjectToSub

End Function


Arno

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
Hi David,

Here's some code that gets a selectionset from a function.

Make sure you have the 'Autocad R14 Object Library' checked in
'Project\References' in your VB editor.

Regards,

Arno van Eeuwen


Option Explicit

Private Acad As Object
Private Document As Object


Public Sub Main()

Dim MainSset As AcadSelectionSet

Set Acad = GetObject(, "AutoCAD.Application")

Set Document = Acad.ActiveDocument

Set MainSset = GetSomethingFromScreen

MsgBox "Selected " & MainSset.Count & " items"

End Sub

Private Function GetSomethingFromScreen() As AcadSelectionSet

Dim Sset As AcadSelectionSet

Set Sset = Document.SelectionSets.Add("NameIt")

Sset.SelectOnScreen

Set GetSomethingFromScreen = Sset

End Function

Kenneth Tam

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
David:
If you embed a selectionset as argument in the function, then you can
reference to it after a function call,

In the procedure that make the call:

...

Dim ss as acadselectionset

set ss = ThisDrawing.Selectionsets.Add("ss")

' Make call to get the selection set

If GetMySS(ss) Then
' Do somthing with selectionset ss
end if

...

Follow is GetMySS function, I like to put a return as True/False so I'll
know if the function is success or fail

Public Function GetMySS(ss As AcadSelectionset) As boolean

' Reset the return value to fail
' Do some kine of select here
if ss.count = 0 then
GetMySS = False
else
GetMyss = True
end if
End Function

WARNING: ss Must be ByRef (default) can't not use ByVal event if it is any
VB(A) data type.

You don't have to have a return value of true, false but you need to check
the reference variable properties in order to know if the called function
operate success or not.

Ken

0 new messages