Reorder Attributes values

Reorder Attributes values

C.Utzinger
Collaborator Collaborator
3,562 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,563 Views
53 Replies
Replies (53)
Message 21 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

Sorry I take so much time from you...

 

Thanks again!


No worries, i needed the practice.

 

add num before the last parenthesis of the _padZero subfunction. 

 

(defun _padZero (num md)
(setq num (strcat "0" num))
      (while (< (strlen num) md)
		(setq num (strcat "0" num))
	)
      num
      )

 

HTH

 

0 Likes
Message 22 of 54

C.Utzinger
Collaborator
Collaborator

Now it counts correct, but i found a strange thing :(, sorry for hard testing :).

 

See the attachment.

0 Likes
Message 23 of 54

pbejse
Mentor
Mentor

"EG-01002"  <--what the?????  Hahaha

 

Its an easy fix, but go ahead and try it with more formats and values and report all the bugs and quirks you encounter. I'll be here.

0 Likes
Message 24 of 54

C.Utzinger
Collaborator
Collaborator

It was not a new formatSmiley Very HappySmiley Very HappySmiley Very Happy

 

It should be EG-1002 Smiley Very Happy

 

But I will try more...

0 Likes
Message 25 of 54

C.Utzinger
Collaborator
Collaborator

I think that is all.

 

I found another strange thing but i think it's the same like the other one.

 

 

Can you please fix this, I hope that is all.

 

Thank you again and again... 

0 Likes
Message 26 of 54

C.Utzinger
Collaborator
Collaborator

Just for understanding...

 

There will be no more formats, Smiley WinkSmiley WinkSmiley Wink.

 

I think i should have postet this before. Smiley FrustratedSmiley FrustratedSmiley Frustrated

 

Neue Bitmap.jpg

0 Likes
Message 27 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

I think that is all.



(defun _padZero (num md)
      (while (< (strlen num) md)
		(setq num (strcat "0" num))
	)
      num
      )

If there are no other bugs, I think that should do it. There was an extra line there before the while function

 

HTH

 

EDIT: Yeah, you should have at the get-go. Anyway. I had fun

 

Cheers

 

 

0 Likes
Message 28 of 54

C.Utzinger
Collaborator
Collaborator

COOOLLLL Thank you!!!

 

Post the hole code for Solution!

 

 

Kind regards

0 Likes
Message 29 of 54

pbejse
Mentor
Mentor
Accepted solution

@C.Utzinger wrote:

COOOLLLL Thank you!!!

 


 

Here at    Autodesk Community Logo  customer satisfaction is our priority. 

 

 

 bcm.jpg "One is glad to be of service".

 

 

 

 

 

 

 

pBe

 

Message 30 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

I have a Little problem...

 

I had to change the textformat of the block and know the code dont work with only numbers (001, 002, 003).

 

Could give help me please, i tried to modify the code but it is to much for me.

 

Attached the changed block, there is no width 0.7 anymore...

 

 

Thank you...

0 Likes
Message 31 of 54

C.Utzinger
Collaborator
Collaborator

I think i have a solution!!!

 

I changed the spilt function and now it works

 

(defun _split (lst i / numbers)
	(while (< 46  (setq n (if (/= i 0)(nth (setq i (1- i)) lst) (setq i (1- i)))) 58)   
			(setq numbers (cons n  numbers)))
      	(if (and numbers
                 (setq str (vl-list->string lst)))
		 (list (substr str 1 (1+ i)) (vl-list->string numbers))))

 

Is that so OK, or i just made a very stupid thing? Smiley LOL

0 Likes
Message 32 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

I think i have a solution!!!

 ....

Is that so OK, or i just made a very stupid thing? Smiley LOL


Well good for you Cree-G.

 

Haven't had the chance to try your mod yet. If it works for you then go for it. It's a learning opportunity for you. 

Tell us how it goes.

 

0 Likes
Message 33 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

I hope you remember this thread.

 

I was trying to rewrite the code for an other block (attached), but i failed.

 

Could you please help me with it?

 

 

Kind regards

 

 

0 Likes
Message 34 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

 ..I hope you remember this thread. 


Just barely.


@C.Utzinger wrote:

 

..I was trying to rewrite the code for an other block (attached), but i failed...  


I saw the blocks, Not sure what FillTheGap.lsp objective was, I'll have a look and get back to you in a few.

 

Message 35 of 54

pbejse
Mentor
Mentor

Question for you, are the values will be a as simple as "A".... "R" or "1" to "12"? no dash or any other symbol like "EG-100"?

0 Likes
Message 36 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

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.

 

Thank you in advance.

 

 

Kind regards

0 Likes
Message 37 of 54

C.Utzinger
Collaborator
Collaborator
And
0 Likes
Message 38 of 54

pbejse
Mentor
Mentor

@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

Message 39 of 54

C.Utzinger
Collaborator
Collaborator

HI

 

Perfect!!! Thank you very much!

 

I will change it a little bit, so there will be only one request for userinput.

 

And if it goes over Z I will try to add an alert.

 

 

Kind regards

0 Likes
Message 40 of 54

pbejse
Mentor
Mentor

@C.Utzinger wrote:

...Thank you very much!

 

 


You are welcome, Happy to help

 

pBe

 

0 Likes