Jump to content

Reorder objects


gibenner

Recommended Posts

Hello everyone! There are text objects, each figure is a separate object, which has the following order:

 

1 6 3

4 7 2

5 8 9

 

The It should be possible procedurally always change it to the following procedure:

 

1 2 3

4 5 6

7 8 9

 

I tried to use the sort function on X and Y, but it is not the result that is obtained. Is there a way to sort on two axes at once or is there a simpler solution? It's probably obvious, but I do not see it)

Link to comment
Share on other sites

Did you try this ?

 

(setq l [b][color=red]'[/color][/b](4 7 8 2 1 6 3 5 9))
(vl-sort l [b][color=red]'[/color][/b]<)

 

What is the differance

(setq l (4 7 8 2 1 6 3 5 9))
(vl-sort l <)

Link to comment
Share on other sites

What is the differance

(setq l (4 7 8 2 1 6 3 5 9))
(vl-sort l <)

 

You need to read about the quote function to know the differences between these two situations .

Link to comment
Share on other sites

This was kind of fun...

 

What you need to keep in mind is that, in your drawing, it appears that your '1' is below '2&6' and your '9' is below your '8' so the order in which my program will sort will take hat into account and it wont look right as it sorts from upper left to lower right. I'm sure you can take it and mess around with it to fit your needs though

 

(defun c:ArrangeText ( / textSS textList sortedTextList sortedPointList)
 (vl-load-com)
 (if (setq textSS (ssget "x" (list (cons 0 "TEXT")(cons 410 "Model"))))
   (progn
     (setq textList (mapcar 'vlax-ename->vla-object  (vl-remove-if 'listp (mapcar 'cadr (ssnamex textSS)))))
     (setq sortedTextList (vl-sort textList '(lambda (x y) (< (atoi (vla-get-Textstring x)) (atoi (vla-get-Textstring y))))))
     (setq sortedPointList (SortPoints (mapcar '(lambda (x) (vlax-get x "InsertionPoint")) textlist)))
     (mapcar '(lambda (x y) (vlax-put x "InsertionPoint" y)) sortedTextList sortedPointList)
     ))
     
     
 )
(defun SortPoints ( l )
 (setq l
 (vl-sort l
   '(lambda (x y)
      (cond
        ((= (cadr x)(cadr y))
  (< (car x)(car y)))
        ((> (cadr x)(cadr y)))
        )
      )
   )
)
 )

Link to comment
Share on other sites

Thank you guys for responding! In fact of the matter is that will not be known in advance the position of text in different cases, it can be located in different ways. This is the whole problem and have a predictable outcome. I see the script may try to add it by yourself.

Link to comment
Share on other sites

Thank you guys for responding! In fact of the matter is that will not be known in advance the position of text in different cases, it can be located in different ways. This is the whole problem and have a predictable outcome. I see the script may try to add it by yourself.

 

You can try to add some "fuzz" in the code so that if the text is slightly lower than the other it will still count as in line. Also, I tested it on different alignments, and it doesn't seem to work on all alignments, someone else may be able to explain why...

Link to comment
Share on other sites

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