harimaddddy Posted October 27 Share Posted October 27 Hi all, I need some help from pros, but my English is not good .  I'm use this 1 command to align the text with custom insertion point and evenly distributed, the issues are listed below,  1. When I select the text entities with green window (snap-1) it reorder all text entities by itself (snap-2), I might select a group of texts labeled 5 to 7 first, then select another group from 1 to 4, and finally include text labeled 8. However, when I look at the selection afterward, the order is not what I expected (snap-2); it seems to rearrange itself instead of keeping the sequence I selected them in. Snap:1 Snap-2  2.If i use undo it affect the osmode , so that i use a error handler.  Thanks in advance....  (defun c:1() (command "ucs" "world") (setq objs (ssget '((0 . "TEXT")))) (Setq scalef (/ (cdr(assoc 40(entget(ssname objs 0))))9)) (setq x_x (* scalef 4.0)) (setq y_y (* scalef 4.0)) (setq text_gap (* scalef 16.0)) (setq text_height (* scalef 9.0)) (setq ss_len (sslength objs)) (setq osm (getvar "osmode")) (command "osnap" "end") (setq cxy (getpoint "pick a point")) (command "osmode" 0) (setq cx (car cxy)) (setq cy (car (cdr cxy))) (setq count 0) (setvar "osmode" 16383) (repeat ss_len (if (= count 0) (progn (setq tx1 (+ cx x_x)) (setq ty1 (+ cy (/ (+ (* (- ss_len 1.0) text_gap) text_height) 2 ) ) ) (setq tx2 tx1) (setq ty2 (- ty1 text_height)) ) (setq ty2 (- ty2 text_gap)) ) (setvar "osmode" 16383) (setq obj (ssname objs count)) (setq objp (entget obj)) (setq objj_new (cons 72 0)) (setq objc_11 (cons 11 (list 0 0 0))) (setq objc_10 (cons 10 (list tx2 ty2 0))) (setq objp (subst objc_10 (assoc 10 objp) objp)) (setq objp (subst objc_11 (assoc 11 objp) objp)) (setq objp (subst objj_new (assoc 72 objp) objp)) (entmod objp) (setq count (+ count 1)) ) (setvar "osmode" 16383) (setq lpx1 (+ cx (* 12.0 SCALEF))) (setq lpx2 cx) (setq lpx3 cx) (setq lpx4 lpx1) (setq lpy1 (+ ty1 x_x)) (setq lpy2 lpy1) (setq lpy3 (- ty1 (+ (+ (* text_gap (- count 1)) text_height) (* scalef 5.0)) ) ) (setq lpy4 lpy3) (setq lp1 (list lpx1 lpy1)) (setq lp2 (list lpx2 lpy2)) (setq lp3 (list lpx3 lpy3)) (setq lp4 (list lpx4 lpy4)) (setq clay (getvar "clayer")) (setvar "clayer" "0-25text") (if(> ss_len 1) (progn (command "pline" lp1 lp2 lp3 lp4 "") ) ) (setvar "osmode" 16383) (setvar "clayer" clay) )  Quote Link to comment Share on other sites More sharing options...
devitg Posted October 27 Share Posted October 27 @harimaddddy, please upload such sample.dwg . Â Quote Link to comment Share on other sites More sharing options...
harimaddddy Posted October 27 Author Share Posted October 27 @devitg 1 command.dwg1&2 command.lsp attached are the respective sample dwg and lisp file brother... Quote Link to comment Share on other sites More sharing options...
devitg Posted October 27 Share Posted October 27 11 minutes ago, harimaddddy said: @devitg 1 command.dwg1&2 command.lsp attached are the respective sample dwg and lisp file brother... @harimaddddy could it be a text first number > 9 , say 15 , or worse > 99 , say 134 ?  By the way , where are you.? I'm at Córdoba Argentina Quote Link to comment Share on other sites More sharing options...
harimaddddy Posted October 27 Author Share Posted October 27 Just now, devitg said: By the way , where are you.? I'm at Córdoba Argentina I'm at India  Just now, devitg said:  could it be a text first number > 9 , say 15 , or worse > 99 , say 134 ? I added the numbers to make things clearer, but if I remove them, it still works the same way. I can't find how the code processes the selected text by green selection window. It works by selecting the text individually. Quote Link to comment Share on other sites More sharing options...
devitg Posted October 27 Share Posted October 27 Ok, I'll see it later. Quote Link to comment Share on other sites More sharing options...
harimaddddy Posted October 27 Author Share Posted October 27 @devitgok sir Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 27 Share Posted October 27 I think your talking about select by window, so a selection is by creation order not by display order. As your looking for a lisp you can sort the "textstring" by the Y value so will be in correct order. Â Another no code is use "Txt2mtxt" a built in command. It will make a mtext of your text with fixed spacing but that can be changed. Â So a few code changes (setq objs (ssget '((0 . "TEXT")))) (setq lst '()) (repeat (setq x (sslength objs)) (setq obj (vlax-ename->vla-object (ssname objs (setq x (- x 1))))) (setq txt (vlax-get obj 'textstring)) (setq ins (vlax-get obj 'insertionpoint)) (setq lst (cons (list (cadr ins) txt) lst)) ) (setq lst (vl-sort lst '(lambda (x y)(>(car x)(car y))))) So if you look at "lst" it is the text in a sorted order. The rest of the code needs to be amended to suit a list of the text rather than a selection set. Use (cadr of each item in the list to get the text. Use a Foreach rather than a repeat as this will auto loop through the lst. Â So have a go, if you get stuck just ask. Â Â Â Â Â Quote Link to comment Share on other sites More sharing options...
harimaddddy Posted October 28 Author Share Posted October 28 Hi @BIGAL Screen Recording 2024-10-28 071748.mp4  The video i have attached is the issue,  (Updated code) When I try to reorder the text by selecting individually, it doesn’t work as expected. I want to order it from 1 to 8, but some numbers are placed next to each other (as in video), so I use the green selection window. For single numbers, I pick them alone. It should work with both the green selection window and individual selection in the order I choose.  Thanks a lot to look into it brother  Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 28 Share Posted October 28 If your going to do pick pick pick you must only select 1 item at a time, do not use window and select 2 lines. Then it should work. Quote Link to comment Share on other sites More sharing options...
harimaddddy Posted October 28 Author Share Posted October 28 31 minutes ago, BIGAL said: If your going to do pick pick pick you must only select 1 item at a time, do not use window and select 2 lines. Then it should work. I've been using the fencing option to select text entities in order, but it takes a lot of time. I'm thinking about skipping that option. Quote Link to comment Share on other sites More sharing options...
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.