Drawing Ellipsessess...

Discussion in 'AutoCAD' started by Matt W, Mar 4, 2004.

  1. Matt W

    Matt W Guest

    Okay... here's the deal...
    I would like to be able to pick a point on the screen and draw an ellipse with the bottom of the ellipse at the point that was picked.
    Here's how I'm doing it with LSP, but I'd like to move it to VBA.
    I use this code when creating utility profiles.

    Any input will be greatly appreciated!


    --------------------------------------------------------------------------------

    (defun PROFILEPIPE (intHeight intWidth)
    (setq pt1 (getpoint "\n Pick the invert elevation of pipe..."))
    (command "ellipse" pt1 (strcat "@0," intHeight) intWidth)
    (princ)
    )
     
    Matt W, Mar 4, 2004
    #1
  2. *****
    Option Explicit

    Public Sub Ellipse()
    Dim dblHeight As Double
    Dim dblWidth As Double
    Dim varPt1 As Variant
    Dim dblPt2(2) As Double
    Dim varPt2 As Variant
    Dim dblRatio As Double
    Dim objEnt As AcadEllipse
    dblHeight = ThisDrawing.Utility.GetReal("Enter an Height: ")
    dblWidth = ThisDrawing.Utility.GetReal("Enter an Width: ")
    On Error GoTo ErrorHandler
    varPt1 = ThisDrawing.Utility.GetPoint(, "Pick Point: ")
    On Error GoTo 0
    dblPt2(0) = varPt1(0)
    dblPt2(1) = varPt1(1) + dblHeight
    dblPt2(2) = varPt1(2)
    varPt2 = dblPt2
    dblRatio = dblWidth / dblHeight
    Set objEnt = ThisDrawing.ModelSpace.AddEllipse(varPt1, varPt2, dblRatio)
    objEnt.Move varPt1, varPt2
    Exit Sub
    ErrorHandler:
    Resume
    End Sub
    *****
    Regards - Nathan
     
    Nathan Taylor, Mar 4, 2004
    #2
  3. Matt W

    jbryant4 Guest

    Wow....VBA required about 5 times amount of code!
     
    jbryant4, Mar 4, 2004
    #3
  4. Matt W

    Matt W Guest

    Why is it that when I run this code, the ellipse is drawn rotated??!?
     
    Matt W, Mar 4, 2004
    #4
  5. Here you go, Matt.
    I was about to defend VBA against jbryant's wisecrack earlier today, but now
    I'm glad I didn't. You actually have to compare the height and width to see
    which is greater, and use that one in the AddEllipse method. The reason it
    was creating a rotated ellipse for you was that the major axis point (2nd
    param of AddEllipse) is given relative to the center, not relative to the
    origin. The HLP file sure doesn't mention that little factoid....

    James


    Public Sub Ellipse()
    Dim dblHeight As Double
    Dim dblWidth As Double
    Dim varPt1 As Variant
    Dim varPt2 As Variant
    Dim dblRatio As Double
    Dim objEnt As AcadEllipse
    dblHeight = ThisDrawing.Utility.GetReal("Enter an Height: ")
    dblWidth = ThisDrawing.Utility.GetReal("Enter an Width: ")
    On Error GoTo ErrorHandler
    varPt1 = ThisDrawing.Utility.GetPoint(, "Pick Point: ")
    On Error GoTo 0
    If dblHeight >= dblWidth Then
    varPt2 = Point3D(0, dblHeight / 2, 0)
    dblRatio = dblWidth / dblHeight
    Set objEnt = ThisDrawing.ModelSpace.AddEllipse(varPt1, varPt2, dblRatio)
    objEnt.Move Point3D(0, 0, 0), varPt2
    Else
    varPt2 = Point3D(dblWidth / 2, 0, 0)
    dblRatio = dblHeight / dblWidth
    Set objEnt = ThisDrawing.ModelSpace.AddEllipse(varPt1, varPt2, dblRatio)
    objEnt.Move Point3D(0, 0, 0), Point3D(0, dblHeight / 2, 0)
    End If
    Exit Sub
    ErrorHandler:
    Resume
    End Sub

    Public Function Point3D(x As Double, Y As Double, Optional Z As Double = 0)
    As Variant
    ' courtesy www.acadx.com
    Dim retVal(0 To 2) As Double
    retVal(0) = x: retVal(1) = Y: retVal(2) = Z
    Point3D = retVal
    End Function
     
    James Belshan, Mar 4, 2004
    #5
  6. Matt W

    Matt W Guest

    No... the HLP file DOESN'T mention that.
    Thanks!
     
    Matt W, Mar 4, 2004
    #6
  7. Matt W

    jbryant4 Guest

    Didn't intend for my comment to be taken as a wise-crack, however, this is a perfect example of the beauty of Lisp. No overhead garbage to deal with, just do it. I know there are alot of things Lisp can't do that VBA can, however it has been, and still is, an almost perfct fit language for customizing AutoCAD. The Vlax routines can typically reducelines of code even more.
     
    jbryant4, Mar 4, 2004
    #7
  8. Matt W

    Tim J Guest

    I agree with you somewhat, however we are not exactly comparing apples to
    apples here. The VBA code is complete. The lisp code is not. You do not
    see the 2 setq's for the values passed to the defun. There is no error
    handling in the lisp code and there is in the VBA code. And finally, if you
    do not use Option Explicit the code is reduced even more. (Although I would
    never, ever recommend programming without Option Explicit).

    Anyway, you are correct, though, that lisp will under a lot of circumstances
    be shorter. Try adding a form with a couple of text boxes for width and
    height and see which is shorter (and quicker to program) - lisp with DCL or
    VBA.
     
    Tim J, Mar 5, 2004
    #8
  9. Hi,

    You should watch some new users of AutoCAD starting a command and looking
    every where but at the command line. While lisp is wonderful at doing
    things, it's command line user interface is unforgiving of errors in user
    data entry. Writing interfaces via DCL is more than an order of magnitude
    more difficult than with VBA, as well as it cannot provide the same range of
    controls.

    Also, lisp is far more difficult to debug with the tools supplied by
    Autodesk.


    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au



    a perfect example of the beauty of Lisp. No overhead garbage to deal with,
    just do it. I know there are alot of things Lisp can't do that VBA can,
    however it has been, and still is, an almost perfct fit language for
    customizing AutoCAD. The Vlax routines can typically reducelines of code
    even more.
     
    Laurie Comerford, Mar 5, 2004
    #9
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.