Jump to content

Perform hatch without superfluous requests


Recommended Posts

Posted (edited)

Hi, everybody.
It is necessary to perform hatch, regardless of the previous type of hatching.
The code performs the hatch using the previous type, not the one specified in the code.

; *********** 
(defun c:HatchUser ( / ss)
  (setq ss (ssget))
  (if ss
    (progn
(command "_.-BHATCH" "_User" "_Double" "_Yes" "0" "200" "_S" ss "" "")
        )
    )
  (princ)
)

 

HatchUserdwg.dwg

 

HatchUser.png

Edited by Nikon
Posted

Maybe use (setvar 'hpname "User") in code, sets the pattern name.

  • Thanks 1
Posted
9 hours ago, BIGAL said:

Maybe use (setvar 'hpname "User") in code, sets the pattern name.

Spacing=200, double=yes and (setvar 'hpname old_hpname) do not work in this code
Is there a solution?

(defun c:HatchUserHpn ( / ss old_hpname )
(setq old_hpname (getvar 'hpname))
 (setvar 'hpname "_User")
  (setq ss (ssget))
  (if ss
    (progn
      ;; User-defined, angle=0, spacing=200, double=yes, select objects
      (command "BHATCH" "U" "0" "200" "D" "Y" "S" ss "" "")
     ;(command "_.-BHATCH" "_U" "0" "200" "_D" "_Y" "_S" ss "" "")
    )
  )
(setvar 'hpname old_hpname)
  (princ)
)

 

Posted (edited)
59 minutes ago, Steven P said:

If it all goes wrong then entmake it....

This link might help, with the code from code ding

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/entmake-hatch-with-base-point-or-object-polyline-entity-name/td-p/8696712

Couldn't open the link...

I used the MHATCH.lsp code author VVA (2006).

; Thanks to the author VVA /2006/
(defun c:MHATCH ( /  nab cmd osm *error*)
(defun *error* (msg)(princ msg)
(if cmd (setvar "cmdecho" cmd))
(if osm (setvar "osmode" osm))
(princ))
(vl-load-com)
(setq cmd (getvar "cmdecho"))
(setq osm (getvar "osmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(setvar "hpassoc" 1)
(setq nab (ssget "_:L"))
(if 
(and nab 
(setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex nab)))))
 (foreach item lst
  (vl-catch-all-apply
    '(lambda ()
       (command "_.-bhatch" "_s" item "" ""))))) ;_foreach
(setvar "cmdecho" cmd)
(setvar "osmode" osm)
(princ))

I added two main lines
 (setvar "hpdouble" 1) - criss-cross
 (setvar "hpspace" 200) - spacing

The code is working. Perhaps there is a simpler solution.
I accept comments from the pros...

; MHATCH VVA /2006 + additions /2026
(defun c:UShatch_Doub_200 ( / nab cmd osm old_hpname old_hpang old_hpdouble old_hpspace old_hpassoc lst *error*)
  (defun *error* (msg)
    (princ msg)
    (if cmd (setvar "cmdecho" cmd))
    (if osm (setvar "osmode" osm))
    (if old_hpname (setvar "hpname" old_hpname))
    (if old_hpang (setvar "hpang" old_hpang))
    (if old_hpdouble (setvar "hpdouble" old_hpdouble))
    (if old_hpspace (setvar "hpspace" old_hpspace))
    (if old_hpassoc (setvar "hpassoc" old_hpassoc))
    (princ)
  )
  (vl-load-com)
  (setq cmd (getvar "cmdecho"))
  (setq osm (getvar "osmode"))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)

  (setq old_hpname (getvar "hpname"))
  (setq old_hpang (getvar "hpang"))
  (setq old_hpdouble (getvar "hpdouble"))
  (setq old_hpspace (getvar "hpspace"))
  (setq old_hpassoc (getvar "hpassoc"))

  (setvar "hpname" "_USER")
  (setvar "hpang" 0)
  (setvar "hpdouble" 1) 
  (setvar "hpspace" 200)
  (setvar "hpassoc" 1)

  (setq nab (ssget "_:L"))
  (if (and nab (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex nab))))
           )
    (foreach item lst
      (vl-catch-all-apply
        '(lambda ()
           (command "_.-bhatch" "_s" item "" "")
         )
       )
    )
  )

  (setvar "hpname" old_hpname)
  (setvar "hpang" old_hpang)
  (setvar "hpdouble" old_hpdouble)
  (setvar "hpspace" old_hpspace)
  (setvar "hpassoc" old_hpassoc)
  (setvar "cmdecho" cmd)
  (setvar "osmode" osm)
  (princ)
)
(princ "Type in the command prompt UShatch_Doub_200")

Thank @BIGAL, you gave me the right direction.

"Maybe use (setvar 'hpname "User") in code, sets the pattern name".

Edited by Nikon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...