Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit:</strong> Further investigation shows that you should be calling ssetObj(i) if you want to get indexed items of your selection set.</p> <p>I'd not worry about trying to get the count of the selection set anyway if you plan on iterating through it. A For Each should suffice to walk though it. One of the problems with going from VBA/VB6 to VB.NET is the temptation to use the same methodology, when it can sometimes be invalid (at times it can be excellent, but .NET is very capable). Here's my entire class that I tested your problem with, just to show how I'm connecting to AutoCAD and interfacing with it.</p> <pre><code>Public Class frmMain Private acApp As AcadApplication Private polyList As List(Of String) Const acProgId As String = "AutoCAD.Application.17" &lt;DllImport("User32.dll")&gt; _ Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean End Function Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click Try acApp = DirectCast(Marshal.GetActiveObject(acProgId), AcadApplication) Catch Try Dim acType = Type.GetTypeFromProgID(acProgId) acApp = DirectCast(Activator.CreateInstance(acType), AcadApplication) Catch ex As Exception MsgBox("Unable to create AutoCAD application of type: " &amp; acProgId) End Try End Try End Sub Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click If acApp Is Nothing Then Return acApp.Visible = True Dim acDoc As AcadDocument = acApp.ActiveDocument ' Kill all existing selection sets While (acDoc.SelectionSets.Count &gt; 0) acDoc.SelectionSets(0).Delete() End While Dim mySS As AcadSelectionSet = acDoc.SelectionSets.Add("ss") SetForegroundWindow(acApp.HWND) mySS.SelectOnScreen() polyList = New List(Of String) Dim numVertices As Integer For Each ent As AcadEntity In mySS If ent.ObjectName = "AcDbLWPolyline" Or ent.ObjectName = "AcDbPolyline" Then numVertices = (ent.Coordinates.Length) / 2 polyList.Add(String.Format("{0} \ {1} Vertices", ent.ObjectID, numVertices)) End If Next End Sub End Class </code></pre> <p>External COM methods like this are going to be slower than you're used to seeing via VBA. Therefore it's definitely worth diving into the in-process AutoCAD .NET stuff to see great performance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload