.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Newbie VB.NET -- How to explode a polyline

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
BuckeyeFanInFL76
1578 Views, 2 Replies

Newbie VB.NET -- How to explode a polyline

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)

                        Next

                        tm.Commit()
                        tm.Dispose()
                    End Using
                Else
                End If
            Next
        End Sub

 

Tags (2)
2 REPLIES 2
Message 2 of 3

Message 3 of 3

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost