This is a testing version only but it seems to work. I wonder what CAD wizard made this mess of a detail library
(vl-load-com)
;;
;; Fix the extrusuion values of hatches so they are 0,0,1
;;
;; TESTING VERSION
;;
;; Thread here: https://www.cadtutor.net/forum/topic/92094-flatten-issue-with-drawing
;;
;; 3dwannab 2024.10.08
;;
;; TO DO:
;; - Make this work for ENTITIES inside BLOCKS
;;
(defun c:FXHatchExtrusion_To_0 (/ *error* acDoc cnt dxf210 ent entData newEntData newExtrude newExtrudeVal obj oldExtrude ss typ var_cmdecho)
(defun *error* (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " errmsg " >>\n"))
)
(setvar 'cmdecho var_cmdecho)
)
;; Start the undo mark here
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
;; Get any system variables here
(setq var_cmdecho (getvar "cmdecho"))
(setvar 'cmdecho 0)
(if (setq ss (ssget "_:L" '((0 . "HATCH"))))
(progn
(repeat (setq cnt (sslength ss))
(setq cnt (1- cnt))
(setq ent (_dxf -1 (entget (ssname ss cnt))))
(setq entData (entget ent)) ; Get the entity's data list
(setq obj (vlax-ename->vla-object ent))
(setq typ (cdr (assoc 0 (entget ent))))
(cond
;; Placeholder condition for other entities
; ((= typ "**")
; ) ;; end cond
;; Condition for HATCHES.
((= typ "HATCH")
(setq newExtrudeVal 0.0) ; Set this to 0.0
(if (setq dxf210 (assoc 210 entData))
(progn
(setq oldExtrude (cdr dxf210)) ;; Extract the current extrude components
(setq newExtrude (list (nth 0 oldExtrude) newExtrudeVal (nth 2 oldExtrude))) ;; Create the new extrude with the modified Y component
(setq newEntData (subst (cons 210 newExtrude) dxf210 entData)) ;; Replace the old extrude with the new extrude
(entmod newEntData) ;; Apply the changes to the HATCH entity
(entupd ent) ; Update the entity to reflect the change
)
)
) ;; end cond HATCH
)
)
) ;; progn
) ;; if ssget
(if ss
(progn
(princ (strcat ">> " (itoa (sslength ss)) (if (> (sslength ss) 1) " objects extrude values are" " objects extrude value is") " fixed <<\n"))
(sssetfirst nil ss)
(command "_.regen")
)
)
(vla-EndUndoMark acDoc)
(*error* nil)
(princ)
)
;; -----------------------------------------------------------------------
;; ----------------------=={ Functions START }==--------------------------
;;----------------------------------------------------------------------;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args - dxfcode elist
;; Example - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns - <Entity name: xxxxxxxxxxx>
(defun _dxf (code elist)
(cdr (assoc code elist))
)
(c:FXHatchExtrusion_To_0) ;; Unlbock for testing