Help with code

Discussion in 'AutoCAD' started by Aaron Cunningham, Jul 7, 2004.

  1. I'm trying to set up a button that will draw a pline and then insert a homerun arrow where I select and then pause for user input of some text. The way I have everything set up to this point works fine but I would like to add a string to set the osmode to 1 but I can't figure out what I'm doing wrong because no matter how I manipulate this code it will not work. Can anybody help me?

    ^P^C^C(setq clr clr2)(setq blkx "lh8")(setq layx "x-wire")(laysetx)(setq blk(strcat dirlght blkx))(command "pline" pause pause "")(command "insert" blk "s"(getvar "dimscale") pause pause)(setq clr clr6)(setq layx "x-text")(laysetx)(command "dtext" pause "" "")
     
    Aaron Cunningham, Jul 7, 2004
    #1
  2. (command "insert" blk "s" (getvar "dimscale") "_endp" pause pause)

    --
    R. Robert Bell


    I'm trying to set up a button that will draw a pline and then insert a
    homerun arrow where I select and then pause for user input of some text. The
    way I have everything set up to this point works fine but I would like to
    add a string to set the osmode to 1 but I can't figure out what I'm doing
    wrong because no matter how I manipulate this code it will not work. Can
    anybody help me?

    ^P^C^C(setq clr clr2)(setq blkx "lh8")(setq layx "x-wire")(laysetx)(setq
    blk(strcat dirlght blkx))(command "pline" pause pause "")(command "insert"
    blk "s"(getvar "dimscale") pause pause)(setq clr clr6)(setq layx
    "x-text")(laysetx)(command "dtext" pause "" "")
     
    R. Robert Bell, Jul 7, 2004
    #2
  3. I've tried adding this to my button but it will not work. Any other ideas?
     
    Aaron Cunningham, Jul 7, 2004
    #3
  4. In macro tablet/screen/button format (which I assume from your ^P^C^C
    beginning), you can save some code stuff most of the time by skipping the
    (command) functions and just putting in the commands, and by using a
    backslash for user input instead of "pause", and a semi-colon instead of "".

    If you're building, all inside this menu item, the block name to insert,
    there's no need to string it together from pieces; you can just put it in
    straight. Likewise with the layer setting -- I don't know (laysetx), but I
    assume it's somehow setting the current layer to the "layx" value, but you
    can do that more directly. (If blkx or layx were set somewhere else, and
    you were calling on them at this point, they'd be needed, but not as you
    have this constructed.)

    Since you don't seem to actually use the "clr" value you've set, and that's
    not familiar to me, I assume that's something to do with the current entity
    color, which can also be done with direct AutoCAD commands. (But I do
    wonder why you don't leave it at Bylayer, and let the layer determine the
    color of the entity.)

    How about:

    ^P^C^C-COLOR 2 LAYER S X-WIRE ;+
    PLINE \\;INSERT dirlghtlh8 S (getvar "dimscale") \\+
    -COLOR 6 LAYER S X-TEXT ;DTEXT \;;

    (Sorry about the Newsgroup system making double-backslash stuff underlined
    and blue.)

    If "dirlght" is a value saved elsewhere, rather than the text content of
    part of the block name, then you'd still need to use (strcat), but you can
    still do it more simply, without needing a blkx value:

    .....INSERT (strcat dirlght "lh8") S ...<etc.>

    If "dirlght" IS part of the name of the block, then you'd need it in
    quotation marks if you use it in a (strcat) function, but you can skip that
    entirely as above if there's no previously-saved value being brought in as
    part of it.

    If your homerun arrow block is defined appropriately, you could use the last
    point of the Pline as its insertion point and save the user one step:

    ^P^C^C-COLOR 2 LAYER S X-WIRE ;+
    PLINE \\;INSERT dirlghtlh8 S (getvar "dimscale") (getvar "LASTPOINT") \+
    -COLOR 6 LAYER S X-TEXT ;DTEXT \;;

    You could even give it the rotation angle for them (sort of like a reverse
    leader, where the arrow is at the last end instead of the first). If the
    arrowhead in zero-degree orientation is "pointing" to the left so its
    direction that would go back along the line is toward zero degrees, you
    could do this:

    ^P^C^C-COLOR 2 LAYER S X-WIRE ;+
    PLINE (setq pt1 (getpoint)) \\; INSERT dirlghtlh8 S +
    (getvar "dimscale") (getvar "LASTPOINT") !pt1+
    -COLOR 6 LAYER S X-TEXT ;DTEXT \;;

    You could replace the -COLOR command (with hyphen to skip the dialog box)
    with CECOLOR to do it by the system variable directly, which doesn't use the
    dialog box.

    You could also make it do a real leader in the reverse direction by saving
    both points, so it would stretch nicely if you needed that, and you could
    have it calculate the insertion point for the Dtext, and probably several
    other things....

    Kent Cooper, AIA


    homerun arrow where I select and then pause for user input of some text. The
    way I have everything set up to this point works fine but I would like to
    add a string to set the osmode to 1 but I can't figure out what I'm doing
    wrong because no matter how I manipulate this code it will not work. Can
    anybody help me?
    blk(strcat dirlght blkx))(command "pline" pause pause "")(command "insert"
    blk "s"(getvar "dimscale") pause pause)(setq clr clr6)(setq layx
    "x-text")(laysetx)(command "dtext" pause "" "")
     
    Kent Cooper, AIA, Jul 7, 2004
    #4
  5. Thanks for the info Kent. Not really what I was looking for though. These buttons are company standard and have been created long before I got here. All I want to do is use the code I have but add the endpoint snap to it somehow.
    R. Robert Bell had a suggestion and I think he is close to what I want but when I add the "_endp" to my string the button will not function? Any ideas on what to add to my existing code.
     
    Aaron Cunningham, Jul 7, 2004
    #5
  6. Please post your current macro with my modification.
     
    R. Robert Bell, Jul 7, 2004
    #6
  7. Is it safe to assume that the Endpoint you want to snap to is the second end
    of the Pline you just drew? If so, you should be able to just let it use
    that instead of asking the user:

    (command "insert" blk "s" (getvar "dimscale") (getvar "lastpoint") pause)

    If not, I don't have any better idea than Bob's, or any idea why his
    suggestion doesn't work.

    Kent Cooper, AIA


    buttons are company standard and have been created long before I got here.
    All I want to do is use the code I have but add the endpoint snap to it
    somehow.
    when I add the "_endp" to my string the button will not function? Any ideas
    on what to add to my existing code.
     
    Kent Cooper, AIA, Jul 7, 2004
    #7
  8. This is what I have so far. Robert what I can't figure out is if I would just paste what you have posted on the command line it will run just like I need it to. But if I put it with the rest of the code the button will not work. What I mean by not working is that it will not produce anything when clicked. I can just keep on clicking the button and it will bring blank lines across the command prompt.

    ^P^C^C(setq clr clr2)(setq blkx "lh8")(setq layx "x-wire")(laysetx)(setq blk(strcat dirlght blkx))(command "pline" pause pause "")(command "insert" blk "s" (getvar "dimscale") "_endp" pause pause)(setq clr clr6)(setq layx "x-text")(laysetx)(command "dtext" pause "" "")
     
    Aaron Cunningham, Jul 7, 2004
    #8
  9. Aaron,

    Since I don't have all your subrs, I stripped it down to this:
    ^C^C^P(command "._pline" pause pause "")(command "._insert" "W:/Sym/N" "_s"
    (getvar "dimscale") "_endp" pause pause)(command "._dtext" pause "" "")

    ....which worked just fine. The block was inserted using the EndP OSnap and
    the DText started. Perhaps you should remove the ^P during your debug and
    post the results of the command line.


    --
    R. Robert Bell


    This is what I have so far. Robert what I can't figure out is if I would
    just paste what you have posted on the command line it will run just like I
    need it to. But if I put it with the rest of the code the button will not
    work. What I mean by not working is that it will not produce anything when
    clicked. I can just keep on clicking the button and it will bring blank
    lines across the command prompt.

    ^P^C^C(setq clr clr2)(setq blkx "lh8")(setq layx "x-wire")(laysetx)(setq
    blk(strcat dirlght blkx))(command "pline" pause pause "")(command "insert"
    blk "s" (getvar "dimscale") "_endp" pause pause)(setq clr clr6)(setq layx
    "x-text")(laysetx)(command "dtext" pause "" "")
     
    R. Robert Bell, Jul 7, 2004
    #9
  10. Aaron Cunningham

    Doug Broad Guest

    Aaron,
    AFAIK, you can't use pause in menu items or toolbar buttons macros.
    You have 2 choices:
    1) Do as Kent suggested - think like a script - don't use (command ...)
    and use \ for pause
    2) create an associated .mnl file and put your lisp routines there, wrapping
    the entire sequence with a defun. Then assign the name of the routine
    to the toolbar button.



    will run just like I need it to. But if I put it with the rest of the code the button will not work. What I mean by not working is
    that it will not produce anything when clicked. I can just keep on clicking the button and it will bring blank lines across the
    command prompt.
    "")(command "insert" blk "s" (getvar "dimscale") "_endp" pause pause)(setq clr clr6)(setq layx "x-text")(laysetx)(command "dtext"
    pause "" "")
     
    Doug Broad, Jul 7, 2004
    #10
  11. Is there any chance this is at the very END of a menu file? If so, it may
    need a return at the end, rather than ending with that last right
    parenthesis. I know some kinds of files are sensitive to that (hatch
    pattern files, specifically), but I'm not sure about menus.

    Kent Cooper, AIA


    What I mean by not working is that it will not produce anything when
    clicked. I can just keep on clicking the button and it will bring blank
    lines across the command prompt.
    ....
     
    Kent Cooper, AIA, Jul 7, 2004
    #11
  12. I had trouble once with some older routines that were quite long, and didn't
    work in 2000 or later until I divided them each into two smaller doses (one
    to get user input, the other to do the stuff with it). But even the smaller
    doses are a lot longer than this. On the other hand, they are at least
    broken up into reasonable-length lines with + signs, so although they feed
    more into the system at once, they don't (maybe) feed in that much on one
    line of entry. Have you tried putting a plus sign in the middle of the
    whole thing and dividing it into two lines? It may not make any difference,
    because I think one of those other .mn<some-letter-or-other> files puts
    multiple-line items back together into single lines.

    It makes me curious as to whether something like my suggested shortened
    version would work, but that wouldn't really answer your question unless the
    reason it works is simply that it's shorter.

    Kent Cooper, AIA


    to be a certain amount of text that can be entered on the command line. When
    I took out the ^p and ran the code it stops in the middle of the dtext
    function. I have pasted what it looks like. Is there a limitation on the
    amount of text that can be entered on the command line?
     
    Kent Cooper, AIA, Jul 7, 2004
    #12
  13. Adding a plus (+) didn't work. There has to be some limitation because with adding the plus my code now looks like:

    (setq clr clr2)(setq blkx "lh8")(setq layx "x-wire")(laysetx)(setq
    blk(strcat dirlght blkx))+(command "pline" pause pause "")(command "insert" blk
    "s" (getvar "dimscale") "_endp" pause pause)(setq clr clr6)(setq layx
    "x-text")(laysetx)(command "text" "s" "
     
    Aaron Cunningham, Jul 7, 2004
    #13
  14. Simple enough to handle. Just add a semi-colon (;) between each paren, e.g.:
    (setq clr clr2);(setq blkx "lh8");(setq layx "x-wire");(...


    --
    R. Robert Bell


    Not at the end of a menu file. What I have discovered is that there seems to
    be a certain amount of text that can be entered on the command line. When I
    took out the ^p and ran the code it stops in the middle of the dtext
    function. I have pasted what it looks like. Is there a limitation on the
    amount of text that can be entered on the command line?

    (setq clr clr2)(setq blkx "lh8")(setq layx "x-wire")(laysetx)(setq
    blk(strcat dirlght blkx))(command "pline" pause pause "")(command "insert"
    blk
    "s" (getvar "dimscale") "_endp" pause pause)(setq clr clr6)(setq layx
    "x-text")(laysetx)(command "text" "s" "b
     
    R. Robert Bell, Jul 7, 2004
    #14
  15. Did you add the plus sign AND hit Enter to physically make it two lines? I
    did look in Help, and it says "Line breaks are not preserved when AutoCAD
    creates the MNS file." It presumably would remove the plus sign in the
    process, which makes me wonder whether you put the Enter in, since the plus
    sign appears below. If all you did was add a plus sign, without Enter, it
    probably wouldn't do the trick (IF the trick is even the solution to the
    problem, which it may not be). And it would explain the end result below
    having one character less at the end (missing the b that was there before),
    since there's one character more earlier on.

    Kent Cooper, AIA


    with adding the plus my code now looks like:
     
    Kent Cooper, AIA, Jul 7, 2004
    #15
  16. Well, I'll be fascinated to know whether that does the trick. (If so,
    spaces would work, too, and I usually write this stuff with spaces just
    because it seems easier to read.) But I'll sure wonder WHY it makes the
    difference! Especially if the routine used to work without anything between
    them, before putting the endpoint osnap call in there broke the camel's
    back.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Jul 7, 2004
    #16
  17. From the looks of the command line, the entire menu macro is being stuffed
    there, and it doesn't all make it. Adding the semi-colons makes each
    AutoLISP statement a separate command so it should avoid that problem. I
    prefer semi-colons since it is easier to count those than multiple spaces
    where more than one <Enter> is needed.

    --
    R. Robert Bell


    Well, I'll be fascinated to know whether that does the trick. (If so,
    spaces would work, too, and I usually write this stuff with spaces just
    because it seems easier to read.) But I'll sure wonder WHY it makes the
    difference! Especially if the routine used to work without anything between
    them, before putting the endpoint osnap call in there broke the camel's
    back.

    Kent Cooper, AIA


    ...
     
    R. Robert Bell, Jul 8, 2004
    #17
  18. There's not much advantage to stuffing a menu macro with LISP code,
    so while semi-colons might make it work, that doesn't make it right.

    You would still be better served if you just defined a custom command
    in the menu's .MNL file, and then issued it in the macro. One obvious
    advantage to that is that it makes the entire command repeatable using
    the ENTER key.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning


    with adding the plus my code now looks like:
     
    Tony Tanzillo, Jul 8, 2004
    #18
  19. Kent and Robert,

    Thank you for your help. I've tried all the suggestions about putting in + or ; and I stiil cannot get it to read the entire code. So this is what I've done and seems to be working fine. I would like to add a way to check if text style "ba" is created and if not create the style.

    As you have probally figured out I'm not very good at creating lisp routines so any help is appreciated.

    (defun c:hrun ()
    (setq clr clr2)
    (setq blkx "lh8")
    (setq layx "x-wire")
    (laysetx)
    (setq blk(strcat dirlght blkx))
    (command "pline" pause pause "")
    (command "insert" blk "s" (getvar "dimscale") (getvar "lastpoint") "_endp" pause)
    (setq clr clr6)
    (setq layx "x-text")
    (laysetx)
    (command "dtext" "s" "ba" pause """")
    (laybac))
     
    Aaron Cunningham, Jul 8, 2004
    #19
  20. (tblsearch) is the function you needto use.

    --
    R. Robert Bell


    Kent and Robert,

    Thank you for your help. I've tried all the suggestions about putting in +
    or ; and I stiil cannot get it to read the entire code. So this is what I've
    done and seems to be working fine. I would like to add a way to check if
    text style "ba" is created and if not create the style.

    As you have probally figured out I'm not very good at creating lisp routines
    so any help is appreciated.

    (defun c:hrun ()
    (setq clr clr2)
    (setq blkx "lh8")
    (setq layx "x-wire")
    (laysetx)
    (setq blk(strcat dirlght blkx))
    (command "pline" pause pause "")
    (command "insert" blk "s" (getvar "dimscale") (getvar "lastpoint") "_endp"
    pause)
    (setq clr clr6)
    (setq layx "x-text")
    (laysetx)
    (command "dtext" "s" "ba" pause """")
    (laybac))
     
    R. Robert Bell, Jul 8, 2004
    #20
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.