Length Calculations

Discussion in 'AutoCAD' started by Kumar, Feb 27, 2004.

  1. Kumar

    Kumar Guest

    Hi every body,
    I am using VBA for automation of drawing. In this I am drawing a line.To draw a line using VBA, you need to enter Strat Point & End Point. For general cases, I have length of line and its angle of full circle bearing. For example--I want to darw-
    @100'<156d24'45"

    But in VBA, i need to enter start point and end point. I tried it using Trigometric formula, to get the end point as i am provided with length and its angle. But could not generalize formula for all angles.
    Does any body have generalized method to find end point from start point for all angles?
    or
    It can be directly draw a line with length and angle in VBA?

    Second problem--
    How can set preferences like direction of angles(By default for my template is east, but i want to make it North, want to measure clockwise) using VBA.
     
    Kumar, Feb 27, 2004
    #1
  2. Kumar,

    In addition to any replies you might receive or already
    received, you may find more information or responses
    by posting future VBA related questions in the following
    discussion group:

    By NNTP discussion group reader at
    news://discussion.autodesk.com/autodesk.autocad.customization.vba

    By HTTP (web-based) interface at
    http://discussion.autodesk.com/forum.jspa?forumID=33

    --

    -Jason
    Member of the Autodesk Discussion Forum Moderator Program


    <snip>
     
    Jason Piercey, Feb 27, 2004
    #2
  3. Kumar

    Dean McCarns Guest

    Kumar;

    LISP, LISP, LISP - VBA and VB have there places but not with this simple
    item. This function will allow you to pass the function a point, angle and
    length to draw the line:

    (I am assuming this is an internal function and not a command that a user
    will type in at the command line)

    ;; Required Arguments
    ;; pt1 - a typical point list (e.g. '(0.0 0.0 0.0))
    ;; ang - an angle (e.g. 45.0)
    ;; dist - a distance (e.g. 120.0)

    (defun sf:LineByAngle ( pt1 ang dist / acdocms pt2)
    ;; required to use ActiveX VLisp functions
    (vl-load-com)

    ;; acdocms gets a pointer to the current documents model space to draw
    line
    (setq acdocms (vla-get-modelspace (vla-get-activedocument
    (vlax-get-acad-object)))

    ;; pt2 is calculated uing the POLAR function to attain the second point
    ;; it requires a starting point, an angle and distance (in that order)
    pt2 (polar pt1 ang dist))

    ;; ActiveX function to add a line to the drawing
    (vla-addLine acdocms (vlax-3d-point pt1) (vlax-3d-point pt2))

    ;; Release the pointer to the documents model space - Always do this
    (vlax-release-object acdocms)
    )

    ;; Test this function
    (sf:LineByAngle '(0.0 0.0 0.0) 45 120)

    There is no error checking here and I'm not sure if you need user input for
    this but if so let me know. We can get this done.

    Good luck.
    --
    Dean McCarns
    ESP,Inc.
    804.675.2377
    draw a line using VBA, you need to enter Strat Point & End Point. For
    general cases, I have length of line and its angle of full circle bearing.
    For example--I want to darw-
    Trigometric formula, to get the end point as i am provided with length and
    its angle. But could not generalize formula for all angles.
    template is east, but i want to make it North, want to measure clockwise)
    using VBA.
     
    Dean McCarns, Feb 29, 2004
    #3
  4. Kumar

    Dean McCarns Guest

    Kumar;

    Here is a sample user function that will illustrate the function:

    (defun c:KL ( / *Error* upt uang udist cpt)
    (defun *Error* (msg)
    (if (= msg "Function cancelled")
    (setq msg "*Cancel*")
    )
    (if acdocms
    (vlax-release-object acdocms)
    (print msg)
    (princ)
    )
    (setq upt (getpoint "\nSelect start point: ")
    uang (getangle upt "\nAngle of line: ")
    udist (getdist upt "\nLength (distance) of line: ")
    )
    (sf:LineByAngle upt uang udist)
    (princ)
    )

    This function, the KL (KumarLine) function, allows the user to pick a start
    point, supply an angle (by typing or picking a point), supply a distance
    (again by typing or picking), passess the user supplied point, angle and
    distance to the sf:LineByAngle function and draws the line into modelspace
    as needed. (I added a very simplistic error handler - also notice that I
    declair the acdocms pointer as a local variable in the sub-function but
    check for and release it in the error handler - its a bit redundent, but you
    can never be too carefull).

    You could simply addapt this function for multiple points as well but thats
    a whole nother bag of worms.

    Good luck.
     
    Dean McCarns, Feb 29, 2004
    #4
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.