Script or Lisp to change hatching

Discussion in 'AutoCAD' started by WashCaps37, Oct 11, 2004.

  1. WashCaps37

    WashCaps37 Guest

    Hello,

    I have 100's of drawings with solid hatching in them so I would like to run a script or lisp that I can run in a batch process. I need to change the hatching to ANSI37 to a scale of 0.5. How would one write a script or lisp to go about selecting just the solid hatching and changing it to ANSI 37 to a scale of 0.5?

    Thank You!
     
    WashCaps37, Oct 11, 2004
    #1
  2. WashCaps37

    BillZ Guest

    One way would be to load a lisp form the script:

    "(load \"c:/change_hatch\")"
    "(change_hatch)"

    Then have your hatch change routine filed in the search path:
    Make separate file out of this with same name.

    (defun Hatch_change (/ ss)
    (while
    (setq ss (ssget "X" '((0 . "HATCH")(2 . "SOLID"))))
    (command "hatchedit" ss "P" "ansi37" "0.5" "")
    )
    )


    Bill


    Message was edited by: BillZ
     
    BillZ, Oct 11, 2004
    #2
  3. WashCaps37

    WashCaps37 Guest

    Thank you Bill. I'll give it a try and let you know.
     
    WashCaps37, Oct 11, 2004
    #3
  4. WashCaps37

    BillZ Guest

    "(load \"c:/change_hatch\")"

    can really be:

    "(load \"change_hatch\")"

    being the routine is in the search path.

    Bill
     
    BillZ, Oct 11, 2004
    #4
  5. WashCaps37

    BillZ Guest

    Another note:

    "(load \"change_hatch\")" is snipped from a write-line so if you type this directly into a script:

    (load "c:/change_hatch")

    and

    (change_hatch)

    would be fine.

    Bill
     
    BillZ, Oct 11, 2004
    #5
  6. WashCaps37

    BillZ Guest

    As it sometimes happens with my dyslexia:

    Hatch_change NOT change_hatch


    Bill
     
    BillZ, Oct 11, 2004
    #6
  7. WashCaps37

    WashCaps37 Guest

    Bill, when I run the lisp routine I keep getting a message saying Unknown command "HATCH_CHANGE". To resolve this issue would I remove the ( before the defun? Don't know if it makes a difference but I am running AutoCAD 2004.

    Thanks!
     
    WashCaps37, Oct 11, 2004
    #7
  8. WashCaps37

    Tom Smith Guest

    Whatever you do, don't fiddle with parentheses! The number of opening and
    closing parentheses must match exactly or you kill the lisp.

    He didn't make it a "command" function. To run the function, you must
    enclose its name in parentheses (hatch_change), or else go into the file and
    add a c: before the function name, as in

    (defun c:Hatch_change .....
     
    Tom Smith, Oct 11, 2004
    #8
  9. WashCaps37

    WashCaps37 Guest

    Thanks Tom! I didn't catch the missing c: . I added the c: as you suggested and it works great!

    Both of your help is very much appreciated.
     
    WashCaps37, Oct 11, 2004
    #9
  10. WashCaps37

    Adesu Guest

    Hi WashCaps37,try my code maybe can you take it,yes my program not yet
    perfect,and at location;
    ###(setq inp2
    (getreal
    (strcat "\nENTER NEW SCALE OF HATCH" "<" info41 ">" ": ")))
    (setq inp3
    (getreal
    (strcat "\nENTER NEW ANGLE OF HATCH" "<" info52 ">" ": ")))###
    it can't changed anything if user only click enter,you must enter value
    integer.


    ; eh is stand for edit hatch
    ; Design by Ade Suharna <>
    ; 5 October 2004
    ; Program no.102/10/2004
    (defun c:eh (/ ent info2 info41 info52 inp1 inp2 inp3 ed)
    (while
    (setq ent (entget (car (entsel))))
    (setq info2 (cdr (assoc 2 ent)))
    (setq info41 (rtos (cdr (assoc 41 ent))))
    (setq info52 (rtos (cdr (assoc 52 ent))))
    (setq inp1
    (getstring
    (strcat "\nENTER NEW NAME OF HATCH PATTERN" "<" info2 ">" ": ")))
    (setq inp2
    (getreal
    (strcat "\nENTER NEW SCALE OF HATCH" "<" info41 ">" ": ")))
    (setq inp3
    (getreal
    (strcat "\nENTER NEW ANGLE OF HATCH" "<" info52 ">" ": ")))
    (setq ed1 (subst (cons 2 inp1)(assoc 2 ent) ent))
    (setq ed2 (subst (cons 41 inp2)(assoc 41 ent) ed1))
    (setq ed3 (subst (cons 52 inp3)(assoc 52 ent) ed2))
    (entmod ed3)
    )
    )
     
    Adesu, Oct 12, 2004
    #10
  11. WashCaps37

    BillZ Guest

    That's weird,

    I never had to make the routine a "command" to get it to work in a script.
    As long as I called it with (hatch_change) instead of (c:hatch_change). Is that because I was using a command (which I hardly ever do) inside the lisp?

    Thanks

    Bill
     
    BillZ, Oct 12, 2004
    #11
  12. WashCaps37

    Tom Smith Guest

    I think the OP just didn't understand how to call it, it would have worked
    as (hatch_change).
     
    Tom Smith, Oct 12, 2004
    #12
  13. WashCaps37

    BillZ Guest

    Ah ,
    I see now that I re-read things.

    Thanks

    Bill
     
    BillZ, Oct 12, 2004
    #13
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.