Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

REQ: lisp to orient hatch to object

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
andrea_ricci-ext
914 Views, 7 Replies

REQ: lisp to orient hatch to object

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

Tags (2)
Labels (3)
7 REPLIES 7
Message 2 of 8

Post a dwg, at least a few samples.

Message 3 of 8

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

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.

Message 5 of 8

Hi @ВeekeeCZ,

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

Thank you

Message 6 of 8

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
in reply to: komondormrex

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

hey, not at all. check original code posting.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report