Hi All,
This is my first post in this Forum. I've gained so much of knowledge about CAD from this forum... Thanks to All of You...
I need your help and my request is.
I am trying to make a lisp routine which create Panels along Polyline for preparing Alignment Sheet, but I am stuck as I am not such a good programmer.
Below is the code so far I've made. I am not able to insert a loop in my routine because I am confused.
I am attaching a drawing too in which I've created Panels manually.
Its my humble request to all of you to please have a look at the drawing and help me achieve this.
(Defun C:CreatePanel ()
(defun MakePanel (p1 p2 len wid Ang / tmpent widmid)
(command "_Rectangle" p1 (strcat "@" (rtos len 2 16) "," (rtos wid 2 16)) "")
(setq tmpent (entlast))
(setq Tmplist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget tmpent))))
(setq widmid (list (car (car Tmplist)) (/ (+ (cadr (car Tmplist)) (cadr (cadddr Tmplist))) 2)))
;(command "_move" tmpent "" widmid p1)
(command "_Rotate" tmpent "" widmid Ang)
(command "_move" tmpent "" widmid p2)
(princ))
(defun dtr (a) ; Degrees to Radians
(* pi (/ a 180.0)))
(defun rtd (a) ; Radians to Degrees
(/ (* a 180.0) pi))
(defun *error* (msg)
(if msg
(princ (strcat "\nError! " msg))
)
(princ)
)
;;-----------------=={ Group by Number }==--------------------;;
;; ;;
;; Groups a list into a list of lists, each of length 'n' ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; l - List to process ;;
;; n - Number of elements by which to group the list ;;
;;------------------------------------------------------------;;
;; Returns: List of lists, each of length 'n' ;;
;;------------------------------------------------------------;;
(defun LM:GroupByNum (l n / r)
(if l
(cons
(reverse (repeat n
(setq r (cons (car l) r)
l (cdr l)
)
r
)
)
(LM:GroupByNum l n)
)
)
)
;;-----------------=={ Get Intersections }==------------------;;
;; ;;
;; Returns a list of all points of intersection between ;;
;; two objects ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; obj1, obj2 - VLA-Objects ;;
;;------------------------------------------------------------;;
;; Returns: List of intersection points, or nil ;;
;;------------------------------------------------------------;;
(defun LM:GetIntersections (obj1 obj2)
(LM:GroupByNum
(vlax-invoke obj1 'IntersectWith obj2 acExtendnone)
3
)
)
(setq Plength (getreal "\nSpecify Panel Length:")
Pwidth (getreal "\nSpecify Panel Width:")
Overlap (getreal "\nSpecify Overlapping between Panels:");refer drawing
gap (getreal "\nSpecify gap between Route and First Panel:");refer drawing
)
(while (not
(and (setq Kproute
(car (entsel "\nSelect Polyline Route:")))
(eq "LWPOLYLINE"
(cdr (assoc 0 (entget Kproute))))
)))
(setq Kprop (entget Kproute))
(setq Coorlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) Kprop))); list of coordinates
(setq Vertlength (length Coorlist)
FirstVert (nth 0 Coorlist)
SecondVert (nth 1 Coorlist)
FSAng (rtd (angle FirstVert SecondVert)); angle between first and second vertex
FScounterAng (angle SecondVert FirstVert); angle between second and first vertex
StartP (polar FirstVert FScounterAng gap))
(MakePanel FirstVert StartP Plength Pwidth FSAng)
(setq Panel (entlast));saves last rectangle
(setq InterCheck (LM:GetIntersections (vlax-ename->vla-object Kproute) (vlax-ename->vla-object Panel)));check intersection between rec and route
(princ))