Sendcommand Select Object

Discussion in 'AutoCAD' started by Jason Stevens, Feb 26, 2004.

  1. I am using the following code to try and run a command and have it use a
    3dpolyline that gets selected by the user. The problem is at the handent
    part of the code. How would I have the sendcommand use that 3dpoly? I have
    to use the sendcommand because the 3D Polyline Create Curb command can not
    be accessed any other way (as far as I know).

    Dim ent As Object
    Dim pt As Variant
    Dim Cmd1 As String
    Dim Cmd2 As String
    Dim Cmd3 As String

    Cmd1 = "(er_mnl)"
    Cmd2 = "(zz_sdsk'(er_grdcurb))"
    Cmd3 = "ldd"

    On Error Resume Next
    ThisDrawing.Utility.GetEntity ent, pt, "Pick something:" '3dpoly gets
    selected here
    If (Err.Number = 0) Then
    ThisDrawing.SendCommand Cmd1 & vbCr & Cmd2 & vbCr & Cmd3 & vbCr &
    "(handent """ & ent.Handle & """)"
    Else
    'The user didn't pick something
    End If


    Thanks for any help,
    Jason
     
    Jason Stevens, Feb 26, 2004
    #1
  2. Jason Stevens

    Ed Jobe Guest

    Here's one I wrote that's self explanitory.

    Public Function Ent2lspEnt(entObj As AcadEntity) As String
    'Designed to work with SendCommand, which can't pass objects.
    'This gets an objects handle and converts it to a string
    'of lisp commands that returns an entity name when run in SendCommand.
    Dim entHandle As String

    entHandle = entObj.Handle
    Ent2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
    End Function
     
    Ed Jobe, Feb 26, 2004
    #2
  3. Jason Stevens

    Jeff Mishler Guest

    Jason,
    Instead of using Sendcommand, which processes asynchrously with the
    remaining code, why noy create your own curb function? I've created this as
    a start for you, no error checking and it may/probably will fail if the
    offset function truncates the pline but it should give you the basics....

    Option Explicit

    Sub TestMe()
    Dim ent As Object
    Dim Pline As Acad3DPolyline
    Dim newPline As Acad3DPolyline
    Dim pt As Variant
    Dim curbHeight As Double
    Dim curbOffset As Double

    On Error Resume Next
    ThisDrawing.Utility.GetEntity ent, pt, "Pick something:" '3dpoly gets
    selected here
    If (Err.Number = 0) Then
    If TypeOf ent Is Acad3DPolyline Then
    Set Pline = ent
    curbHeight = ThisDrawing.Utility.GetReal(vbCrLf & "Curb height: ")
    curbOffset = ThisDrawing.Utility.GetReal(vbCrLf & "Offset distance:
    ")
    Set newPline = MakeCurb(Pline, curbHeight, curbOffset)
    End If
    Else
    'The user didn't pick something
    End If

    End Sub

    Public Function MakeCurb(Pline As Acad3DPolyline, height As Double, offset
    As Double) As Acad3DPolyline
    Dim tempPline1 As AcadPolyline
    Dim tempPline2 As AcadPolyline
    Dim newPline As Acad3DPolyline
    Dim temp As Variant
    Dim coords As Variant
    Dim newcoords As Variant
    Dim i As Long

    coords = Pline.Coordinates
    If offset <> 0 Then
    Set tempPline1 = ThisDrawing.ModelSpace.AddPolyline(coords)
    temp = tempPline1.offset(offset)
    Set tempPline2 = temp(0)
    newcoords = tempPline2.Coordinates
    tempPline1.Delete
    tempPline2.Delete
    Else
    newcoords = coords
    End If
    For i = 2 To UBound(newcoords) Step 3
    newcoords(i) = coords(i) + height
    Next i
    Set newPline = ThisDrawing.ModelSpace.Add3DPoly(newcoords)
    newPline.Layer = Pline.Layer
    Set MakeCurb = newPline

    End Function

    HTH,
    Jeff
     
    Jeff Mishler, Feb 26, 2004
    #3
  4. Ed,
    I implemented your code but am still having a problem. My code currently
    looks like:

    Dim Ent As AcadEntity
    Dim pt As Variant
    Dim Cmd1 As String
    Dim Cmd2 As String
    Dim Cmd3 As String
    Dim entHandle As String
    Dim Ent21spEnt As String

    Cmd1 = "(er_mnl)"
    Cmd2 = "(zz_sdsk'(er_grdcurb))"
    Cmd3 = "ldd"

    On Error Resume Next
    ThisDrawing.Utility.GetEntity Ent, pt, "Pick something:"
    entHandle = Ent.Handle
    Ent21spEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
    If (Err.Number = 0) Then
    ThisDrawing.SendCommand Cmd1 & vbCr & Cmd2 & vbCr & Cmd3 & vbCr &
    Ent21spEnt & vbCr
    Else
    'The user didn't pick something
    End If

    I get this (handent "A22A") at the select polyline step and then it says:
    Can't reenter LISP
    Invalid point
    It then asks to Select polyline again. Any ideas why it is not working? I
    did try placing the code in its own module and calling to that way but got
    the same results.

    Jason
     
    Jason Stevens, Feb 26, 2004
    #4
  5. Jason,
    I don't have Land or whatever so I can't check your functions, but if you
    haven't already you should check your commands incrementally. Truncate your
    command string (save a copy first, of course), and put an "End" statement
    after it, and see if your code leaves you hanging in the middle of the
    command where you expect to be. Add a little more of your command string
    and re-run. Sometimes it's just a matter of the wrong # of vbCR's or
    something... or the command may require a varying # of CR's.

    HTH,

    James
     
    James Belshan, Feb 26, 2004
    #5
  6. Jeff,
    That is awesome. Thank you very much. I am going to have it offset 5 times
    so I just have to do that part but this is great.

    Thanks,
    Jason
     
    Jason Stevens, Feb 26, 2004
    #6
  7. Jason Stevens

    Ed Jobe Guest

    Ent2LispEnt is a funtion, not a variable. You should have just pasted the
    code into your module.
    Ent2LispEnt(Ent) returns a string with the handle in it.
    I don't know what those other lisp funtions do, but try setting a lisp var
    first, and then calling the other funtions with them referencing the
    variable you just set.
     
    Ed Jobe, Feb 26, 2004
    #7
  8. Jason Stevens

    Jeff Mishler Guest

    You are welcome and I'm glad you like it. I'd been thinking about doing that
    for some time, and your initial post made me think about it again. So thanks
    to you for prodding me on! ;-)

    Jeff
     
    Jeff Mishler, Feb 26, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.