.NET

Reply
Active Contributor
Posts: 37
Registered: ‎04-27-2010
Message 1 of 12 (431 Views)

No 'SelectionSets' in VB.net

431 Views, 11 Replies
11-15-2012 11:11 AM

From the AutoDESK help docs (http://docs.autodesk.com/ACD/2013/EN...ber=d30e719293)


"AutoCAD.Application.ActiveDocument.SelectionSets. Add method
Not needed/provided" in VB.Net


Thus 'Autodesk.AutoCAD.ApplicationServices.Application. DocumentManager.MdiActiveDocument.SelectionSets' will not work.

So, I can't store multiple selection sets in VB.Net?


Why is it not provided? Or is there some other way to do that?
*Expert Elite*
Posts: 887
Registered: ‎04-27-2009
Message 2 of 12 (426 Views)

Re: No 'SelectionSets' in VB.net

11-15-2012 12:10 PM in reply to: NirantarVidyarthee

It seems you do not know the difference of programming language (VB.NET/C#...) and AutoCAD APIs (COM API/.NET API).

 

AutoCAD.Application.ActiveDocument.SelectionSets. Add() still exists in COM API and can be used when needed. With AutoCAD .NET programming (VB.NET/C#), AutoCAD .NET API usually provides enough functionlities, but you can easily mix COM API calls in it (in many cases it is not necesary, as you quoted!).

 

So, what do you do that you have to use "AutoCAD.Application.ActiveDocument.SelectionSets. Add()", instead of various selecting methods provided in .NET API?

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 3 of 12 (418 Views)

Re: No 'SelectionSets' in VB.net

11-15-2012 01:00 PM in reply to: NirantarVidyarthee

SelectionSet object is member of

Autodesk.AutoCAD.EditorInput namespace

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
Posts: 37
Registered: ‎04-27-2010
Message 4 of 12 (415 Views)

Re: No 'SelectionSets' in VB.net

11-15-2012 01:18 PM in reply to: norman.yuan

Obviusly, I don't know the difference between VB and VBA. That;s the reason I came here and asked the question.

 

But my original quesry remains: How can I access the SelectionSets collection (or its equivalent) in VB.Net.

 

If I create 2 selection sets ss1 and ss2, then how do I access one of these like:

 

ThisDrawing.SelectionSets("SS1")

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 5 of 12 (392 Views)

Re: No 'SelectionSets' in VB.net

11-15-2012 11:30 PM in reply to: NirantarVidyarthee

Show your Sub code to see what you started wth,

guess you want to use Interop library?

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
Posts: 37
Registered: ‎04-27-2010
Message 6 of 12 (385 Views)

"Re: No 'SelectionSets' in VB.net

11-16-2012 04:00 AM in reply to: Hallex

"If I create 2 selection sets ss1 and ss2, then how do I access one of these like:

ThisDrawing.SelectionSets("SS1")

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 7 of 12 (377 Views)

Re: "Re: No 'SelectionSets' in VB.net

11-16-2012 05:41 AM in reply to: NirantarVidyarthee

I didn't see your code, well, then try my attempt

    <CommandMethod("testAcadSelections")> _
    Public Shared Sub testSelections()
        '' borrowed from Luis Esquivel
        Dim AcadComApp As AcadApplication = Nothing
        Dim progId As String = "AutoCAD.Application.18" ''   <-- AutoCAD 2010

        Try
            ' Get a current instance of AutoCAD
            AcadComApp = TryCast(GetObject(, progId), AcadApplication)

        Catch ex As System.Exception
            Try
                ' Create a new instance of AutoCAD
                AcadComApp = TryCast(CreateObject(progId), AcadApplication)

            Catch exx As Exception
                MsgBox(exx.Message)
                Exit Sub
            End Try
        End Try

        Try
            ' Get the active document
            Dim AcadComDoc As AcadDocument = TryCast(AcadComApp.ActiveDocument, AcadDocument)
            ' Get AcadSelectionSets collection
            Dim AcadSets As AcadSelectionSets = TryCast(AcadComDoc.SelectionSets, AcadSelectionSets)
            ' Declare AcadSelectionSet
            Dim AcadSsetObj As AcadSelectionSet = Nothing
            ' Get a StringBuilder object
            Dim sb As StringBuilder = New StringBuilder
            ' Add some selections to document
            For i As Integer = 0 To 24
                Dim setName As String = "Selection" & (i + 1).ToString()
                AcadSsetObj = AcadSets.Add(setName)
                sb.AppendLine(AcadSsetObj.Name)
            Next

            MsgBox("Number of selections created: " & AcadSets.Count.ToString() & vbLf & sb.ToString())
            Dim layoutName As String = AcadComDoc.GetVariable("ctab").ToString()
            ' Get the very first selection
            AcadSsetObj = AcadSets.Item(0)
            ' Create filter to select attributed blocks on current layout
            Dim filterType(2) As Short
            filterType(0) = 0
            filterType(1) = 66
            filterType(2) = 410

            Dim filterData(2) As Object
            filterData(0) = "insert"
            filterData(1) = 1
            filterData(2) = layoutName
            ' Perform the Select method
            AcadSsetObj.Select(AcSelect.acSelectionSetAll, , , filterType, filterData)
            ' Display result
            MsgBox("First selection:" & vbLf & "Number of block selected: " & AcadSsetObj.Count.ToString())
        Catch aex As System.Exception
            MsgBox(aex.Message & vbLf & aex.StackTrace)
        Finally
            ' AcadComApp.Quit()
            AcadComApp = Nothing
        End Try
    End Sub

 See for more

http://through-the-interface.typepad.com/through_the_interface/2010/02/handling-com-calls-rejected-b...

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
Posts: 37
Registered: ‎04-27-2010
Message 8 of 12 (361 Views)

No 'SelectionSets' in VB.net

11-16-2012 10:43 PM in reply to: Hallex

Thankyou but my question is not about how we can use COM API for getting SelectionSets collection. My question is why .NET API does not provide this and is there any other way in .NET API, other than probably creating my own collection.

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 9 of 12 (357 Views)

Re: No 'SelectionSets' in VB.net

11-16-2012 11:19 PM in reply to: NirantarVidyarthee

My answer is in post#3 if you don't understand it

Type:

Autodesk.AutoCAD.EditorInput

 

in editor console,

then highlight it and select from right clicking mouse: Go to Definition,

then scroll down to see Selection within object Browser

You can see so there is no SelectionSets collection in there

just only SelectionSet object only, and also read the docs for more

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
Posts: 37
Registered: ‎04-27-2010
Message 10 of 12 (355 Views)

Re: No 'SelectionSets' in VB.net

11-16-2012 11:42 PM in reply to: Hallex

" You can see so there is no SelectionSets collection in there

just only SelectionSet object only, and also read the docs for more."

 

I know this.And I stated this in my first post. 

 

I am asking why? What could be the logical reason behind not having the collection? And is using COM API the only alternative?

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community