Draw a hatch without boundaries like a rectangle

Draw a hatch without boundaries like a rectangle

thomas_schluesselberger
Advocate Advocate
1,383 Views
13 Replies
Message 1 of 14

Draw a hatch without boundaries like a rectangle

thomas_schluesselberger
Advocate
Advocate

Hello!

 

I'm looking for a way to quickly draw a hatch without a boundary.

I want to draw it as if it were a rectangle. That means:

Execute command -> specify first vertex -> specify second vertex.


In addition, I want to be able to enter the formatting (layer, color, hatch type) in advance.

The formatting should be saved after entering it once.

 

 

Maybe someone has a solution.

0 Likes
Accepted solutions (1)
1,384 Views
13 Replies
Replies (13)
Message 2 of 14

johnyDFFXO
Advocate
Advocate

Draw a rectangle, hatch that rectangle, erase the rectangle.

0 Likes
Message 3 of 14

komondormrex
Mentor
Mentor
Accepted solution

hi,

not dynamic.

 

 

 

 

 

 

(defun c:rect_hatch (/ pattern_name_saved hatch_layer_saved hatch_color_saved 1st_corner 2nd_corner 
					   rectangle hatch_object outer_loop option_selected
					)
	(if (and
			(null pattern_name)
			(setq pattern_name "SOLID")
		)
            (setq pattern_name_saved "SOLID")
            (setq pattern_name_saved pattern_name)
    )
	(if (and
			(null hatch_layer)
			(setq hatch_layer "RECT_HATCH")
		)
            (setq hatch_layer_saved "RECT_HATCH")
            (setq hatch_layer_saved hatch_layer)
    )
	(if (and 
			(null hatch_color)
			(setq hatch_color 1)
		)
            (setq hatch_color_saved 1)
            (setq hatch_color_saved hatch_color)
    )
	(while (null option_selected) 
		(initget "Pattern Layer Color")
		(setq option_selected (getkword "Select option [Pattern/Layer/Color] or Space/Enter to skip: "))
		(cond 
			(
				(= "Pattern" option_selected)
					(setq pattern_name (strcase (getstring (strcat "\nEnter hatch pattern name <" pattern_name_saved ">: ")))
						  option_selected nil
					)
			)
			(
				(= "Layer" option_selected)
					(setq hatch_layer (getstring t (strcat "\nEnter hatch layer name <" hatch_layer_saved ">: "))
						  option_selected nil
					)
			)
			(
				(= "Color" option_selected)
					(setq hatch_color (getint (strcat "\nEnter color index for hatch <" (itoa hatch_color_saved) ">: "))
						  option_selected nil
					)
			)
			(
				t
					(setq  option_selected t)
			)
		)
	)
	(setq 1st_corner (getpoint "\nPick 1st coner of hatch: ")
		  2nd_corner (getcorner 1st_corner "\nPick 2nd corner of hatch: ")  
	)
	(if (= "" pattern_name)
            (setq pattern_name pattern_name_saved)
            (setq pattern_name_saved pattern_name)
    )
	(if (= "" hatch_layer)
            (setq hatch_layer hatch_layer_saved)
            (setq hatch_layer_saved hatch_layer)
    )
	(if (null hatch_color)
            (setq hatch_color hatch_color_saved)
            (setq hatch_color_saved hatch_color)
    )
	(command "_.rectang" 1st_corner 2nd_corner)
	(setq rectangle (vlax-ename->vla-object (entlast))) 
	(setq hatch_object (vla-addhatch (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
									 achatchpatterntypepredefined
									 pattern_name
									 :vlax-false
									 achatchobject
					   )
	)
	(vlax-safearray-put-element (setq outer_loop (vlax-make-safearray vlax-vbobject '(0 . 0))) 0 rectangle)
	(vla-appendouterloop hatch_object outer_loop)
	(vla-put-color hatch_object hatch_color)
	(entmod (subst (cons 8 hatch_layer) (assoc 8 (entget (vlax-vla-object->ename hatch_object))) (entget (vlax-vla-object->ename hatch_object))))  
	(vla-erase rectangle)
	(princ)
)

 

 

 

 

 

 

0 Likes
Message 4 of 14

thomas_schluesselberger
Advocate
Advocate
"I'm looking for a way to quickly draw a hatch without a boundary."
0 Likes
Message 5 of 14

thomas_schluesselberger
Advocate
Advocate

Hi, thanks for your anwser.

 

But sadly i get the following error:

 

; Error: Bad argument type: stringp nil

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

You can do this directly, without any custom code, within the -HATCH command [note the hyphen prefix].  Choose the "draW boundary" option, and you get a choice of whether or not to keep the boundary.  You can draw it as you would a Polyline, including the option of arc segments.

Kent Cooper, AIA
0 Likes
Message 7 of 14

komondormrex
Mentor
Mentor

sorry, check the update above.

0 Likes
Message 8 of 14

thomas_schluesselberger
Advocate
Advocate
I know this method but it aint really fast.
But thanks!
0 Likes
Message 9 of 14

thomas_schluesselberger
Advocate
Advocate
Thank you very much, works just as wanted.

As an addition (if not too much work) it would be great if the settings were called up separately.
So that I don't have to skip all 3 settings every time I run the command.
0 Likes
Message 10 of 14

komondormrex
Mentor
Mentor

sure. check update.

0 Likes
Message 11 of 14

johnyDFFXO
Advocate
Advocate

One could be thinking, why the extra step is necessary.

(getpoint "\nPick 1st corner of hatch or [Pattern/Layer/Color]: ")

0 Likes
Message 12 of 14

pendean
Community Legend
Community Legend

@thomas_schluesselberger wrote:
"I'm looking for a way to quickly draw a hatch without a boundary."

They were trying to teach you to fish, not hand you one 🙂

0 Likes
Message 13 of 14

pendean
Community Legend
Community Legend

@johnyDFFXO wrote:

One could be thinking, why the extra step is necessary.

(getpoint "\nPick 1st corner of hatch or [Pattern/Layer/Color]: ")


A bypass is built into that LISP, along with defaults you can change.

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

There is 2 point rectang code out there does not take much to work out the 4 points or a start point and length and width, the reason that I say that is you dismissed Kent's suggestion, but it could be written as a lisp so would be super fast, start the -hatch command and pass all the correct answers. No "draW boundary" in my version of Bricscad, so no code.

0 Likes