Text Offset...

Discussion in 'AutoCAD' started by Mugenlude, Dec 3, 2004.

  1. Mugenlude

    Mugenlude Guest

    I have a lsp that I use to insert seqential numbers into a room or door schedule, it's pretty basic.

    (defun c:brsobjno ()
    (setq a (getint "Enter First Number:"))(terpri)
    (setq x 1)
    (while x
    (command "-layer" "set" "A-Text" "")(terpri)
    (command "-color" "BYLAYER" "")(terpri)
    (command "text" "j" "mc" pause "0" a)(terpri)
    (setq a (+ a 1))
    (princ)(terpri)
    )
    )

    They way it is written now it prompts me for an insertion point for each piece of text.

    What I want to do is prompt me for one intial point (1st number at top of door schedule), then offset the remain text to a specified distance (the spacing of my door schedule).

    Probably pretty basic, but I'm just learning. =)

    Thanks in advance,
    -Jason
     
    Mugenlude, Dec 3, 2004
    #1
  2. Mugenlude

    ECCAD Guest

    (defun c:brsobjno (/ a x p1)
    (setq a (getint "Enter First Number:"))(terpri)
    (setq x 1)
    (command "-layer" "set" "A-Text" "")(terpri)
    (command "-color" "BYLAYER" "")(terpri)
    ;
    (setq p1 (getpoint "\nPick Beginning Point for Text:"))
    (while x
    (command "text" "j" "mc" p1 "0" a)(terpri)
    (setq p1 (list (+ (car p1) 0.0)(- (cadr p1) 0.25)))
    (setq a (+ a 1))
    (princ)(terpri)
    ); while
    ); function
    ---------------
    Note a few things.
    Localize variables used ... in the (defun.... line.
    For While Loop - move Layer / Color outside loop..
    Line ..(setq p1 (list (+ (car p1) 0.0)(- (cadr p1) 0.25)))...
    calculates 'next' insertion point (x of p1) + 0, (y of p1) - 0.25
    Place the 'distance' needed into (- (cadr p1) 0.??) to change
    the incremental distance..

    Bob
     
    ECCAD, Dec 3, 2004
    #2
  3. Mugenlude

    ECCAD Guest

    Now,
    You notice that this is an 'endless' loop, you need to have
    a way to 'pause' in there..
    Just after the (while...
    do:
    (setq z (getstring "\nMore..or Escape to quit.."))

    Bob
     
    ECCAD, Dec 3, 2004
    #3
  4. Mugenlude

    ECCAD Guest

    So far we have:

    (defun c:brsobjno (/ a x p1)
    (setq a (getint "Enter First Number:"))(terpri)
    (setq x 1)
    (command "-layer" "set" "A-Text" "")(terpri)
    (command "-color" "BYLAYER" "")(terpri)
    ;
    (setq p1 (getpoint "\nPick Beginning Point for Text:"))
    (while x
    (setq z (getstring "\nMore or Escape to Exit:"))
    (command "text" "j" "mc" p1 "0" a)(terpri)
    (setq p1 (list (+ (car p1) 0.0)(- (cadr p1) 0.25)))
    (setq a (+ a 1))
    (princ)(terpri)
    ); while
    ); function

    Next,
    You will want a better way to 'exit' the While loop..rather than
    just pushing on the 'ESC' key.. right?

    This example shows a more 'proper' way to do that...

    (defun c:brsobjno (/ a p1 ocmd clay osm opt)
    (setq ocmd (getvar "CMDECHO"); save old command echo.
    clay (getvar "CLAYER"); save old Layer.
    osm (getvar "OSMODE"); save Osnap Mode
    ); setq
    ;;
    (setvar "CMDECHO" 0); turn off echo of commands.
    (setvar "OSMODE" 0); turn off Osnap, set to 'none'.
    ;;
    (command "-layer" "set" "A-Text" "")
    (command "-color" "BYLAYER" "")
    (setq a (getint "Enter First Number:"))
    (setq p1 (getpoint "\nPick Beginning Point for Text:"))
    (initget "Next Exit")
    (setq opt (getkword "\n[N]ext or [E]xit <Next> "))
    (cond
    ( (= opt "Next")
    (command "text" "j" "mc" p1 "0" a)
    (setq p1 (list (+ (car p1) 0.0)(- (cadr p1) 0.25)))
    (setq a (+ a 1))
    (princ)
    )
    ); cond
    (if clay (command "-layer" "set" clay "")); restore current layer
    (setvar "OSMODE" osm)
    (setvar "CMDECHO" ocmd)
    (princ)
    ); function

    Bob
     
    ECCAD, Dec 3, 2004
    #4
  5. Mugenlude

    ECCAD Guest

    Whoops, forgot the while..
    This example shows a more 'proper' way to do that...

    (defun c:brsobjno (/ a p1 ocmd clay osm opt)
    (setq ocmd (getvar "CMDECHO"); save old command echo.
    clay (getvar "CLAYER"); save old Layer.
    osm (getvar "OSMODE"); save Osnap Mode
    ); setq
    ;;
    (setvar "CMDECHO" 0); turn off echo of commands.
    (setvar "OSMODE" 0); turn off Osnap, set to 'none'.
    ;;
    (command "-color" "BYLAYER" "")
    (command "-layer" "m" "A-Text" "")
    (setq a (getint "Enter First Number:"))
    (setq p1 (getpoint "\nPick Beginning Point for Text:"))
    (while (/= opt "Exit")
    (initget "Next Exit")
    (setq opt (getkword "\n[N]ext or [E]xit <Next> "))
    (cond
    ( (= opt "Next")
    (command "text" "j" "mc" p1 "0" a)
    (setq p1 (list (+ (car p1) 0.0)(- (cadr p1) 0.25)))
    (setq a (+ a 1))
    (princ)
    )
    ); cond
    ); while
    (if clay (command "-layer" "set" clay "")); restore current layer
    (setvar "OSMODE" osm)
    (setvar "CMDECHO" ocmd)
    (princ)
    ); function

    And, do a 'm'ake on the layer, case it doesn't exist.

    Bob
     
    ECCAD, Dec 3, 2004
    #5
  6. Mugenlude

    Mugenlude Guest

    Thank you for the detail explaination, it helps very much.

    Couple of more questions that you might be able to help me with, if you please.

    1. I modified the OSMODE to be just node because that is what is provided on our master schedule of a insertion point. Once this command is done I want to change the OSMODE back to what the user had before running this lisp. So I guess I'm looking for an undo function with the OSMODE, if there isn't one I will just remove changing OSMODE all together.

    2. When I get "[N]ext or [E]xit <Next>" on the command line hitting enter does not initiate the "Next" command, I either have to type N or E.

    Thanks again, this has been very helpful.
    -Jason
     
    Mugenlude, Dec 3, 2004
    #6
  7. Mugenlude

    ECCAD Guest

    ;; This model shows another way to get options..using
    ;; getstring & checking for "N" or "" (Enter key), Will Exit with
    ;; 'E' ........
    (defun c:brsobjno (/ a p1 ocmd clay osm opt)
    (setq ocmd (getvar "CMDECHO"); save old command echo.
    clay (getvar "CLAYER"); save old Layer.
    osm (getvar "OSMODE"); save Osnap Mode
    ); setq
    ;;
    (setvar "CMDECHO" 0); turn off echo of commands.
    ;;; (setvar "OSMODE" 0); turn off Osnap, set to 'none'.
    (setvar "OSMODE" 8);Node.
    ;;
    (command "-color" "BYLAYER" "")
    (command "-layer" "m" "A-Text" "")
    (setq a (getint "Enter First Number:"))
    (setq p1 (getpoint "\nPick Beginning Point for Text:"))
    ;; Shows different method..
    (setq opt "X"); no valid choice
    (while (/= opt "E")
    (setq opt (strcase (getstring "\n[N]ext or [E]xit <Next> "))
    (cond
    ( (= opt "")(= opt "N"))
    (command "text" "j" "mc" p1 "0" a)
    (setq p1 (list (+ (car p1) 0.0)(- (cadr p1) 0.25)))
    (setq a (+ a 1))
    (princ)
    )
    ); cond
    ); while
    (if clay (command "-layer" "set" clay "")); restore current layer
    (setvar "OSMODE" osm); restore osmode on exit..
    (setvar "CMDECHO" ocmd)
    (princ)
    ); function

    On your point about osnap.
    In the code, this line gets the 'current' osmode..
    osm (getvar "OSMODE"); save Osnap Mode
    {part of the (setq...
    On exit of the loop.....this line resets it.
    (setvar "OSMODE" osm); restore osmode on exit..

    For (internal to the program) setting of the 'node',
    do:
    (setvar "OSMODE" 8); Node
    rather than (setvar "OSMODE" 0); None..
    The program should get the current osmode, and reset it
    on exit.

    Bob
     
    ECCAD, Dec 3, 2004
    #7
  8. Mugenlude

    ECCAD Guest

    ( (= opt "")(= opt "N"))
    should be:
    ( (or (= opt "")(= opt "N"))
    Bob
     
    ECCAD, Dec 3, 2004
    #8
  9. Mugenlude

    Mugenlude Guest

    Got it... thank you very much!!!!

    -Jason
     
    Mugenlude, Dec 3, 2004
    #9
  10. Mugenlude

    ECCAD Guest

    OK,
    Bye.
    Bob
     
    ECCAD, Dec 3, 2004
    #10
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.