Can anyone please correct the code to work properly?

Can anyone please correct the code to work properly?

smallƑish
Advocate Advocate
661 Views
11 Replies
Message 1 of 12

Can anyone please correct the code to work properly?

smallƑish
Advocate
Advocate

1. Begin by executing the "ET" command.
2. Prompt the user to specify the width of the duct (DW).
3. Ask the user to select an existing polyline.

Backend Operations:

4. Offset the selected polyline on both sides by a distance equal to 0.5 times DW.
5. Apply a fillet with a radius of 0.75 times DW at all deviations along the polyline.
6. Draw two new lines originating from both ends of the inner fillet, extending perpendicularly to the opposite offset line.
7. Delete the original polyline located in the middle.
8. Insert the DW value, provided by the user, as text at the midpoint of each offset segment. Use a text size of 0.40 times DW, ensuring middle-center justification.

smallish_0-1693692775276.png

 

 

0 Likes
Accepted solutions (2)
662 Views
11 Replies
Replies (11)
Message 2 of 12

Sea-Haven
Mentor
Mentor

You need to learn simple maths in lisp 1 function at a time 

 

(1/2.0 (* DW -1.0))

(/ (* DW -1.0) 2.0)
(* (* DW -1.0) 0.5)

 

Some deep functions can take a bit of understanding.

 

0 Likes
Message 3 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

Isn't there another recent topic that already has something to do this?

 

You have a Fillet command setting the Radius [with an extraneous (/) function around what I think you really want], but you never apply it to the Polylines.  But that needs to be done to the center-path Polyline before Offsetting, to get the result you are looking for.

 

You can use (vla-offset) on a VLA-object conversion of the center-path Polyline, giving it positive and negative values of half the width, to avoid needing to calculate which-side point locations.  Search the Forum for examples.

 

If you put those resulting Polylines' entity names into variables, you can draw all the across Lines much more easily using Parameter values, whole-number values of which are at the vertices:

(command "_.line"

  (vlax-curve-getPointAtParam OnePolylineEntityName 0)

  (vlax-curve-getPointAtParam OtherPolylineEntityName 0)

  ""

)

and do that for each integer Parameter value to the end.

 

You can also use Parameter values at x.5 values to get the midpoints of segments, which will give you the easiest way to locate the Text, on the center-path Polyline before removing it.

Kent Cooper, AIA
0 Likes
Message 4 of 12

Sea-Haven
Mentor
Mentor

Like you Kent, the other was draw ducting and a solution was offered. In fact more than 1 solution.

 

Starting to sound like I want more for free. Why learn myself.

0 Likes
Message 5 of 12

smallƑish
Advocate
Advocate

Please accept my Apology.

0 Likes
Message 6 of 12

Sea-Haven
Mentor
Mentor

Its ok to ask but sometimes asking for multiple versions is really I want a package of options, in that case pay some one to do all the options you want, remember the people here including me are giving their time for free. Your getting paid for your work.

Message 7 of 12

smallƑish
Advocate
Advocate

Will do this from next time. And I always respect valuable time and effort for every one specially who make magic with coding. Thank you to explain me the same.

0 Likes
Message 8 of 12

smallƑish
Advocate
Advocate

🙂

0 Likes
Message 9 of 12

smallƑish
Advocate
Advocate

Thank you 😊

0 Likes
Message 10 of 12

Sea-Haven
Mentor
Mentor

Google "Label pline Autocad Lisp", yes it should come up with a good example by Kent, he has offered it many times.

0 Likes
Message 11 of 12

komondormrex
Mentor
Mentor
Accepted solution

not a correction but rather a new version 

 

 

 

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

;	c:pline_to_filleted_duct
;	komondormrex, sep 2023

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

(defun first_last_remove (in_list)
		(reverse (cdr (reverse (cdr in_list))))
)

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

(defun make_points (coordinates_raw_list / point_list)
  	(if coordinates_raw_list
		(setq point_list (cons
							   (list (car coordinates_raw_list) (cadr coordinates_raw_list))
							   (make_points (cddr coordinates_raw_list))
						 )
		)
	)
  	point_list
)

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

(defun c:pline_to_filleted_duct (/ outer_radius_factor inner_radius_factor text_height_factor pline_data half_duct_diameter
								   pline offset_pline_1 offset_pline_2 pline_object line vertex_index vertex_number_bulge_list
								   text_param_list diameter_text text_angle
								)
	(setq outer_radius_factor 1.25
		  inner_radius_factor 0.25
		  text_height_factor 0.4
	)
	(if (setq pline_data (entsel "\nPick pline to convert to a filleted duct: "))
		(progn
			(setq half_duct_diameter (getdist (vlax-curve-getclosestpointto (setq pline (car pline_data)) (cadr pline_data))
											  "\nSet half duct diameter: "
									 )
			)
			(setvar 'filletrad (* 0.5 (+ outer_radius_factor inner_radius_factor) (* 2.0 half_duct_diameter)))
			(setvar 'cmdecho 0)
			(command "_fillet" "_p" pline)
			(setvar 'cmdecho 1)
			(setq offset_pline_1 (car (vlax-invoke (setq pline_object (vlax-ename->vla-object pline)) 'offset (* +1 half_duct_diameter)))
				  offset_pline_2 (car (vlax-invoke pline_object 'offset (* -1 half_duct_diameter)))
			)
			(if (not (= (vlax-curve-getendparam pline) (vlax-curve-getendparam offset_pline_1) (vlax-curve-getendparam offset_pline_2)))
				(alert "You've probably had a problem with duct diameter set")
			)
			(mapcar '(lambda (line_point_1 line_point_2)
							(progn
								(setq line (vla-addline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
										     		    (vlax-3d-point line_point_1)
										     		    (vlax-3d-point line_point_2)
										   )
								)
							    (vla-put-truecolor line (vla-get-truecolor pline_object))
							    (vla-put-layer line (vla-get-layer pline_object))
					    	)
					 )
					 (first_last_remove (make_points (vlax-get offset_pline_1 'coordinates)))
		 			 (first_last_remove (make_points (vlax-get offset_pline_2 'coordinates)))
			)
			(setq vertex_index -1)
			(repeat (fix (vlax-curve-getendparam pline))
				(setq vertex_number_bulge_list (append vertex_number_bulge_list (list (cons (setq vertex_index (1+ vertex_index))
				                                                                      		(vla-getbulge pline_object vertex_index)
																					  )
																				)
											   )
				)
				(if (not (zerop (cdr (last vertex_number_bulge_list))))
					(setq vertex_number_bulge_list (vl-remove (last vertex_number_bulge_list) vertex_number_bulge_list))
				)
			)
			(setq text_param_list (mapcar '(lambda (element) (+ 0.5 (car element))) vertex_number_bulge_list))
			(mapcar '(lambda (text_param)
						(progn
							(setq diameter_text (vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
										  	    			 (rtos (* 2 half_duct_diameter) 2 1)
										  	    			 (setq alignment_point (vlax-3d-point (vlax-curve-getpointatparam pline text_param)))
										  	    			 (* 2 text_height_factor half_duct_diameter)
									  	 	 	)
							)
							(vla-put-truecolor diameter_text (vla-get-truecolor pline_object))
							(vla-put-layer diameter_text (vla-get-layer pline_object))
							(vla-put-alignment diameter_text 4)
							(vla-put-textalignmentpoint diameter_text alignment_point)
							(vla-put-rotation diameter_text
											  (if (and
											  			(< (* 0.5 pi) (setq text_angle (angle (trans '(0 0) 1 0) (vlax-curve-getfirstderiv pline text_param))))
														(>= (* 1.5 pi) text_angle)
												  )
													(+ pi text_angle)
													text_angle
								  			  )
							)
						)
					 )
					 text_param_list
			)
			(entdel pline)
		)
	)
	(princ)
)

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

 

 

 

Message 12 of 12

smallƑish
Advocate
Advocate

@komondormrex

As always your code is the perfect solution.

Thank you so much.

0 Likes