james9710 Posted July 23 Posted July 23 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 July 23 Posted July 23 @james9710 please upload your sample dwg where you will apply such lisp Quote
BlackBox Posted July 23 Posted July 23 (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 July 24 by BlackBox 1 Quote
pkenewell Posted July 23 Posted July 23 (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 July 23 by pkenewell 2 Quote
BlackBox Posted July 23 Posted July 23 (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 July 23 by BlackBox 1 Quote
pkenewell Posted July 23 Posted July 23 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 July 24 Posted July 24 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 July 24 Posted July 24 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 July 24 Posted July 24 (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 July 24 by pkenewell Quote
pkenewell Posted July 24 Posted July 24 (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 July 24 by pkenewell Quote
masterfal Posted July 25 Posted July 25 (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 July 25 by masterfal Quote
masterfal Posted July 25 Posted July 25 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 July 25 Posted July 25 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 July 25 Posted July 25 (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 July 25 by pkenewell Quote
CivilTechSource Posted 6 hours ago Posted 6 hours ago (edited) So I saw this post and came up with the idea to create a lisp to draw polyline once closed it will insert the area of the polyline at the centre (this is for drainage catchment). Did I overcomplicate the lisp? Initially I was going for static text, but I am all about making life easier so tried to merge the ATC function from the lisp here https://jtbworld.com/autocad-areatext-lsp . Any feedback on the below lisp would be appreciated. Thank you all! (setq jtbfieldformula ">%).Area \\f \"%lu2%pr1%ps[,m²]%ct8[0.001]\">%") (defun Get-ObjectIDx64 (obj / util) (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (= (type obj) 'ENAME) (setq obj (vlax-ename->vla-object obj)) ) (if (= (type obj) 'VLA-OBJECT) (if (> (vl-string-search "x64" (getvar "platform")) 0) (vlax-invoke-method util "GetObjectIdString" obj :vlax-False ) (rtos (vla-get-objectid obj) 2 0) ) ) ) (defun c:CTS-DrawGullyCatchment () (if (not (tblsearch "LAYER" "CTS-Gully Catchment")) (command "-LAYER" "_M" "CTS-Gully Catchment" ;;Set Layer Name "_C" "True" "0,255,0" ;;Set Color "CTS-Gully Catchment" ;;Set Layer Name "") ) (command "._pline") (while (and (not (initget 32)) (if pt (setq pt (getpoint pt)) (setq pt (getpoint)) ) ) (command pt) ) (command "_c") (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 "._area" "_o" e) ;;(setq GullyArea (getvar "area")) ; Get the area of the polyline ;;(setq GullyAreaTxt (strcat (rtos GullyArea 2 2) "m2")) ;;(setq GullyAreaTxtPt (getpoint "\nSpecify point for Guylly Cathcment text:")) (vl-load-com) (setq entObject (vlax-ename->vla-object (setq ent (entlast)))) (setq entObjectID (Get-ObjectIDx64 entObject)) (setq lastpt (getvar "lastpoint")) (setq InsertionPoint (vlax-3D-Point(trans (osnap lastpt "_gcen") 1 0))) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (setq mtextobj (vla-addMText (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) InsertionPoint 0.0 (strcat "%<\\AcObjProp Object(%<\\_ObjId " entObjectID jtbfieldformula ) ) ) (vla-put-AttachmentPoint mtextobj 5) (vla-put-insertionPoint mtextobj InsertionPoint) ) ) ) Edited 6 hours ago by CivilTechSource 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.