james9710 Posted Wednesday at 02:20 PM Posted Wednesday at 02:20 PM hi, can someone please assist me on creating a lisp: create polyline then after closing, it will automatically create a solid hatch within the closed polyline. hatch should be solid and layer is as per current. command should be PLH big thanks. we are working on large scale landscape projects that need hatches of each area of soft scape and hardscape Quote
devitg Posted Wednesday at 03:49 PM Posted Wednesday at 03:49 PM @james9710 please upload your sample dwg where you will apply such lisp Quote
BlackBox Posted Wednesday at 04:12 PM Posted Wednesday at 04:12 PM (edited) Without using Visual LISP reactors, here's a starting point: (defun c:PLH (/ pt) (command "._pline") (while (and (not (initget 32)) (if pt (setq pt (getpoint pt)) (setq pt (getpoint)) ) ) (command pt) ) (command "_c") (command "._-hatch" "_p" "_s" "_co" "." "." "_la" "." "_s" (ssadd (entlast)) "" "" ) (princ) ) Edited yesterday at 12:03 PM by BlackBox 1 Quote
pkenewell Posted Wednesday at 04:20 PM Posted Wednesday at 04:20 PM (edited) @BlackBox Beat me to the Punch! @james9710 Here is my version - as simple as I can make it: (defun C:PLH (/ e el) (command "._pline") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (if (and (setq e (entlast)) (setq el (entget e)) (= (cdr (assoc 0 el)) "LWPOLYLINE") (= (logand (cdr (assoc 70 el)) 1) 1) ) (command "._-hatch" "_pro" "_S" "_S" e "" "") (princ "\nInvalid Polyline Created (Must be complete and Closed).") ) (princ) ) Edited Wednesday at 04:42 PM by pkenewell 2 Quote
BlackBox Posted Wednesday at 05:36 PM Posted Wednesday at 05:36 PM (edited) 1 hour ago, pkenewell said: @BlackBox Beat me to the Punch! @james9710 Here is my version - as simple as I can make it: (defun C:PLH (/ e el) (command "._pline") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (if (and (setq e (entlast)) (setq el (entget e)) (= (cdr (assoc 0 el)) "LWPOLYLINE") (= (logand (cdr (assoc 70 el)) 1) 1) ) (command "._-hatch" "_pro" "_S" "_S" e "" "") (princ "\nInvalid Polyline Created (Must be complete and Closed).") ) (princ) ) '... as simple'... using logand. (chortles) Teeheehee Props though, as yours allows arcs, etc... Well done Edited Wednesday at 05:37 PM by BlackBox 1 Quote
pkenewell Posted Wednesday at 06:46 PM Posted Wednesday at 06:46 PM 14 minutes ago, BlackBox said: '... as simple'... using logand. (chortles) Teeheehee Props though, as yours allows arcs, etc... Well done @BlackBox Thanks! (yeah - logand is fairly advanced, but shorter lol) Quote
masterfal Posted yesterday at 03:41 AM Posted yesterday at 03:41 AM Hi All, managed to tweak this code slightly so it draws into a specific layer and then removes the polyline at the end so you are just left with solid hatch. just wondering if i wanted to specify a certain hatch pattern instead of solid (eg ANSI34 with scale of 10 and angle of 90) how would i do that? (defun C:PLH (/ e el old_layer hatch_ent) ;; Store the current layer (setq old_layer (getvar "clayer")) ;; Set the desired layer for the polyline and hatch (command "._layer" "_m" "layernamehere" "") ; Create layer if it doesn't exist (command "._layer" "_s" "layernamehere" "") ; Set current layer (command "._pline") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (if (and (setq e (entlast)) ; 'e' now holds the entity name of the polyline (setq el (entget e)) (= (cdr (assoc 0 el)) "LWPOLYLINE") (= (logand (cdr (assoc 70 el)) 1) 1) ) (progn (command "._-hatch" "_pro" "_S" "_S" e "" "") (setq hatch_ent (entlast)) ; Get the entity name of the newly created hatch (entdel e) ; Delete the polyline using its entity name 'e' ) (princ "\nInvalid Polyline Created (Must be complete and Closed).") ) ;; Restore the original layer (command "._layer" "_s" old_layer "") (princ) ) Quote
SLW210 Posted yesterday at 10:46 AM Posted yesterday at 10:46 AM How are you creating the polyline? You can use -Hatch with the "draW boundary" option, just a few clicks for a solid hatch on current layer. 2 Quote
pkenewell Posted yesterday at 02:20 PM Posted yesterday at 02:20 PM (edited) 10 hours ago, masterfal said: Hi All, managed to tweak this code slightly so it draws into a specific layer and then removes the polyline at the end so you are just left with solid hatch. just wondering if i wanted to specify a certain hatch pattern instead of solid (eg ANSI34 with scale of 10 and angle of 90) how would i do that? (defun C:PLH (/ e el old_layer hatch_ent) ;; Store the current layer (setq old_layer (getvar "clayer")) ;; Set the desired layer for the polyline and hatch (command "._layer" "_m" "layernamehere" "") ; Create layer if it doesn't exist (command "._layer" "_s" "layernamehere" "") ; Set current layer (command "._pline") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (if (and (setq e (entlast)) ; 'e' now holds the entity name of the polyline (setq el (entget e)) (= (cdr (assoc 0 el)) "LWPOLYLINE") (= (logand (cdr (assoc 70 el)) 1) 1) ) (progn (command "._-hatch" "_pro" "_S" "_S" e "" "") (setq hatch_ent (entlast)) ; Get the entity name of the newly created hatch (entdel e) ; Delete the polyline using its entity name 'e' ) (princ "\nInvalid Polyline Created (Must be complete and Closed).") ) ;; Restore the original layer (command "._layer" "_s" old_layer "") (princ) ) @masterfal Simple - just replace the the options in the command statement for the -HATCH command ; Replace Hatch command line (command "._-hatch" "_pro" "_S" "_S" e "" "") with: (command "._-hatch" "_Pro" "ANSI34" "10.0" "90" "_S" e "" ""); where after "Pro" (properties), the arguments are [Pat. Name] [Scale] [Rotation] Edited yesterday at 02:23 PM by pkenewell Quote
pkenewell Posted yesterday at 02:34 PM Posted yesterday at 02:34 PM (edited) 3 hours ago, SLW210 said: How are you creating the polyline? You can use -Hatch with the "draW boundary" option, just a few clicks for a solid hatch on current layer. @SLW210 That's true! the command could be boiled down to this below if you don't want a polyline boundary. However, the PLINE command has more options, and there are 2 extra returns that you have to press at the end to complete the command - that's why I would stick to the original. (defun C:PLH (/ e el) (command "._-hatch" "_Pro" "ANSI34" "10.0" "90" "_W" "_N") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (princ) ) Edited yesterday at 02:34 PM by pkenewell Quote
masterfal Posted 15 hours ago Posted 15 hours ago (edited) 16 hours ago, SLW210 said: How are you creating the polyline? You can use -Hatch with the "draW boundary" option, just a few clicks for a solid hatch on current layer. how am i creating polyline? what do you mean..? i just click the points where i want my polyline and c to close. isn't that how everyone does it? i need the hatch in specific hatch layer which would rarely be my current layer + the correct hatch pattern wont always be the last used so i thought setting a little routine that specifies layer and hatch pattern would be the quickest way. this way i just type plh, enter, click click click with mouse, c to close and thats it. surely thats gotta be quicker than running original -hatch and manually entering required hatch/layer types? Edited 15 hours ago by masterfal Quote
masterfal Posted 15 hours ago Posted 15 hours ago 13 hours ago, pkenewell said: @masterfal Simple - just replace the the options in the command statement for the -HATCH command ; Replace Hatch command line (command "._-hatch" "_pro" "_S" "_S" e "" "") with: (command "._-hatch" "_Pro" "ANSI34" "10.0" "90" "_S" e "" ""); where after "Pro" (properties), the arguments are [Pat. Name] [Scale] [Rotation] Ahh i see.. i knew was going to be something like that, just couldnt work out exactly what to change. Works like a charm. Appreciate the help! one thing i just noticed though is its not actually drawing the hatch in the correct layer. its drawing the polyline in the correct layer (which gets removed at the end) but the layer the hatch is being put in is whatever layer is set in the hatch dialog box when you run the hatch command. basically just using the previous layer that was used when doing hatch. how can i fix so it drops the hatch into my specified layer? Quote
SLW210 Posted 8 hours ago Posted 8 hours ago 6 hours ago, masterfal said: how am i creating polyline? what do you mean..? i just click the points where i want my polyline and c to close. isn't that how everyone does it? i need the hatch in specific hatch layer which would rarely be my current layer + the correct hatch pattern wont always be the last used so i thought setting a little routine that specifies layer and hatch pattern would be the quickest way. this way i just type plh, enter, click click click with mouse, c to close and thats it. surely thats gotta be quicker than running original -hatch and manually entering required hatch/layer types? I wasn't talking to you. I was asking the OP, if not mentioned by name or quoted it is presumed all over the internet the question is for the OP. But, I mentioned, no LISP needed if you are manually making a polyline, -Hatch with "draW boundary" option. I see no need for a LISP and you can also leave a polyline if needed. 1 Quote
pkenewell Posted 4 hours ago Posted 4 hours ago (edited) 12 hours ago, masterfal said: Works like a charm. Appreciate the help! one thing i just noticed though is its not actually drawing the hatch in the correct layer. its drawing the polyline in the correct layer (which gets removed at the end) but the layer the hatch is being put in is whatever layer is set in the hatch dialog box when you run the hatch command. basically just using the previous layer that was used when doing hatch. how can i fix so it drops the hatch into my specified layer? @masterfal First Check the HPLAYER and other HP... variables. These will make a hatch on a particular layer and other specifications regardless of what layer is set current. You have to set HPLAYER to blank (type in a "." for the setting). Look up HPLAYER in your help and it will explain. You can also set HPLAYER to the layer you want in code using (setvar "HPLAYER" "MyLayer") Edited 2 hours ago by pkenewell 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.