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

Align A Selected Side Of A Polyline To Zero Degrees In Autolisp

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
cncah
940 Views, 6 Replies

Align A Selected Side Of A Polyline To Zero Degrees In Autolisp

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.

 

Side Of Part To Align To Zero Degrees.JPG

6 REPLIES 6
Message 2 of 7
hmsilva
in reply to: cncah

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

 

EESignature

Message 3 of 7
cncah
in reply to: hmsilva

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?

Message 4 of 7
hmsilva
in reply to: cncah


@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

EESignature

Message 5 of 7
3wood
in reply to: cncah

Alternatively, draw a horizontal line then use ALIGN command.

Message 6 of 7
cncah
in reply to: 3wood

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 "")

 

Message 7 of 7
hmsilva
in reply to: cncah

You're welcome, cncah
Glad you got a solution.

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost