repeat last amount

Discussion in 'AutoCAD' started by spencer1971, Apr 30, 2004.

  1. spencer1971

    spencer1971 Guest

    I have written this lsp routine to provide a hatch to a given ucs to a selected area.

    I would like it to return the last value used for dist1 when the lsp is run more than once so the hatch can be the same. by hitting return.

    I realise this may be a bit rough as I am just staring out writing but any help would be greatly appriciated.

    Also any suggestions for tidying up the *error* corrector would be welcome. Once again v. rough as I hve been learning as I go (with a lot of help from this group)

    Many thanks



    (defun MyError (strErr)
    (setvar "OSMode" oldsnap)
    (setvar "clayer" clay)
    (command "ucs" "w")
    (princ)
    )
    (defun C:Weld (/ *ERROR*)
    (setq
    *ERROR* MyError
    oldsnap (getvar "osmode"))
    (setq
    *ERROR* MyError
    clay (getvar "clayer"))
    (setvar "osmode" 0)
    (setq dist1 (getdist "\nPick (or type) distance between hatchlines: "))
    (setq
    *ERROR* MyError
    ent (entsel "\select face of beam to weld"))
    (command "ucs" "e" ent)
    (command "-layer" "m" "defpoints" "")
    (setvar "osmode" 1)
    (setq
    *ERROR* MyError
    pt1 (getpoint "\nselect top corner of weld"))
    (setvar "osmode" 512)
    (setq
    *ERROR* MyError
    pt2 (getpoint "\nselect extent of weld"))
    (command "rectang" pt1 pt2)
    (command "-layer" "m" "HATCH" "")
    (command "-layer" "c" "RED" "" "")
    (command "hatch" "u" "45" dist1 "n" "l" "")
    (setvar "osmode" oldsnap)
    (setvar "clayer" clay)
    (command "ucs" "w")
    (princ)
    )
     
    spencer1971, Apr 30, 2004
    #1
  2. spencer1971

    bob.at Guest

    spencer

    (setq dist1 (getdist "\nPick (or type) distance between hatchlines: "))

    instaead of this line try the following:

    (setq distinp nil)
    (setq distinp (getdist (strcat "\nPick (or type) distance between hatchlines <" (rtos dist1 2 2) ">: ")))
    (if (distinp) (setq dist1 distinp))

    Why do you set your error function so mutch times? It is sufficient, if you do the setq once at the begin of the function.

    It is a good idea to define all variables as local to avoid conflicts with other routins wich use the same variable names (but do *not* do this for dist1, this must stay global)

    bob.at
     
    bob.at, Apr 30, 2004
    #2
  3. spencer1971

    Joe Burke Guest

    Bob,

    This (rtos dist1 2 2) will cause a numberp nil error on the first pass when dist1
    doesn't have a value yet.

    Joe Burke


    setq once at the begin of the function.
    routins wich use the same variable names (but do *not* do this for dist1, this must
    stay global)
     
    Joe Burke, Apr 30, 2004
    #3
  4. spencer1971

    bob.at Guest

    Thanks Joe, you're right. Normaly I set default values for my global variables so that does not happen.

    (setq distinp nil)
    (if dist1 (setq distdef (rtos dist1 2 2) (setq distdef ""))
    (setq distinp (getdist (strcat "\nPick (or type) distance between hatchlines <" distdef ">: ")))
    (if distinp (setq dist1 distinp))
     
    bob.at, Apr 30, 2004
    #4
  5. spencer1971

    spencer1971 Guest

    I pasted that in and the lsp file has stopped working. It allows you to enter a figure then stops.
     
    spencer1971, Apr 30, 2004
    #5
  6. spencer1971

    bob.at Guest

    one parenthesis is missing (at us it is friday evening and i think i should start the weekend)

    (if dist1 (setq distdef (rtos dist1 2 2)) (setq distdef ""))

    ... but it should not be possibel to load it without the closing )

    bob.at
     
    bob.at, Apr 30, 2004
    #6
  7. spencer1971

    spencer1971 Guest

    bob.at,

    you are a legend, thank you very much.

    Have a good weekend.

    spencer
     
    spencer1971, Apr 30, 2004
    #7
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.