AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

These two programs help to find the first or the last point of an entity (for POLYLINE, LWPOLYLINE, SPLINE, LINE, ARC).

Nikolai Poleshchuk

;CODING STARTS HERE
;**********************************************************************
;**** In the current coordinate system, find the first point of
;**** an entity of type LINE, POLYLINE, LWPOLYLINE, ARC, or SPLINE.
;**** V.Savelieva, 2000
;**********************************************************************
;**** No globals.
;**** No arguments.
;**** The locals:
;**** w - the list returned by the entsel function;
;**** e - the specified entity;
;**** le - the list of the e entity;
;**** ten - the type of the e entity;
;**** ca10 - the value of the dotted pair (DXF code is 10);
;**** pt - the point to be found.
;**** The return value:
;**** a list of three coordinates of the points or nil
;**** (if an entity of another type was specified).
;**********************************************************************
;
(defun ffp ( / w le e ten ca10 pt)
; Request for an object
(setq w
(entsel
"\nSpecify an object of type LINE, ARC, POLYLINE, LWPOLYLINE, or SPLINE: "
);entsel
)
; Check if an object is specified
(while (null w) (setq w (entsel "\nNo object is selected, repeat: ")))
; Read the entity's data, get the values for the DXF codes 0 and 10
(setq
le (entget (setq e (car w)))
ten (cdr (assoc 0 le))
ca10 (cdr (assoc 10 le))
);setq
; Display the type of the entity
(princ (strcat "\n" ten " "))
; Find the first point of the object in its own coordinate system
(setq pt
(cond
; LINE and SPLINE
((or (= ten "LINE")(= ten "SPLINE")) ca10)
; LWPOLYLINE (append the third coordinate to ca10)
((= ten "LWPOLYLINE") (append ca10 (list (cdr (assoc 38 le)))))
; ARC (find the point by the center, the radius, and the angle
((= ten "ARC")
(list
(+
(car ca10)
(* (cdr (assoc 40 le)) (cos (cdr (assoc 50 le))))
);+
(+
(cadr ca10)
(* (cdr (assoc 40 le)) (sin (cdr (assoc 50 le))))
);+
(caddr ca10)
);list
)
; POLYLINE (read the first vertex of the polyline)
((= ten "POLYLINE")(cdr (assoc 10 (entget (entnext e)))))
; For all other types display a message and return nil
(T
(princ "\nInvalid entity type. ")
nil
);T
);cond
);setq pt
; Transform the coordinates to the current UCS
(if pt (trans pt e 1))
);defun
;CODING ENDS HERE

;CODING STARTS HERE
;**********************************************************************
;**** In the current coordinate system, find the last point of
;**** an entity of type LINE, POLYLINE, LWPOLYLINE, ARC, or SPLINE.
;**** V.Savelieva, 2000
;**********************************************************************
;**** No globals.
;**** No arguments.
;**** The locals:
;**** w - the list returned by the entsel function;
;**** e - the specified entity;
;**** le - the list of the e entity;
;**** ten - the type of the e entity;
;**** ca10 - the value of the dotted pair (DXF code is 10);
;**** pt - the point to be found.
;**** The return value:
;**** a list of three coordinates of the points or nil
;**** (if an entity of another type was specified).
;**********************************************************************
;
(defun flp ( / w e le ten ca10 e1 pt)
; Request
(setq w
(entsel
"\nSpecify an object of type LINE, ARC, POLYLINE, LWPOLYLINE, or SPLINE: "
);entsel
);setq
; Check if an object is specifie
(while (null w) (setq w (entsel "\nNo object is selected, repeat: ")))
; Read the entity's data
(setq
le (entget (setq e (car w)))
ten (cdr (assoc 0 le))
ca10 (cdr (assoc 10 le))
)
; Display the type of the entity
(princ (strcat "\n" ten " "))
; Find the last point of the object in its own coordinate system
(setq pt
(cond
; LINE
((= ten "LINE") (cdr (assoc 11 le)))
; SPLINE
((= ten "SPLINE") (cdr (assoc 10 (reverse le))))
; LWPOLYLINE (append the third coordinate)
((= ten "LWPOLYLINE")
(append
(if (= 1 (cdr (assoc 70 le))); closed?
ca10; last = first
(cdr (assoc 10 (reverse le)))
);if
(list (cdr (assoc 38 le)))
);append
);LWPOLYLINE
; ARC (find the point by the center, the radius, and the angle
((= ten "ARC")
(list
(+
(car ca10)
(* (cdr (assoc 40 le)) (cos (cdr (assoc 51 le))))
);+
(+
(cadr ca10)
(* (cdr (assoc 40 le)) (sin (cdr (assoc 51 le))))
);+
(caddr ca10)
);list
);ARC
; POLYLINE (read the vertices of the polyline up to the SEQEND entity
((= ten "POLYLINE")
(if (= 1 (cdr (assoc 70 le))); closed?
(cdr (assoc 10 (entget (entnext e)))); last=first
(progn
(setq e1 (entnext e))
(while (= "VERTEX" (cdr (assoc 0 (entget (entnext e1)))))
(setq e1 (entnext e1))
);while
(cdr (assoc 10 (entget e1)))
);progn
);if
);POLYLINE
; For all other types display a message and return nil
(T
(princ "\nInvalid entity type. ")
nil
);T
);cond
);setq
; Transform the coordinates to the current UCS
(if pt (trans pt e 1))
);defun flp
;CODING ENDS HERE

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website