pyou Posted October 21, 2023 Author Posted October 21, 2023 (edited) On 20/10/2023 at 20:09, Steven P said: I'm not getting that, can you post an example drawing? Should be something simple Hi Steven P, I have attached example and lisp. First I run H command manually and selected Layer as ''random layer test'' and hatch one of the rectangles as ''pick points in boundaries'' and the second rectangle as ''select boundary entities'' after that i tried to run the lisp and it used ''random layer test'' layer. test1.lsp test3.dwg Edited October 23, 2023 by pyou Quote
BIGAL Posted October 22, 2023 Posted October 22, 2023 Did not look at code but for future reference "0 height" in CAD is referred to as "Elevation". So can set the current plane Z value, For your 3dpoly I think its at current Elev value, but its a flat plane all at that Z value. 1 Quote
Steven P Posted October 23, 2023 Posted October 23, 2023 Having a quick look at this, it mostly works for me as your link test1, apart from the blocks - I haven't got time just now to work out why I changed the hatch slightly for the polylines, circles etc to be a bit quicker and added an undo marker - I'll see if I get chance to look at the blocks later (defun c:test1 ( / Lay_Old MySS target_layers block_names layer_name hatch_pattern ) (setq Lay_Old (getvar 'clayer)) ; Record the current layer ; Define a list of layers for hatching with different patterns (setq target_layers '( ("Layer1" "SOLID") ("Layer2" "SOLID") ("Layer3" "SOLID") ("Layer4" "SOLID") ("Layer5" "ANSI31") ("Layer6" "ANSI31") ("New Layer" "ANSI31") ("New Layer" "SOLID") ; Add more layers here as needed ) ; end list ) ; end setq ; Define a list of block names to hatch (setq block_names '("CIRCL" "Triangle" "MH3")) ;;Added undo mark (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark thisdrawing) (foreach layer_data target_layers (setq layer_name (car layer_data)) (setq hatch_pattern (cadr layer_data)) ; Set the current layer to "Chamber_Hatch" if the hatch pattern is "ANSI31" (if (equal hatch_pattern "ANSI31") (setvar 'clayer "Chamber_Hatch") ) ; Set the current layer to "Features_Hatch" if the hatch pattern is "SOLID" (if (equal hatch_pattern "SOLID") (setvar 'clayer "Features_Hatch") ) ; Select objects for hatching (setq MySS (ssget "X" (list '(0 . "*POLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name)))) (if MySS (progn ; (setq i 0) ; (repeat (sslength MySS) ; (setq ename (ssname MySS i)) (if (equal hatch_pattern "SOLID") ; (command "-hatch" "S" ename "" "P" "SOLID" "") ; (command "-hatch" "P" hatch_pattern 0.03 0.0 "S" ename "" "") ;;Changed to this, removes a loop and is quicker (command "-hatch" "S" MySS "" "P" "SOLID" "") (command "-hatch" "P" hatch_pattern 0.03 0.0 "S" MySS "" "") ) ; end if ; (setq i (1+ i)) ; ) ; end repeat ) ; end progn ) ; end if ; Select and hatch blocks (foreach block_name block_names (setq MySS (ssget "X" (list '(0 . "INSERT") (cons 8 layer_name) (cons 2 block_names)))) (if MySS (progn (setq i 0) (repeat (sslength MySS) (setq ename (ssname MySS i)) (if (equal hatch_pattern "SOLID") (command "-hatch" "S" ename "" "P" "SOLID" "") (command "-hatch" "P" hatch_pattern 0.03 0.0 "S" ename "" "") ) (setq i (1+ i)) ) ) ) ) ; Reset the current layer to the original layer (setvar 'clayer Lay_Old) ) ;;added this line (vla-endundomark thisdrawing) (princ) ; End quietly ) 1 Quote
Steven P Posted October 24, 2023 Posted October 24, 2023 looking at this again, I think you might want to think about hatching the blocks again - I wasn't thinking straight yesterday but if you add a hatch into one block, all instances of that block will get that hatch. You could 'edit' the block (either edit command or use the entity information) and grab all the entities that the block is made from, create a list of points from each part of the block, come out of the block, align these points to the instance of that block and create a hatch from points - which should sit on top of the block. That sounds like a bit of work to do this evening though. 1 Quote
pyou Posted October 30, 2023 Author Posted October 30, 2023 On 24/10/2023 at 20:15, Steven P said: looking at this again, I think you might want to think about hatching the blocks again - I wasn't thinking straight yesterday but if you add a hatch into one block, all instances of that block will get that hatch. You could 'edit' the block (either edit command or use the entity information) and grab all the entities that the block is made from, create a list of points from each part of the block, come out of the block, align these points to the instance of that block and create a hatch from points - which should sit on top of the block. That sounds like a bit of work to do this evening though. Thanks Steven P , but the first version worked better. I just can understand why it does not work when you start manually hatch things and use the lisp afterwards. It seems you can run this lisp only at the beginning. Quote
Recommended Posts
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.