Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help - How to put consecutive letters

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
arperezinf
1231 Views, 24 Replies

Help - How to put consecutive letters

Hi everyone

 

I'm new to the forum and autolisp programming, I need your help.

 

I have the following lsp code, which when I run it, create a code in this consecutive way:

 

PPP_001
PPP_002
PPP_003
PPP_n times.

 

I would like that instead of putting consecutive numbers, put letters for example like this:

 

PPP_A,
PPP_B ...
PPP_Z

 

And when you finish the alphabet, increase one more letter up to n times, like this for example.

 

PPP_AA,
PPP_BB ...
PPP_n times

 

This is the code

 

(defun c:NCAEM (/ #EntityCount GroupEntity Entity NSec TNSEC HUB valor) 
  (setq #EntityCount 0)
  (setq NSec 0)
  (setq HUB "PPP")
  (setq NSec (getint "\nEnter starting number: [001] "))

  (setq GroupEntity (ssget "x" (list (cons 0 "SPRSYMBOL") (cons 70 190))))

  (while (ssname GroupEntity #EntityCount) 

    (setq Entity       (ssname GroupEntity #EntityCount)
          #EntityCount (+ #EntityCount 1)
    )

    (SETQ TNSEC (itoa Nsec))
    (IF (= (strlen TNSEC) 2) (setq TNSEC (strcat "0" tnsec)))
    (IF (= (strlen TNSEC) 1) (setq TNSEC (strcat "00" tnsec)))

    (setq valor (strcat HUB "-" TNSEC))
    (IF (getlinksipre Entity 98) 
      ()
      (progn 
        (addlinksipre Entity 98 Valor)
        (chsprcolor Entity 1)
        (setq NSec (+ NSec 1))
      )
    )
  )

  (ALERT "Process completed satisfactorily!")
)

 

 

Where I need the letters to be is where it says "TNSEC"

 

(setq valor (strcat HUB "-" TNSEC))

 

Could you tell me how it can be done, that I have to change to put letters.

 

Thank you very much for reading my message and for your responses.
Greetings.

Labels (1)
24 REPLIES 24
Message 21 of 25
john.uhden
in reply to: arperezinf

I guess I'm not as sharp as one would guess (hmm... they all know better; no guessing required)

These numbers... 65190200207 and 451,

do they represent the only acceptable 70 codes for being re-IDed?

Meaning that any SPRSYMBOLs that don't have those codes should be excluded from processing?

Or should they be the only 70 codes that should be processed?

Or maybe there is a different list of 70 codes that should or shouldn't be processed?

Or maybe we should remove the 70 code from the ssget filtering?

The answer to these questions may make a huge difference in what gets processed.

BTW, from where do these *linkishmear functions come?  Is that in Map 2021?  I used to use various Map functions for importing and working with GIS data, but I don't recall having seen such function names.

John F. Uhden

Message 22 of 25
arperezinf
in reply to: arperezinf

Hello @john.uhden 

 

Thank you very much for your quick reply.

 

I will reply to your message.

 

Yes, those are the only numbers that represent the 70 acceptable codes for the 5 blocks that the lisp routine that you publish works with.

 

Yes, all SPRSYMBOLs that do not have these codes must be excluded.

 

I can't give you an answer to your last three questions, I just know that code 70 must be present for the lisp routine you post to work.

 

I also have no idea what those functions * linkishmear are, they don't come with map 2021, they are other programmed functions to which I don't have access to see their programming code.

 

getlinksipre (I think this function obtains the ID of the entity or element to which you want to add or change the value).
addlinksipre (I think this function adds the value to the entity or element to which you want to add or change the value).

 

Then I have other lisp routines that have these other functions inside them and I have no idea what they do because I don't have access to see their programming code either.

 

LinkidChange2 (I think this function looks for the ID that you want to change)
SpridChange2 (I think this function looks for the element whose ID value you want to change).

 

It seems to me that it complicates me with wanting to select the first element, if I leave the ritina as you code it before modifying it, it works perfect for me!

 

I am analyzing whether to continue moving forward with this that I asked or to leave the lisp routine like this, because as I have said several times the lisp routine works wonderfully.

 

Thank you very much for reading my message.
Greetings.

Message 23 of 25
john.uhden
in reply to: arperezinf

Alrighty then.

Try this out...

(defun c:NCAEM (/ ntos link #EntityCount GroupEntity Entity NSec TNSEC HUB) 
  (defun ntos (n) ;; by @Anonymous 2/10/17 and compacted by @john.uhden
    (if (< (setq n (1- n)) 26)
      (chr (+ 65 n))
      (strcat (ntos (/ n 26))(chr (+ 65 (rem n 26))))
    )
  )
  (defun link (Entity N / valor TNSEC)
    (IF (getlinksipre Entity 98) 
      ()
      (progn
	(setq NSec N)
        (SETQ TNSEC (ntos NSec))
        (setq valor (strcat HUB "-" TNSEC))
        (addlinksipre Entity 98 Valor)
        (chsprcolor Entity 1)
        (setq NSec (1+ NSec))
      )
    )
    T
  )
  (setq #EntityCount 0)
  (setq HUB "PPP")
  (and
    (setq Entity (car (entsel "\nSelect first SPRSYMBOL: ")))
    (or
      (and
        (= (cdr (assoc 0 (entget Entity))) "SPRSYMBOL")
	(vl-position (cdr (assoc 70 (entget Entity)))'(65 190 200 207 451))
      )
      (prompt "\nEntity selected is not a qualified SPRSYMBOL.")
    )
    (not (initget 6))
    (or
      (setq NSec (getint "\nEnter starting number <1>: "))
      (setq NSec 1)
    )
    (link Entity NSec)
    (setq GroupEntity
      (ssget "x"
        (list
          (cons 0 "SPRSYMBOL")
         '(-4 . "<OR")'(70 . 65)'(70 . 190)'(70 . 200)'(70 . 207)'(70 . 451)'(-4 . "OR>")
        )
      )
    )
    (setq GroupEntity (ssdel Entity GroupEntity))
    (while (setq Entity (ssname GroupEntity #EntityCount))
      (setq #EntityCount (1+ #EntityCount))
      (link Entity NSec)
    )
  )

  (ALERT "Process completed satisfactorily!")
)

John F. Uhden

Message 24 of 25
arperezinf
in reply to: arperezinf

Hello @john.uhden 👋

 

I just tried your lisp routine.👀

 

You are the best! 👏👍🙌🙏

Your lisp routine works great! 😀💣💥

 

Could you explain these parts of the code to me.

(= (cdr (assoc 0 (entget Entity))) "SPRSYMBOL")
(vl-position (cdr (assoc 70 (entget Entity))) '(65 190 200 207 451))
)

And this one too.

(list
(cons 0 "SPRSYMBOL")
'(-4. "<OR")' (70. 65) '(70. 190)' (70. 200) '(70. 207)' (70. 451) '(- 4. "OR>")
)

Thank you very much for your time, your patience, your great effort!
Greetings.

 

 

Message 25 of 25
john.uhden
in reply to: arperezinf

@arperezinf
Hey, you started it, so give yourself some credit, unlike the "needy" folk
who can't even (setq a 1) but want a freeware solution that they don't even
know how to run.
Most of the credit goes to @Anonymous for his alphanumeric function (I try to
remember to pack away the good ones when they come along).
If it seems like Doug is my favorite, it's probably because he is; plus we
both go back to the Compuserve days being entertained by the incantations
of T.T. and Grant & Elaine (you had to have been there).

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report