Posts: 4
Registered: ‎04-11-2013
Message 1 of 3 (309 Views)
Accepted Solution

Newbie VB.NET -- How to explode a polyline

309 Views, 2 Replies
03-24-2014 07:19 PM

Hello all,

I am new to programming in VB.NET and in Autocad.  I am writing a routine that will get all the polylines on some specific layers and then explode them.  Below is the code I have written.  I am correctly filtering the polylines into a selection set and then creating an array of the objectids.  Then I would like to have a For Loop to iterate through the array and then get the object via objectid and then cast it into an explodable object but I cannot think how to do this.  I am still learning about accessing objects so any help will be appreciated. 


        Public Sub expPoly()

            'get the current open drawing
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            'gets the database of the current drawing and assigns it to db
            Dim db As Database = doc.Database
            'allows the user to edit the database
            Dim ed As Editor = doc.Editor
            'sets up an array of layers we would like to delete objects that reside on
            Dim iter() As String = {"FA-CKT-NAC", "FA-CKT-ID", "FA-WIRERUN1", "FA-WIRERUN2"}
            'iterates through the layers array above
            For Each value As String In iter
                'sets up a typedvalue filter and then initializes it with the parameters

                Dim tv(1) As TypedValue
                tv.SetValue(New TypedValue(0, "lwpolyline"), 0)
                tv.SetValue(New TypedValue(8, value), 1)
                'Dim tv As TypedValue() = New TypedValue(2) {New TypedValue(0, "lwpolyline"), New TypedValue(-4, "&"), New TypedValue(70, 1)}
                Dim selFilter As New SelectionFilter(tv)

                'this selects all the entities in the drawing filtered by the user defined filter
                Dim res As PromptSelectionResult = ed.SelectAll(selFilter)

                'this is a selectionset of the entities
                Dim SS As SelectionSet = res.Value

                'if the selection set is NULL then it will not execute the code below
                If Not SS Is Nothing Then
                    'this is an array of objectids from the selection set
                    Dim idarray As ObjectId() = SS.GetObjectIds()

                    'open a transaction and initializes it
                    Using tm As Transaction = db.TransactionManager.StartTransaction()
                        'assigns id as the objectid of the entity in the array

                        Dim id As ObjectId

                        'iterates the array of object ids
                        For Each id In idarray
                            'currect object id
                            Dim tt As DBObject = CType(tm.GetObject(id, OpenMode.ForWrite), DBObject)


                    End Using
                End If
        End Sub


Valued Mentor
Posts: 449
Registered: ‎01-12-2008
Message 2 of 3 (286 Views)

Re: Newbie VB.NET -- How to explode a polyline

03-25-2014 12:37 AM in reply to: BuckeyeFanInFL76
Posts: 4
Registered: ‎04-11-2013
Message 3 of 3 (272 Views)

Re: Newbie VB.NET -- How to explode a polyline

03-25-2014 04:31 AM in reply to: Ajilal.Vijayan

Thank you Ajilal, this worked perfectly after a little tweaking.  The C# to VB translator was very helpful.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.