Jump to content

Need some lisp...


mfadzli

Recommended Posts

Understand what you want can you elaborate a bit more is it TEXT or Mtext, is it on one layer only. You can get all the text search for the 1st apha character then find the highest number add 1 and add text. Post a dwg for testing. As the quantity of text increases if not on one layer it may mean slight hesitation bewteen each one.

Link to comment
Share on other sites

Sorry for that simple question..hehe..

 

I'm looking for a lisp to increment Text

For example i have text "01" "02" "03" "04" "05" "06" need to replaced with "01R" "01Y" "01B" "02R" "02Y" "02B".

Just pick the text and it will replace and follow the sequence as above example.

 

For example see attached file.

Sample.dwg

Link to comment
Share on other sites

Sorry for that simple question..hehe..

 

I'm looking for a lisp to increment Text

For example i have text "01" "02" "03" "04" "05" "06" need to replaced with "01R" "01Y" "01B" "02R" "02Y" "02B".

Just pick the text and it will replace and follow the sequence as above example.

For example see attached file.

 

i try to figure out:

does it mean

9= "03B"?

28= "10R"?

38= "13Y"?

 

if i'm right, then you can try the code below,

command: BRY

select Text or Mtext

;Add incremental suffix B R Y
;hp# 22/07/14
;http://www.cadtutor.net/forum/showthread.php?87667-Need-some-lisp...

(defun C:BRY  (/  *error* e tx #)

(defun *error* (msg)
    (if (wcmatch (strcase msg) "*CANCEL*,*EXIT*")
     (princ msg)
     (princ (strcat "\n*Error: " msg))
   )
 )
 (while (setq e (entsel "\nSelect *TEXT: ")) ; *edited thanx mr.Tharwat
   (if	(and (setq e (car e))
     (setq tx (cdr (assoc 1 (entget e))))
     (/= (setq # (atof tx)) 0)
    ;(not (wcmatch (strcase tx) "*B,*R,*Y")) ; *removed
     		(numberp(read tx)) ; *added
     )

     (vla-put-textstring
(vlax-ename->vla-object e)
('((# / i n)
   (setq
    n
    (fix (abs #))
    i
    (rem n 3.))
   (strcat
    (if
     (minusp #)
     "-"
     (if
      (< n 10)
      "0"
      ""))
    (rtos
     (if
      (zerop i)
      (/ n 3.)
      (1+ (fix (/ n 3.))))
     2
     0)
    (cond
     ((zerop i) "B")
     ((= i 1) "R")
     ((= i 2) "Y"))))
  #)))))

(princ "command: BRY")
(princ)

Edited by hanhphuc
(while (/= (setq e... ) nil) ... ; thanx mr.Tharwat
Link to comment
Share on other sites

wow...thanks hanhphuc...you are awesome...this is what i want..

thanks for help.. i think i need to learn lisp from now...hehe..

Link to comment
Share on other sites

wow...thanks hanhphuc...you are awesome...this is what i want..

thanks for help.. i think i need to learn lisp from now...hehe..

 

you are welcome :)

i edit a bit which

i replaced: (not (wcmatch (strcase tx) "*B,*R,*Y"))

to: (numberp(read tx))

ie: It only works on numeric text, eg:01,02,03

so it won't mass up "kacau" alphabetic text eg:ABC,03X,P123, etc..

Link to comment
Share on other sites

you are welcome :)

i edit a bit which

i replaced: (not (wcmatch (strcase tx) "*B,*R,*Y"))

to: (numberp(read tx))

ie: It only works on numeric text, eg:01,02,03

so it won't mass up "kacau" alphabetic text eg:ABC,03X,P123, etc..

 

 

 

wow...thanks for that...

you can speak malay? hehe

Link to comment
Share on other sites

sorry this forum is for CAD & LISP topic hehe :)

i assumed you are Singaporean or Malaysian bcos they used to say "..lah" "..hehe" "..meh" etc..

i agree with @BIGAL: elaborate a bit more, there are a lot of distinguished gurus can help you too, who i also need their guide too

Link to comment
Share on other sites

i try to figure out:

does it mean

9= "03B"?

28= "10R"?

38= "13Y"?

 

How'd you come up with that hanhphuc? Can you explain it to the rest of us. :)

Link to comment
Share on other sites

How'd you come up with that hanhphuc? Can you explain it to the rest of us. :)

The pattern is sequence remainder of 3, to suffix R,Y,B :)

BRY.PNG

Link to comment
Share on other sites

 (while (/= (setq e (entsel "\nSelect *TEXT: ")) nil)

 

FYI , if a user selected any object (e.g TEXT in this routine ) it would return a value which is does not mean equal to nil at all , so to check for not equal to nil is not needed .

Link to comment
Share on other sites

FYI , if a user selected any object (e.g TEXT in this routine ) it would return a value which is does not mean equal to nil at all , so to check for not equal to nil is not needed .

 

oops.. mr.Tharwat you are correct: (while T... ),

your (esp senior members) comments, guide, debug etc.. are very appreciated in order i can improve learning from mistake.

Thanks again cheers :)

 

@pBe: you are welcome

Link to comment
Share on other sites

oops.. mr.Tharwat you are correct: (while T... ),

your (esp senior members) comments, guide, debug etc.. are very appreciated in order i can improve learning from mistake.

Thanks again cheers :)

 

It's kind of you to say that , and you're welcome. :)

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