Hello, I am needing a lisp routine that would rotate an entity to zero degrees based on which side of the polyline the user selects. Is this possible? Or would I require more input from the user? Such as rotation angle or base point for rotation? If it makes any difference, the polyline is always on the same layer, and is always closed. The direction, CW or CCW does vary from part to part. I've included a top view picture of the side of the polyline that I need to align to zero. I wrote a program that will rotate the part in a loop but I have to prompt the user if they want to run the program again. I would like to be able to have the user select the side of the polyline they want inline with the X axis and be done with it. Any help or pointers would be greatly appreciated. Thanks.
Solved! Go to Solution.
Solved by 3wood. Go to Solution.
Solved by hmsilva. Go to Solution.
Only as a "demo", quick and dirty...
Will work as expected in WCS.
(defun c:demo (/ A B ENT OUT PAR PAR1 PAR1PT PARPICK PARPT PT PTPICK) (while (and (princ "\nSelect LwPolyline Segment to put rotation zero degrees, the nearest vertex will be the rotation base point!" ) (setq out (ssget "_+.:E:S:L" '((0 . "LWPOLYLINE") (8 . "Outside_*")))) ) (setq pt (cadr (last (last (ssnamex out)))) ent (ssname out 0) ptpick (vlax-curve-getClosestPointTo ent pt T) parpick (vlax-curve-getParamAtPoint ent ptpick) par (fix parpick) parpt (vlax-curve-getPointAtParam ent par) par1 (1+ par) par1pt (vlax-curve-getPointAtParam ent par1) ) (if (< (distance ptpick parpt) (distance ptpick par1pt)) (setq a parpt b par1pt ) (setq b parpt a par1pt ) ) (command "_.rotate" ent "" a "_R" "@" b 0.0) ) (princ) )
hope that helps
Henrique
It works fine as far as rotating it, but it seems like you have to select the same segment of the polyline twice and rotate the part twice before it ends up where the picked polyline segment is at zero. Any thoughts?
@cncah wrote:
It works fine as far as rotating it, but it seems like you have to select the same segment of the polyline twice and rotate the part twice before it ends up where the picked polyline segment is at zero. Any thoughts?
You only need to select the Lwpolyline segment once, the "demo" continues to prompt to select other...
To exit the command, just press enter or spacebar or select nothing...
Henrique
Thanks! Using Align keeps everything in the positive Y axis quadrant like I'm needing. It also allows me to get rid of the loop making it a click once and done program. Thanks Henrique and 3wood!
(command "-view" "_top" ) (command "_undo" "_m" ) (princ "\nPress _undo <enter> Then _b <enter> To Undo Program Changes") (and (princ "\nSelect Polyline Segment To Align To Zero Degrees:" ) (setq out (ssget "_+.:E:S:L" '((0 . "LWPOLYLINE") (8 . "Outside_*")))) ) (setq pt (cadr (last (last (ssnamex out)))) ent (ssname out 0) ptpick (vlax-curve-getClosestPointTo ent pt T) parpick (vlax-curve-getParamAtPoint ent ptpick) par (fix parpick) parpt (vlax-curve-getPointAtParam ent par) par1 (1+ par) par1pt (vlax-curve-getPointAtParam ent par1) ) (setq part (ssget "x")) (setq line1 (list 0 0)) (setq line2 (list (+ (car line1) 10) 0)) (command "_.line" line1 line2 "") (setq lineENT (entlast)) (command "_.align" part "" parpt line1 par1pt line2 "" "") (command "_.erase" lineEnt "")