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
Solved! Go to Solution.
Solved by Ajilal.Vijayan. Go to Solution.
Try this
The code in the above link is in C#.
This webpage can use to convert the C# code VB.net
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.