Results 1 to 6 of 6

Thread: Hatch Pattern Background Color Lisp

  1. #1
    Member
    Join Date
    2023-12
    Posts
    3
    Login to Give a bone
    0

    Default Hatch Pattern Background Color Lisp

    I am looking to streamline our background conversion process. I have everything working that I want so far. However, I am looking to script something that changes the Hatch --> Pattern --> Background Color to None. I have tried multiple lisps and even utilized chat GPT (awesome tool BTW). See below for what I have tried to start along with a screenshot of the parameter I am trying to change. Any assistance would be greatly appreciated.

    Code:
    (defun c:ChangeAllHatchesToNone ()
      (vl-load-com)
      (setq ss (ssget '((0 . "HATCH"))))
      (if ss
        (progn
          (setq i 0)
          (repeat (sslength ss)
            (setq ent (ssname ss i))
            (if (and ent (entget ent))
              (entmod (subst '(62 . 256) (assoc 62 (entget ent)) (entget ent))) ; 256 represents BYLAYER
            )
            (setq i (1+ i))
          )
          (princ "\nHatch pattern background color set to 'ByLayer' for selected hatches.")
        )
        (princ "\nNo hatches found.")
      )
      (princ)
    )
    Attached Images Attached Images

  2. #2
    Member
    Join Date
    2023-12
    Posts
    3
    Login to Give a bone
    0

    Default Re: Hatch Pattern Background Color Lisp

    Code:
    (setq all-hatches (ssget "_X" '((0 . "HATCH"))))
      (if all-hatches
        (progn
          (setq total-hatches (sslength all-hatches))
          (setq counter 0)
          (while (< counter total-hatches)
            (setq hatch (ssname all-hatches counter))
            
            ; Change the hatch fill to none for each hatch individually
            (command "-HATCHEDIT" hatch "CO" "." ".")
            
            (setq counter (1+ counter))
          )
          (princ (strcat "\n" (itoa total-hatches) " hatches modified."))
        )
        (princ "\nNo hatches found.")
      )
      (princ)
    )
    Last edited by Ed Jobe; 2023-12-11 at 05:34 PM.

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,421
    Login to Give a bone
    0

    Default Re: Hatch Pattern Background Color Lisp

    When trying to figure out the dxf codes for properties, you can learn a lot by inspecting entities in the drawing. For that, I wrote ENTLIST. In this case, the background color is stored as xdata.

    Code:
    ;;; Entlist.lsp
    ;;; Ed Jobe c 2002
    ;;; list the dxf codes of an entity.
    ;;; optional list of xdata.
    
    (defun C:EntList (/ ename elist resp)
      (initget "Yes No")
      (setq resp (getkword "\nInclude xdata? [Yes/No] <No>: "))
      (princ resp)
      (if (or (= resp "No") (= resp nil))
        (progn
          (setq ename (car (entsel)))
          (setq elist (entget ename))
          (princ elist)
          (princ)
        )
        (progn
          (setq ename (car (entsel)))
          (setq elist (entget ename '("*")))
          (princ elist)
          (princ)
        )
      )
    )
    C:> ED WORKING....


    LinkedIn

  4. #4
    Member
    Join Date
    2023-12
    Posts
    3
    Login to Give a bone
    0

    Default Re: Hatch Pattern Background Color Lisp

    Quote Originally Posted by Ed Jobe View Post
    When trying to figure out the dxf codes for properties, you can learn a lot by inspecting entities in the drawing. For that, I wrote ENTLIST. In this case, the background color is stored as xdata.

    Code:
    ;;; Entlist.lsp
    ;;; Ed Jobe c 2002
    ;;; list the dxf codes of an entity.
    ;;; optional list of xdata.
    
    (defun C:EntList (/ ename elist resp)
      (initget "Yes No")
      (setq resp (getkword "\nInclude xdata? [Yes/No] <No>: "))
      (princ resp)
      (if (or (= resp "No") (= resp nil))
        (progn
          (setq ename (car (entsel)))
          (setq elist (entget ename))
          (princ elist)
          (princ)
        )
        (progn
          (setq ename (car (entsel)))
          (setq elist (entget ename '("*")))
          (princ elist)
          (princ)
        )
      )
    )
    Ed, I am somewhat self taught with a lot of help from the community. Thank you for this. I will test it out! Have/do you work with any "batch" scrip programs? I just downloaded ScriptPro via autodesk. Initially I really liked it but it does seem a bit clunky. I also say that Lee Mac has a lisp that works similar to ScriptPro. Just trying to run a .scr on multiple (25-150) drawings at a time. This will help speed up our dept when setting up 2D backgrounds.

  5. #5
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,421
    Login to Give a bone
    0

    Default Re: Hatch Pattern Background Color Lisp

    Yes, I've used ScriptPro. I don't know what you mean by clunky. It is simple though. But all it needs to do is run scripts on a batch of files. I haven't tried Lee's tool. ScriptPro did what I needed. These days I tend to write my own commands to do what I want rather than a script. There are faster methods of batching than opening each dwg in the gui, like if you use accoreconsole, but there's no gui like ScriptPro for it, that I know of. ScriptPro is easy to use, no learning curve. If you do a lot of scripts, you might search the vba forum for my ScriptMgr command.
    C:> ED WORKING....


    LinkedIn

  6. #6
    Woo! Hoo! my 1st post
    Join Date
    2016-04
    Posts
    1
    Login to Give a bone
    0

    Default Re: Hatch Pattern Background Color Lisp

    Hi,

    Maybe a bit late but still might help some.
    Try to use this code (Code written by ronjomp found ):

    Code:
    (defun c:test (/ c a d)
      (vl-load-com)
      (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
        (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
      )
      (vlax-for b (vla-get-blocks d)
        (if (= 0 (vlax-get b 'isxref))
          (vlax-for o b
            (cond
              ((and (vlax-write-enabled-p o) (= (vla-get-objectname o) "AcDbHatch"))
               (or c (progn (setq c (vla-get-backgroundcolor o)) (vla-put-entitycolor c -939524096)))
               (vla-put-backgroundcolor o c)
              )
            )
          )
        )
      )
      (foreach l a (vlax-put l 'lock -1))
      (vla-regen d acallviewports)
      (princ)
    )
    Cheers

Similar Threads

  1. Wishing for Background solid hatch color
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2013-03-14, 04:54 PM
  2. Change command line background color lisp
    By Dave Lewis in forum AutoLISP
    Replies: 1
    Last Post: 2012-08-07, 07:17 PM
  3. Hatch pattern - error in reading pattern file
    By bbapties in forum AutoCAD Customization
    Replies: 10
    Last Post: 2011-04-01, 11:40 PM
  4. Changing background color via Lisp
    By cadconcepts in forum AutoLISP
    Replies: 6
    Last Post: 2011-02-07, 07:31 PM
  5. Replies: 5
    Last Post: 2006-02-28, 01:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •