change list elements as per given list

change list elements as per given list

avinash00002002
Collaborator Collaborator
942 Views
10 Replies
Message 1 of 11

change list elements as per given list

avinash00002002
Collaborator
Collaborator

Hi!

I want to change the list element value from block lists

My list is as below and want to change:

("H6" "H1" "H6" "H6" "H6" "H2" "H2" "H2" "H2" "H2" "H2" "H2" "H2" "H18" "H18" "H2" "H2" "H2" "H18" "H18" "H2" "H2" "H18" "H6" "H6" "H6" "H6" "H6" "H6")

 

where "H6" to "Hole6"

"H2" to "Hole2"

"H18" to "Hole18"

"H1" to "Hole1" etc. block list are more like Hole1 to Hole18.

 

Please Help!

0 Likes
Accepted solutions (1)
943 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant

I'm really sad for you that after so many examples that you received from us you are not able to put together a function so simple.

Stop begging for help! Learn yourself!

Message 3 of 11

hak_vz
Advisor
Advisor
Accepted solution
(defun repl_prefix (lst / oldpref newpref)
(defun srpf (e)(vl-string-subst newpref oldpref e))
(setq oldpref (getstring "\nEnter string prefix value to be replaced >"))
(setq newpref (getstring "\nEnter new prefix value >"))
(mapcar 'srpf lst)
)
Command: (setq lst '("H6" "H1" "H6" "H6" "H6" "H2" "H2" "H2" "H2" "H2" "H2" "H2" "H2" "H18" "H18" "H2" "H2" "H2" "H18" "H18" "H2" "H2" "H18" "H6" "H6" "H6" "H6" "H6" "H6"))
Command: (setq newlst(repl_prefix lst))
Enter string prefix value to be replaced >H
Enter new prefix value >Hole
("Hole6" "Hole1" "Hole6" "Hole6" "Hole6" "Hole2" "Hole2" "Hole2" "Hole2" "Hole2" "Hole2" "Hole2" "Hole2" "Hole18" "Hole18" "Hole2" "Hole2" "Hole2" "Hole18" "Hole18" "Hole2" "Hole2" "Hole18" "Hole6" "Hole6" "Hole6" "Hole6" "Hole6" "Hole6")

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 11

-didier-
Advisor
Advisor

Bonjour @avinash00002002 

 

I’m not sure that I understand.

I’m assuming it’s a replacement for letters in the string list.

If this is the case, this line of code will do the work.

(mapcar '(lambda ( s ) (strcat (strcase (substr s 1 1)) "ole" (substr s 2))) lst)

Amicalement

 

 

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 5 of 11

hak_vz
Advisor
Advisor

I agree with @ВeekeeCZ . It is final time for you to start learning autolisp. Search Autocad help or use internet to find solutions. Next time try to write your own code and if in trouble someone will help you.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 6 of 11

-didier-
Advisor
Advisor

Hello @ВeekeeCZ 

 

Sorry, while I was doing my reply message, you intervened.

I didn’t know this detail, and I’m sorry because I don’t like the requests of people who ask for solutions without making the effort to learn.

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 7 of 11

avinash00002002
Collaborator
Collaborator

Hi!

I am learning AutoLISP and its function uses, but I can't understand to put together in some situations. After I tried so many times and I reached to you for help, next time when I will stuck up I will post along with my tried Code.

 

Thanks for you help.

 

Avinash

0 Likes
Message 8 of 11

ВeekeeCZ
Consultant
Consultant

@avinash00002002 wrote:

Hi!

I am learning AutoLISP and its function uses, but I can't understand to put together in some situations. After I tried so many times and I reached to you for help, next time when I will stuck up I will post along with my tried Code.

Thanks for you help.

Avinash


 

You know what... you can't start learning from LISTs, MAPCARs and LAMBDAs. They are not so straightforward to understand. Maybe this task of yours that you've worked on for weeks is yet too difficult for you.

 

You really need to start with the basics. Before you move to LISTs, make sure that you know FOREACH, WHILE, or REPEAT loops well. Learn how to create custom functions (defun). Then you can move forward to anonymous ones (lambda).

 

We would love to help you, but now... the current way... you're not even capable clearly tell what you need, every single thread of yours blows to gigantic length with no result, with no benefit to anyone. And on the top... there is this language issue.

IMHO ... learn to program a little more and once you will understand it better, you'll be able to better describe what you need and it would be easier for us to help you.

 

Good luck!

Message 9 of 11

john.uhden
Mentor
Mentor

@avinash00002002 ,

I don't quite get it.

What's the point of just modifying a list?  Might you actually want to rename blocks?

IOW, what do you plan to do with your revised list?

And why are there so many repetitions in the list?

John F. Uhden

0 Likes
Message 10 of 11

calderg1000
Mentor
Mentor

Regards @avinash00002002 

What a pleasure to know that you are already starting to program with Autolisp; insurance requires a lot of effort and dedication.
Here I will give you a different procedure to use the somewhat complicated but great Mapcar and Lambda.

Example for a list of one item

;;;------------------------------
(setq lt1'("H1"))
(setq t1 (nth 0 lt1))
(setq t1 (substr t1 2 1))
(setq nt1 (strcat "hole" t1))
(cons  nt1 '() )
;;;-----------------------------

Example for a list of two items

;;;-----------------------------
(setq lt1'("H1" "H2"))
(setq lt1f())
(repeat (setq i(length lt1))
  (setq tn(nth (setq i(1- i)) lt1))
  (setq tn(substr tn 2 1))
  (setq ntn(strcat "Hole" tn))
  (setq lt1f(cons ntn lt1f))
  )
(princ lt1f)
;;;----------------------------

By iterating this way you can get the results for a list of "n" elements. Sorry for the translation


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 11 of 11

avinash00002002
Collaborator
Collaborator

@john.uhden

Yes, I want to rename the block. Function is getting different name from GA drawing and for preparing shop drawing block name is different.

 

@calderg1000

yes, I have started learning LISP. Would you like to suggest a good book.

 

Thanks everyone

 

Avinash

 

 

0 Likes