REQ: lisp to orient hatch to object

REQ: lisp to orient hatch to object

andrea_ricci-ext
Contributor Contributor
1,750 Views
7 Replies
Message 1 of 8

REQ: lisp to orient hatch to object

andrea_ricci-ext
Contributor
Contributor

Hi,

I'd like a lisp to quickly orient an hatch to an object, eventually choosing an angle offset (e.g. object's angle  + 90°), just clicking. I neither know if I can get the angle of a polyline segment.
Sample use case are: hatching irregular paths, or tiles on irregular roof's slopes. Today I have to continuosly switch the ucs, or pick manually the object's angle and copy it in the hatch's angle:

andrea_ricci1_0-1678433704626.png

Thank you

0 Likes
Accepted solutions (1)
1,751 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

Post a dwg, at least a few samples.

0 Likes
Message 3 of 8

komondormrex
Mentor
Mentor
Accepted solution

Hey Andrea,

a simple code

 

 

 

 

(defun c:align_hatch_pattern (/ prompt_ aligning_edge_ename_data picked_point picked_point_parameter
								previous_parameter previous_parameter_point next_parameter next_parameter_point 
								aligning_angle hatch_to_align 
							 )

	;***************************************************************************************************************************

	(defun round_ (float_number up / whole_number)
		(setq whole_number (fix float_number))
		(if up
			(1+ whole_number)
			whole_number
		)
	)

	;***************************************************************************************************************************

 	(setq prompt_ (princ "\nPick p/line edge to align hatch to: ") 
		  aligning_edge_ename_data (ssnamex (ssget "_:S" '((0 . "lwpolyline,line"))))
 		  picked_point (vlax-curve-getclosestpointto (setq aligning_object (vlax-ename->vla-object (cadar aligning_edge_ename_data)))
 		  		                 					 (cadr (last (car  aligning_edge_ename_data)))
 		  		       )      
 		  picked_point_parameter (vlax-curve-getparamatpoint aligning_object picked_point)
 		  previous_parameter (round_ picked_point_parameter nil)
 		  previous_parameter_point (vlax-curve-getpointatparam aligning_object previous_parameter)
 		  next_parameter (round_ picked_point_parameter t)
 		  next_parameter_point (vlax-curve-getpointatparam aligning_object next_parameter)
 		  aligning_angle (angle previous_parameter_point next_parameter_point)
		  prompt_ (princ "\nPick hatch to align pattern: ") 
 		  hatch_to_align (ssname (ssget "_:S" '((0 . "hatch"))) 0)
 	)
 	(vla-put-patternangle (vlax-ename->vla-object hatch_to_align) aligning_angle)
	(princ)
)

 

Message 4 of 8

andrea_ricci-ext
Contributor
Contributor

Hi @komondormrex,

thank you. That works very well.
I'll study it and if I'll be able to implement the angle offset function I'll come back.

Thank you very much.

0 Likes
Message 5 of 8

andrea_ricci-ext
Contributor
Contributor

Hi @ВeekeeCZ,

Here's a sample of what I need (before and after).

Thank you

0 Likes
Message 6 of 8

ВeekeeCZ
Consultant
Consultant

Other possible workflows to consider:

1) adjust the angle while creating hatches. <pick inside pt> <sel line to align to> <pick inside pt> <sel line to align to>...

2) select all/multiple hatches, read it's boundary and align hatch patterns to the longest segment. definitely not flawless, but very fast starting point.

 

Message 7 of 8

boicottms
Enthusiast
Enthusiast
Hi, is it difficult to use any object as reference other than polyline? It doesn't work with a line (acad 2019)
Thank you
0 Likes
Message 8 of 8

komondormrex
Mentor
Mentor

hey, not at all. check original code posting.

0 Likes