simple lisp help please

Discussion in 'AutoCAD' started by Pad, Aug 16, 2004.

  1. Pad

    Pad Guest

    ; Simple macro to allow easy rotating of text
    ; sets direction to 0 and clockwise to n so that crosshairs run parallel
    ; with the rotated object. resets direction and clockwise at end for key
    ; template

    (defun C:met-rt()
    (setvar "CMDECHO" 0)

    ; change direction to 0 and clockwise to n
    (command "units" "" "" "" "" "0" "n" "")

    ; rotate command
    (command "rotate" )

    ; change direction back to 270 and clockwise to y
    (command "units" "" "" "" "" "90" "y" "")

    (setvar "CMDECHO" 1)
    (princ)
    )

    problem is that it doesnt work!
    i dont understand why, my lisp knowledge is rather limited.

    thanks

    pad
     
    Pad, Aug 16, 2004
    #1
  2. Pad

    morrisde Guest

    the rotate call is a little sparse! look at how the rotate command runs in autocad - it requires object(s), a base point and an angle.

    Regards
    Dave
     
    morrisde, Aug 16, 2004
    #2
  3. Pad

    Pad Guest

    thanks dave
    ive added a little to the lisp:

    (defun C:met-rt()
    (setvar "CMDECHO" 0)

    ; change direction to 0 and clockwise to n
    (command "units" "" "" "" "" "0" "n" "")

    (setq t (entsel "Select text: ") )

    (command "rotate" t "" "" )

    ; change direction back to 270 and clockwise to y
    (command "units" "" "" "" "" "90" "y" "")

    (setvar "CMDECHO" 1)
    (princ)
    )


    the rotation seems to work, the problem now is the resetting of the units
    at the end. it just doesnt happen??



    in autocad - it requires object(s), a base point and an angle.
     
    Pad, Aug 16, 2004
    #3
  4. Pad

    Pad Guest

    Thanks Jon

    very helpful
    unfortunately i'm still getting the problem with the units not being reset
    at the end.
    ive tried the pause command just before (command "units" "" "" "" "" "90"
    "y" "")
    but its still not doing it.
    argh!
    its necessary because many of the other lisps i use need the units set up
    with north as 0 and clockwise angles.

    this is the commandline output when running the lisp:

    Command: met-rt

    Select objects: 1 found

    Select objects: Unknown command "MET-RT". Press F1 for help.

    Invalid point.
    Function cancelled
    Specify base point:
    Specify rotation angle or [Reference]:
    Command:

    i should note that i'm using acad2002, maybe upgrade in a couple of months
    time.

    cheers
    pad
     
    Pad, Aug 16, 2004
    #4
  5. Pad

    OLD-CADaver Guest

    What exactly are you trying to do?

    (setq currentrotangle (cdr (assoc 50 (entget (car (entsel))))))

    Will retrieve the rotation angle in radians. Look into ENTMOD and radians to degrees conversions.
     
    OLD-CADaver, Aug 16, 2004
    #5
  6. Pad

    Pad Guest

    basically its a lisp to speed up the rotating of text/blocks along lines.
    our standard template has north as 0 and clockwise angles so this means when
    rotating text/blocks the cross hairs run at 90 deg to the text/blocks.
    with the template changed to 90 and clockwise off the crosshairs run
    parallel to the text/block being rotated which makes it easier to eye in.

    the lisp wants to

    a) set template to (command "units" "" "" "" "" "0" "n" "")

    b) rotate selected object/text

    c) set template to (command "units" "" "" "" "" "90" "y" "")

    d) end

    thats all no conversion necessary

    but i cant get the damn thing to work though ;o(

    pad



    to degrees conversions.
     
    Pad, Aug 16, 2004
    #6
  7. Pad

    OLD-CADaver Guest

    <<b) rotate selected object/text>>

    Rotated to what?
     
    OLD-CADaver, Aug 16, 2004
    #7
  8. Pad

    Pad Guest

    maybe along a line or rotated to any angle of my choice.

    its for landsurvey drawings.
     
    Pad, Aug 16, 2004
    #8
  9. Pad

    Pad Guest

    to whatever i choose it to be with my mouse
    or to the angle of an adjacent poly line.

    thanks
    pad
     
    Pad, Aug 16, 2004
    #9
  10. Pad

    OLD-CADaver Guest

    Then you need to pause the routine to allow you to select the base point, get the current angle and get a point for the rotation angle.

    Getting the current angle, accurately, will require getting the association code 50 of the selected text and converting it to degrees.
     
    OLD-CADaver, Aug 16, 2004
    #10
  11. Pad

    Pad Guest

    the rotation seems to work well enough now, its not required to be very
    accurate just visually accurate at plotting scales of 1:50 to 1:500.

    the problem i'm faced with now is the resetting of the template, it for some
    reason will not work.
    i need to find a lisp book i think.

    (defun C:met-rt (/ SelectionSet)
    (setq SelectionSet (ssget))
    ;; If something was selected ...
    (if SelectionSet
    ;; Do it
    (progn
    (setvar "CMDECHO" 0)
    ;; change direction to 0 and clockwise to n
    (command "units" "" "" "" "" "0" "n" "")

    ;; rotate command
    (command "rotate" SelectionSet "" "")

    ;; change direction back to 270 and clockwise to y
    (command "units" "" "" "" "" "90" "y" "")

    (setvar "CMDECHO" 1)
    )
    ;; Otherwise ...
    (alert "Nothing selected!")
    )
    (princ)
    )

    thanks for your help its appreciated.




    get the current angle and get a point for the rotation angle.
    association code 50 of the selected text and converting it to degrees.
     
    Pad, Aug 16, 2004
    #11
  12. Pad

    Doug Broad Guest

    When I first started doing site plans, I thought I should use North=0
    and angles clockwise, but soon discovered that Surveyor's units
    scheme was designed for the units allowed to remain East=0 and
    angles measured CCW. If you leave the units scheme that way, when
    you key in line 0,0 @12<N , you will find that North still goes up and
    that all other angle directions perform well.

    Then you don't have to worry about text rotation.
     
    Doug Broad, Aug 16, 2004
    #12
  13. Pad

    Pad Guest

    i hear what your saying doug
    i use a fair lisp routines and they rely on north being 0
    using (command "units" "" "" "" "" "0" "n" "") has worked on lisp routines
    for me in the past.
    so i am stuck with using north as 0 and clockwise.

    its no big deal, it would have been a nice little routine to speed up the
    presentation of the text.

    cheers
     
    Pad, Aug 16, 2004
    #13
  14. Pad

    OLD-CADaver Guest

    <<the problem i'm faced with now is the resetting of the template, it for some reason will not work.>>

    Resetting what in the template? What template?
     
    OLD-CADaver, Aug 16, 2004
    #14
  15. Pad

    Pad Guest

    the drawing template.

    i have to use units set at north 0 and clockwise angles.

    if you look at this lisp:

    (defun C:met-rt (/ SelectionSet)
    (setq SelectionSet (ssget))
    ;; If something was selected ...
    (if SelectionSet
    ;; Do it
    (progn
    (setvar "CMDECHO" 0)
    ;; change direction to 0 and clockwise to n
    (command "units" "" "" "" "" "0" "n" "")

    ;; rotate command
    (command "rotate" SelectionSet "" "")

    ;; change direction back to 270 and clockwise to y
    (command "units" "" "" "" "" "90" "y" "")

    (setvar "CMDECHO" 1)
    )
    ;; Otherwise ...
    (alert "Nothing selected!")
    )
    (princ)
    )


    you will see that the units are first changed to east as 0 and counter
    clockwise angle (command "units" "" "" "" "" "0" "n"
    "")
    then the rotation command is used
    then
    the units are changed to 0 as north and clockwise angles for compatibility
    with my other lisp routines.
    this is the bit that isnt working (command "units" "" "" "" "" "90" "y" "")


    ok i wont mention templates again it has seemed to confuse things
     
    Pad, Aug 16, 2004
    #15
  16. Pad

    Doug Broad Guest

    This should work for you. I took John's and added some
    (defun C:met-rt (/ SelectionSet)
    (setq SelectionSet (ssget))
    ;; If something was selected ...
    (if SelectionSet
    ;; Do it
    (progn
    (setvar "CMDECHO" 0)
    ;; change direction to 0 and clockwise to n
    (command "units" "" "" "" "" "0" "n" )
    ;; rotate command
    (command "rotate" selectionset "")
    (while (= 1 (getvar "cmdactive"))
    (command pause))
    ;; change direction back to 270 and clockwise to y
    (command "units" "" "" "" "" "90" "y")
    (setvar "CMDECHO" 1)
    )
    ;; Otherwise ...
    (alert "Nothing selctied!")
    )
    (princ)
    )


    You could also do the rotate like
    (command "rotate" selectionset "" pause pause)


    "Pad" <
     
    Doug Broad, Aug 16, 2004
    #16
  17. Pad

    Pad Guest

    that is the one, works a treat!

    thank you very much both John and Doug

    excellent stuff.
     
    Pad, Aug 16, 2004
    #17
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.