Jump to content

Recommended Posts

Posted

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

742EFF9E-7D70-41CD-917D-B07C2FA3BC33.png.1a9d5df84761cf2dcd23d7e12654ca01.png

Snap-2

0D1AC95D-6549-4861-A037-4BEC3F0BCD96.png.e9cef60677eade83063a1899ca5283be.png

 

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)
)

 

Posted
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 

Posted
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.

Posted

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.

 

 

 

 

 

Posted

Hi @BIGAL

 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😃

 

Posted

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.

Posted
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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...