Hi Mostafa,
short answer, no.
Xline don't have length property.
If the goal is to change xline, to a line/polyline with a defined length, you'll have to trim xline in two paces, to become a line, then you may convert it to polyline...
Henrique
@mostafabadran wrote:
I saw this thread before by Lee
But I just wonder if it possible BTW thanks a lot Henrique for your reply .
You're welcome, Mostafa!
Lee's replay, start with 'Seems pointless, but' , and the goal was entmake a line with a specified length, using the xline direction...
Henrique
@mostafabadran wrote:
... is there any way to convert xline to polyline in lisp and keep as same length ?
Since [as already pointed out] an Xline has no length, one would need to be determined. My preference, if I wanted to do something like that, would be to draw it across the greatest reach in the X and Y directions of the drawing's Limits and/or Extents, equivalent to drawing a Rectangle around that area and Trimming the Xline away from outside it. Since the result of that would be a Line, not a Polyline [and since a Line uses less memory than a one-line-segment Polyline], that's what the following draws, but it's easily adjusted to make a Polyline instead [see instructions near the top]. It could use various enhancements [error handling, command-echo suppression, Undo begin/end, etc.], but it seems to work in limited testing. Other possibilities: option of whether to keep the Xline; check for its being on a locked Layer; account for different Coordinate Systems; Layer choice other than that of the Xline; etc.
;; XlineToLine.lsp [command name: XL2L]
;; To replace an Xline with a Line drawn to the greater reaches of the drawing's
;; Extents or Limits where the Xline crosses them, if it does.
;; [To draw a Polyline instead of a Line, change "_.line" to "_.pline" in (command)
;; function near end, and consider whether to add Width option setting to 0; also
;; adjust command name and appropriate comments and prompts.]
;; Kent Cooper, 12 February 2015
(defun C:XL2L ; = Xline to Line
(/ xlss xl xldata xl1 xl2 extminXY extmaxXY noext limLL limUR
rangeLL rangeUR rangeLR rangeUL intB intR intT intL ends)
(if (not (ssget "_X" (list '(0 . "XLINE") (cons 410 (getvar 'ctab)))))
(progn ; then
(alert "No Xlines in current space.")
(quit)
); progn
); if
(prompt "\nTo replace an Xline with a Line across the Limits/Extents,")
(while
(not (setq xlss (ssget "_+.:S" '((0 . "XLINE")))))
(prompt "\nNo Xline selected.")
); while
(command "_.zoom" "_all" "_zoom" "_previous")
; reset EXTMIN/EXTMAX if needed; encompass both Extents and Limits
(setq
xl (ssname xlss 0)
xldata (entget xl)
xl1 (cdr (assoc 10 xldata)); base point
xl2 (mapcar '+ xl1 (cdr (assoc 11 xldata))); direction-defining point
extminXY (reverse (cdr (reverse (getvar 'extmin)))); XY only
extmaxXY (reverse (cdr (reverse (getvar 'extmax))))
noext (> (car extminXY) (car extmaxXY))
; T if nothing but Xlines/Rays in current space, no extents defined by objects;
; EXTMIN is hugely positive / EXTMAX is hugely negative [reversed]; if so,
; ignore "false" extents later in favor of limits, which will always have non-
; zero dimensions both ways and cannot be reversed as extents can.
limLL (getvar 'limmin)
limUR (getvar 'limmax)
rangeLL (if noext limLL (mapcar 'min extminXY limLL))
rangeUR (if noext limUR (mapcar 'max extmaxXY limUR))
rangeLR (list (car rangeUR) (cadr rangeLL))
rangeUL (list (car rangeLL) (cadr rangeUR))
intB (inters xl1 xl2 rangeLL rangeLR nil)
; intersection of Xline with Bottom edge [or its extension]
intR (inters xl1 xl2 rangeLR rangeUR nil); with Right side
intT (inters xl1 xl2 rangeUR rangeUL nil); with Top edge
intL (inters xl1 xl2 rangeLL rangeUL nil); with Left side
); setq
(foreach corner (list intB intR intT intL)
(if
(and
(or ; X coordinate within range?
(<= (car rangeLL) (car corner) (car rangeUR))
; can sometimes "miss" at extremes with calculation rounding, so give it fuzz:
(equal (car rangeLL) (car corner) 1e-6) (equal (car rangeUR) (car corner) 1e-6)
); or
(or ; Y coordinate within range?
(<= (cadr rangeLL) (cadr corner) (cadr rangeUR))
(equal (cadr rangeLL) (cadr corner) 1e-6) (equal (cadr rangeUR) (cadr corner) 1e-6)
); or
(not (member corner ends)); don't duplicate if goes exactly through corner of range
); and
(setq ends (cons corner ends)); put in list of Line end points
); if
); foreach
(if (= (length ends) 2)
; Xline hits Limits/non-Xline Extents twice [points in list]
(command ; then
"_.line" "_none" (car ends) "_none" (cadr ends) "" "_.erase" xl ""
"_.chprop" "_last" "" "_layer" (cdr (assoc 8 xldata)) ""
); command
(prompt "\nXline does not cross Limits or [non-Xline/Ray] Extents of drawing."); else
); if
(princ)
); defun
(prompt "\nType XL2L to replace an Xline with a Line where it crosses the drawing Limits/Extents.")
@mostafabadran wrote:
thanks Kent Cooper for replay,my goal is xline to polyline keep the same length.
Maybe you don't understand what an Xline is. As has been mentioned several times, it has no length, but extends infinitely in both directions. It is not possible for a Polyline to do that. If my idea of making one that extends as far as the extents of other things in the drawing is not what you want, you will need to describe the result you are looking for in some other way.
Probably posted before somewhere already...
(vl-load-com) (defun c:Line2Xline (/ entmakexline ss i en p1 p2 j) (defun entmakexline (en p1 p2 / ed) (setq ed (entget en)) (entmake (vl-remove-if 'not (list '(0 . "XLINE") '(100 . "AcDbEntity") '(100 . "AcDbXline") (assoc 6 ed) ; lt name (assoc 8 ed) ; layer; possibly '(8 . "MyLayer") (assoc 48 ed); lt scale (assoc 62 ed); color (cons 10 p1) (cons 11 (mapcar '- p2 p1)))))) (if (setq ss (ssget "_:L" '((0 . "LINE,LWPOLYLINE")))) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i)))) (if (= "LINE" (cdr (assoc 0 (entget en)))) (entmakexline en (cdr (assoc 10 (entget en))) (cdr (assoc 11 (entget en)))) (repeat (setq j (fix (vlax-curve-getendparam en))) (if (not (equal (setq p2 (vlax-curve-getpointatparam en j)) (setq p1 (vlax-curve-getpointatparam en (setq j (1- j)))) 1e-6)) (entmakexline en p1 p2)))) (entdel en))) (princ) )
THANKS
@Anonymous wrote:
LINE TO XLINE
Another way to do that is RestoreXline.lsp with its ReX command, >here<. Because it was written to restore an Xline that has been unintentionally Trimmed or Broken, it works on either Lines or Rays, but not Polylines as in @ВeekeeCZ 's routine in Message 11. [But it will turn any Line or Ray into an Xline, not just one that was once an Xline.]