rrulep Posted March 31, 2017 Posted March 31, 2017 I want to select multiple text and sort them in x-coordinate and match the sort order to new selection set of text (red color).Then generate a polyline from the insertion point of the text (red color). refer to the image below. thanks guys . Quote
Grrr Posted March 31, 2017 Posted March 31, 2017 I don't see the text on the image being sorted by X nor Y, from the array you displayed. Either it would be: A1 A2 A4 A3 - descending Y sort A3 A4 A2 A1 - ascending X sort Ofcourse can the above can be reversed. Soo consider this: (defun C:test ( / c e o L ) (setq c (cdr (assoc 62 (tblsearch "LAYER" (getvar 'clayer))))) (setvar 'errno 0) (while (/= 52 (getvar 'errno)) ; Lee Mac's structure to prompt for (entsel) (setq e (car (nentsel "\nPick text <exit>: "))) (cond ( (= 7 (getvar 'errno)) (setvar 'errno 0) ) (e (setq o (vlax-ename->vla-object e)) (cond ( (not (vlax-property-available-p o 'InsertionPoint)) (princ "\nInvalid object.") ) ( (not (setq L (cons (vlax-get o 'InsertionPoint) L))) ) ( (<= 2 (length L)) (redraw) (grvecs (apply 'append (mapcar '(lambda (a b) (list c a b)) L (cdr L)))) ) ); cond ); e ); cond ); while (and (<= 2 (length L)) (LWPoly (LM:UniqueFuzz L 1e-3) 0) (redraw)) (princ) ); defun ;; Unique with Fuzz - Lee Mac ;; Returns a list with all elements considered duplicate to ;; a given tolerance removed. (defun LM:UniqueFuzz ( l f ) (if l (cons (car l) (LM:UniqueFuzz (vl-remove-if (function (lambda ( x ) (equal x (car l) f))) (cdr l) ) f ) ) ) ) (defun LWPoly (lst cls) ; Lee Mac again (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls) ) (mapcar (function (lambda (p) (cons 10 p))) lst) ) ) ) Quote
BIGAL Posted April 1, 2017 Posted April 1, 2017 Grr what you have done is good but is not the answer just pick the text {4 picks} from the drawing in the order you want, make a list of co-ords and make a pline. Grr You are right about sorting on X if you are picking say 4 texts A1 A2 A3 A4 then you have to search for that text in dwg and find co-ords of it and make pline. Other version is "A1 A2 A3 A4" single text again search and make pline. rrulep need to post a sample dwg or confirm exactly which method is it or all 3 ? Re 1st comment you can do lisp inside the "Pline pick point" so get text point so no need to make a list. ; create pline by picking points press enter when finished (command "_pline") (while (= (getvar "cmdactive") 1 ) (do the pick text here and return a point) ) Quote
Lee Mac Posted April 1, 2017 Posted April 1, 2017 Another: (defun c:textpoly ( / ass ent enx idx lst ss1 ss2 str vts xco ) (princ "\nSelect text defining sort order: ") (if (setq ss1 (ssget '((0 . "TEXT,MTEXT")))) (progn (setq ss2 (ssget "_X" (list '(000 . "TEXT,MTEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")) ) ) ) (repeat (setq idx (sslength ss1)) (setq enx (entget (ssname ss1 (setq idx (1- idx)))) str (cdr (assoc 1 enx)) ) (or (assoc str lst) (setq lst (cons (cons str (cadr (assoc 10 enx))) lst))) ) (repeat (setq idx (sslength ss2)) (cond ( (ssmemb (setq ent (ssname ss2 (setq idx (1- idx)))) ss1)) ( (setq ass (assoc (cdr (assoc 1 (setq enx (entget ent)))) lst)) (setq xco (cons (cdr ass) xco) vts (cons (cdr (assoc 10 enx)) vts) lst (vl-remove ass lst) ) ) ) ) (entmake (append (list '(000 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length vts)) '(070 . 0) ) (mapcar '(lambda ( n ) (cons 10 (nth n vts))) (vl-sort-i xco '<)) ) ) ) ) (princ) ) Quote
rrulep Posted April 3, 2017 Author Posted April 3, 2017 Another:(defun c:textpoly ( / ass ent enx idx lst ss1 ss2 str vts xco ) (princ "\nSelect text defining sort order: ") (if (setq ss1 (ssget '((0 . "TEXT,MTEXT")))) (progn (setq ss2 (ssget "_X" (list '(000 . "TEXT,MTEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")) ) ) ) (repeat (setq idx (sslength ss1)) (setq enx (entget (ssname ss1 (setq idx (1- idx)))) str (cdr (assoc 1 enx)) ) (or (assoc str lst) (setq lst (cons (cons str (cadr (assoc 10 enx))) lst))) ) (repeat (setq idx (sslength ss2)) (cond ( (ssmemb (setq ent (ssname ss2 (setq idx (1- idx)))) ss1)) ( (setq ass (assoc (cdr (assoc 1 (setq enx (entget ent)))) lst)) (setq xco (cons (cdr ass) xco) vts (cons (cdr (assoc 10 enx)) vts) lst (vl-remove ass lst) ) ) ) ) (entmake (append (list '(000 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length vts)) '(070 . 0) ) (mapcar '(lambda ( n ) (cons 10 (nth n vts))) (vl-sort-i xco '<)) ) ) ) ) (princ) ) This is exactly what I'm looking for. Perfect!!! Thanks Lee, Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.