Reorder Attributes values

Reorder Attributes values

C.Utzinger
Collaborator Collaborator
3,574 Views
53 Replies
Message 1 of 54

Reorder Attributes values

C.Utzinger
Collaborator
Collaborator

Hi

 

I have the attached block with one Attribute.

 

I'm looking for a Lisp code to reoder the given values. Like:

 

EG-001, EG-002, EG-003, EG-003, EG-007, EG-010 ---> EG-001, EG-002, EG-003, EG-004, EG-005, EG-006.

 

I tried some codes i found in other Forums, but nothing worked.

 

Please help...

0 Likes
Accepted solutions (2)
3,575 Views
53 Replies
Replies (53)
Message 41 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

I have a little quiestion.

 

Is there a possibility to influence the order?

I mean for example, take strictly the order of insert.

Difficult for me to explain.

For example I introduce 4 or 5 blocks, then i change the first ones and then i reorder them all. Somehow the last inserted one gets the now first one A-A.

It should be cool if it's possible to order them strictly by the order of insert.

 

 

(Defun ut:ordnen  ( / opt start ss attVal_collection attval num str sstyp loop flt)

;; Fill The Gap Section Tag  ;;
;; pBe Feb 2018   ;;
(setq *str* (cond ((not *str*) "A") ((numberp *str*)(itoa *str*)) (*str*))) (while (not loop) (setq opt (getstring (strcat "\nStartnummer/-buchstabe eingeben <" *str* ">: ")) opt (if (= opt "") *str* opt)) (cond ((= opt "0")(princ "\n0-Wert ist nicht erlaubt!")) ((< (atoi opt) 0)(princ "Keine negativen Werte erlaubt!")) (T (setq loop 1))) ) (setq start (cond ((and (= (atoi opt) 0) (setq str (cond ((snvalid opt ) (strcase opt)) (*str*) ("A"))) (wcmatch str "[A-Z]") ) (setq sym (list ascii chr)) str ) ((setq num (atoi opt)) (setq sym (list atoi itoa)) (itoa num) ) ) ) (initget "Alle Wählen") (setq sstyp (getkword "\nAuswahl Schnittbezeichnungen [Alle/ Wählen] <Alle>:") flt "spi-schnitt,spi-schnitt-winkel,spi-schnitt-versetzt") (if (and start (setq attVal_collection nil ss (if (= sstyp "Wählen") (ssget (list '(-4 . "<OR") '(-4 . "<AND") '(0 . "INSERT") (cons 2 flt) '(66 . 1)'(-4 . "AND>") '(-4 . "OR>"))) (ssget "_X" (list '(-4 . "<OR") '(-4 . "<AND") '(0 . "INSERT") (cons 2 flt) '(66 . 1) '(-4 . "AND>") '(-4 . "OR>"))) ) ) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (and (setq attval (mapcar (function (lambda (at / num) (list (vla-get-tagstring at) (vla-get-textstring at) at ) ) ) (vlax-invoke e 'Getattributes) ) ) (vl-every '(lambda (tag) (member (Car tag) '("LINKS" "RECHTS"))) attval) ) (setq attVal_collection (cons (list (cadar attval) (mapcar 'last attval) ) attVal_collection ) ) ) ) (foreach itm (vl-sort attVal_collection '(lambda (a b) (< (car a) (car b)))) (cond ( (eq (Car itm) start) ) ( (mapcar '(lambda (at)(vla-put-textstring at start)) (cadr itm)) ) ) (setq start (1+ ((car sym) start)) start ((cadr sym) start) ) ) ) (princ (strcat "\n<<< " (cond ( (null start) (setq str nil) "Invalid Input >>>" ) ( (null ss) "Null Selection >>>" ) ) ) ) ) (setq *str* (cond (str) (num))) (princ) ); end of defun

 

Kind regards

0 Likes
Message 42 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

 

Is there a possibility to influence the order?

I mean for example, take strictly the order of insert.

Difficult for me to explain.

For example I introduce 4 or 5 blocks, then i change the first ones and then i reorder them all. Somehow the last inserted one gets the now first one A-A.

It should be cool if it's possible to order them strictly by the order of insert.

 

 

 


That can be arranged. any drawing sample?

 

EDIT: Was that inserted or copied or both?

 

Message 43 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

Attached a sample.

 

 

Thank you very much.

 

 

Regards

0 Likes
Message 44 of 54

pbejse
Mentor
Mentor

A quick mod

 

 

....
(repeat (sslength ss) (setq e (vlax-ename->vla-object (ssname ss 0))) (if (and (eq "SPI-SCHNITT" (strcase (vla-get-effectivename e))) ...... ) (ssdel (ssname ss 0) ss) ) (foreach itm attVal_collection (cond ( (eq (Car itm) start) ) ( (mapcar '(lambda (at)(vla-put-textstring at start)) (cadr itm)) ) ) (setq start (1+ ((car sym) start)) start ((cadr sym) start) ) )
...

 

 

 

 

Message 45 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

Thanks for the quick mod.

 

It is not exactly what I expected. Now all new inserted, copies are forced to be at the end. Renamed ones goes back to the orignial order.

 

I think the first Routine was better. Only that the copied and the renamed ones get the right order:

 

Now:                    B-B (original) - B-B (copy/ or renamed to)  -->  after oder: C-C (original) - B-B (copy/ or renamed to).

Would be better : B-B (original) - B-B (copy/ or renamed to)  -->  after oder: B-B (original) - C-C (copy/ or renamed to).

 

 

Thanks for your help

0 Likes
Message 46 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

Thanks for the quick mod.

 

It is not exactly what I expected. Now all new inserted, copies are forced to be at the end. Renamed ones goes back to the orignial order.

 


Not really sure what's what Cree-G  but i'm sure you'll figure it out Smiley LOL

 

Sorry i coulee be of any more help

 

Cheers

Message 47 of 54

C.Utzinger
Collaborator
Collaborator

Smiley LOL

0 Likes
Message 48 of 54

C.Utzinger
Collaborator
Collaborator

@pbejse wrote:

@C.Utzinger wrote:

 

....Yes, just A to Z, and 1 to max. 99.

 

I would be cool to have the posibility to switch between numbers an chars, from A to 1 or 1 to A.

 

 

Kind regards


 

(Defun c:FTGST  ( / opt start ss attVal_collection attval)

;;		Fill The Gap Section Tag  	;;
;;		pBe Feb 2018		  		;;

(initget 1 "Letter Number")
(setq opt (getkword "\nChoose option [Letter/Number]: "))
(setq start
		  (cond
		    	(	(and (eq opt "Letter")
		  			(setq str_T (strcase (getstring (strcat "\nEnter start Letter <" (cond (str) ("A")) ">: "))))
					(setq str (cond ((snvalid str_T ) (strcase str_T)) (str) ("A")))
					(wcmatch str "[A-Z]")
					)	(setq sym (list ascii chr))
			 			str
			)
		    (		(eq opt "Number")
			 		(setq num (cond ((getint (strcat "\nEnter start Number <" (itoa (setq num
						              (cond ( num ) ( 1 )))) ">: "
						        )
						      )
						    ) ( num ) ))
					(setq sym (list atoi itoa))
					(itoa num)
			 			)
			)
		  )			 

	(if (and
		 start
		 (setq attVal_collection nil
			 ss (ssget "_:L" '((0 . "INSERT")
	                       (66 . 1)
	                       (2 . "spi-schnitt,`*U*"))))
		    )
		  (progn
		    (repeat (setq i (sslength ss))
				(setq e (vlax-ename->vla-object  (ssname ss (setq i (1- i)))))
				(if
				  (and
				    (eq "SPI-SCHNITT" (strcase (vla-get-effectivename e)))
				    (setq
					 attval (mapcar
							(function
							  (lambda	(at / num)
							    (list	(vla-get-tagstring at)
									(vla-get-textstring at)
									at
							    )
							  )
							)
							(vlax-invoke e 'Getattributes)
						   )
				    )
				    (vl-every '(lambda (tag)
							  (member (Car tag) '("LINKS" "RECHTS"))) attval)
				    )
				    (setq	attVal_collection
						 (cons
						   (list (cadar attval)
							    (mapcar 'last attval)
						   )
						   attVal_collection
						 )
				    )
				  )
			  )
		    
		    (foreach itm (vl-sort attVal_collection '(lambda (a b) (< (car a) (car b))))
			 	(cond
					(	(eq (Car itm) start)	)
				   	(	(mapcar '(lambda (at)(vla-put-textstring at start)) (cadr itm))	)
						)
				  (setq start (1+ ((car sym) start))
			 		   start ((cadr sym) start)
					   )
			 )
		    )
	  (princ (strcat "\n<<< "
	    (cond 
		 (	(null start) (setq str nil) "Invalid Input >>>"	)
		 (	(null ss)	"Null Selection >>>"		)
		 		)
			)
	    )
	  )
  (princ)
    )

Command: FTGST
Choose option [Letter/Number]: L

Enter start Letter <F>: a
Select objects: Specify opposite corner: 4 found

Select objects:

 

Command: FTGST
Choose option [Letter/Number]: N
Enter start Number <1>:

Select objects: Specify opposite corner: 4 found

Select objects:

 

HTH




HI

OK! Last try Smiley LOL

This is your first routine and i'm still using this one, it's better so!

The only thing I wish to change is when you copy one block for example A-A and then reorder, the copy should be B-B.
At the moment the copy stays A-A and the original one gets B-B.


Thank you in advance...

Best regards
0 Likes
Message 49 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:
...The only thing I wish to change is when you copy one block for example A-A and then reorder, the copy should be B-B.
At the moment the copy stays A-A and the original one gets B-B..

I think I understand now, I will look into it, its the weekend after all.

 

You are introducing a new section target B-B that then bump original B-B to be C-C and so forth?

 

Message 50 of 54

C.Utzinger
Collaborator
Collaborator

@pbejse wrote:

 

You are introducing a new section target B-B that then bump original B-B to be C-C and so forth?


 

I'm not sure if I understand your question.

 

The new section target B-B (no matter if new one or copy of existing one)  should be C-C after reorder.

0 Likes
Message 51 of 54

C.Utzinger
Collaborator
Collaborator

Another questionSmiley Frustrated

 

What is `*U*?

 

Without that, when i modifie the length of the dinamic block, it gets not selected and obviousely not reordered.

With that, an other block named spi-schnitt-k (copy) gets selected and reordered (and this one should not!!!).

 

 

 

(initget "Alle Wählen")
(setq sstyp (getkword "\nAuswahl Schnittbezeichnungen [Alle/ Wählen] <Alle>:")
      flt "spi-schnitt,spi-schnitt-winkel,spi-schnitt-versetzt,`*U*")

	(if (and start
		 (setq attVal_collection nil
			 ss (if (= sstyp "Wählen")
                                (ssget (list '(-4 . "<OR")
			                     '(-4 . "<AND") '(0 . "INSERT") (cons 2 flt) '(66 . 1)'(-4 . "AND>")
                                             '(-4 . "OR>")))
                                (ssget "_X" (list '(-4 . "<OR")
			                          '(-4 . "<AND") '(0 . "INSERT") (cons 2 flt) '(66 . 1) '(-4 . "AND>")
                                                  '(-4 . "OR>")))
                            )
                 )
            )

 

Kind regards

0 Likes
Message 52 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

Sorry for annoing you again

 

I just discoverd that when you have more than 10 sections (with numbers), then the new order is a little arbitrarily. It takes 10 as 2.

 

 

Kind regards

0 Likes
Message 53 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

HI

 

Sorry for annoing you again

 

I just discoverd that when you have more than 10 sections (with numbers), then the new order is a little arbitrarily. It takes 10 as 2.

 

 

Kind regards


Smiley LOL , no worries, what you describe actually happened when i was testing the code. And THAT is one more factor to consider.

 

Currently working on a fix and guidelines to run the routine effectively. Hang in there, 

 

pBe

 

 

 

Message 54 of 54

pbejse
Mentor
Mentor
Accepted solution

Your modifed / modiried / modified lisp [ attachment ]

 

http://autode.sk/2F8GsGh