Using Object iD in SendCommand method

By Virupaksha Aithal
You can use Object id to send the “entity selection” while sending the command to AutoCAD using SendCommand API. You need to format the command string such that it contains the objectid handles. Refer below code, which invokes the fillet command after getting 2 lines from the user. The fillet command is used to show the use of Object id during the command invocation and you can use this logic in any other command which requires object selection.

_
        Public Sub testFillet()
            Dim doc As Document = _
                        Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim Db As Database = doc.Database
 
            Dim pEntRes1 As PromptEntityResult = ed.GetEntity( _
                                      "Select first line to Fillet")
            If pEntRes1.Status  PromptStatus.OK Then
                Return
            End If
 
            Dim obj1 As String = pEntRes1.ObjectId.ObjectClass.Name
 
            If String.Compare(obj1, "AcDbLine", True)  0 Then
                ed.WriteMessage("Select line entity" + vbLf)
                Return
            End If
 
            Dim pEntRes2 As PromptEntityResult = ed.GetEntity( _
                                    "Select second line to Fillet")
            If pEntRes2.Status  PromptStatus.OK Then
                Return
            End If
 
            obj1 = pEntRes2.ObjectId.ObjectClass.Name
 
            If String.Compare(obj1, "AcDbLine", True)  0 Then
                ed.WriteMessage("Select line entity" + vbLf)
                Return
            End If
 
            Dim strHandle1 As String = _
                        pEntRes1.ObjectId.Handle.ToString()
            Dim strEntName1 As String = _
                            "(handent """ & strHandle1 & """)"
 
            Dim strHandle2 As String = _
                            pEntRes2.ObjectId.Handle.ToString()
            Dim strEntName2 As String = _
                            "(handent """ & strHandle2 & """)"
 
            Dim strCommand As String = _
                        "_fillet" + vbCr + "r" + vbCr + "0.495" + _
                    vbCr + strEntName1 + vbCr + strEntName2 + vbCr
 
            doc.AcadDocument.SendCommand(strCommand)
 
        End Sub

Comments

5 responses to “Using Object iD in SendCommand method”

  1. This was a very helpful insight. I used the concept to perform some other tasks. Thanks.

  2. everybody Avatar
    everybody

    how do this from vba?

  3. Vaibhav Shinde Avatar
    Vaibhav Shinde

    Dim strEntName1 As String
    Dim rotobj As AcadEntity
    strEntName1 = “(handent “”” & rotobj.Handle & “””)”
    AcadDoc.SendCommand “ROTATE” & vbCr & strEntName1 & vbCr & ” ” & vbCr & 0 & “,” & varpt(1) & “,” & varpt(2) & vbCr

  4. Daboho Avatar
    Daboho

    How if using promptselection
    And ed.getselection() to any curve(multiple curve)
    Multiple fillet using send command is posible

  5. Merci !

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading