Jump to content

closed polyline with automatic hatch


Recommended Posts

Posted

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

Posted (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 by BlackBox
  • Like 1
Posted (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 by pkenewell
  • Like 2
Posted (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 :beer:

Edited by BlackBox
  • Like 1
Posted
14 minutes ago, BlackBox said:

'... as simple'... using logand. (chortles) Teeheehee

 

Props though, as yours allows arcs, etc... Well done :beer:

@BlackBox Thanks! 😆 (yeah - logand is fairly advanced, but shorter lol)

Posted

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)
)

 

Posted

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.

  • Like 2
Posted (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 by pkenewell
Posted (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 by pkenewell
Posted (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 by masterfal
Posted
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?

Posted
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.

  • Like 1
Posted (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 by pkenewell

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...