I am sharing a LISP,will help piping draughtsmans
Selected text will changed to: 25x
Will work for All pipe sizes
Solved! Go to Solution.
This would be a good application for a shared sub-routine, which can save you large quantities of code [and some other elements can be made more concise, too]. For example:
(vl-load-com); [if needed]
(defun numdia (num / a); = NUMber with DIAmeter symbol
(if (setq a (entsel (strcat "\nSelect the text you want to change to " num "dia : ")))
(vla-put-TextString (vlax-ename->vla-object (car a)) (strcat num "%%C"))
(defun C:1 () (numdia "1"))
(defun C:2 () (numdia "2"))
;....and all the others in between....
(defun C:900 () (numdia "900"))
(defun C:1000 () (numdia "1000"))
I am sorry to say that you have few issues to consider into your lisp routines .
1- Try to get used to localize variables in all routines .
2- Use if or cond functions to avoid errors if a user cancelled the routine before ending it normally .
3- You should check after each selection set if that selection is matching the same entity that you want to get .
Finally these codes are just copy and paste with a little changes , so look at the following routine which would work
instead of all your codes .
(defun c:Test (/ ss i sn) ;; Tharwat 02. Oct. 2012 ;;; (if (setq ss (ssget "_:L" '((0 . "*TEXT")))) (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i)))) (entmod (subst (cons 1 (strcat (cdr (assoc 1 (entget sn))) "%%c")) (assoc 1 (entget sn)) (entget sn) )))) (princ) )
Sharing actual code is preferred to relatively "blind" links to who-knows-where.
.... look at the following routine which would work instead of all your codes .
.... (entmod (subst (cons 1 (strcat (cdr (assoc 1 (entget sn))) "%%c")) ....
That will work as a substitute for all their different codes if the text they want to change to a number with a diameter symbol has that same number as its text content already. It will tack the diameter symbol onto the end of whatever the text content is, numerical or otherwise. On the other hand, their collection of routines [and my suggested adjustments] would substitute the command-name-number-plus-diameter-symbol in place of the entirety of any already-existing text content, again, numerical or otherwise.
Of course, only they can say which would be right for them, and others who want to adopt their number-as-command approach will have their own preferences. I can imagine situations in which the existing text content would not already be the pipe diameter number minus the diameter symbol. For instance, they might have a routine that draws pipe-route lines or polylines or something, for which they don't necessarily know the size(s) when they're laying out the routing. Such a routine might put in pieces of place-holder text, in appropriate places and with the right Layer and Style and size, whose content is just something meaningless [such as "..." or "--"], but which thereby have something to be selected by in one of their number-as-command-name commands, when they want to go back later and designate the pipe size(s). Or, they might want to use these commands to change the size designation of some pipe(s) -- they might have [for example] something that currently contains "20%%C" that they want to change to "25%%C", for which they would want to use their '25' command, rather than the 'test' command which would change it to "20%%C%%C".
I certainly agree with the improvements suggested, such as allowing selection of multiple objects, limiting it to things of appropriate entity type(s) that are not on locked Layers, and there are other controls that could be added, either within my suggested shared sub-routine or in all of their individual commands, if your add-the-diameter-symbol-to-anything approach isn't what they need. They could have error handling, Undo beginning/ending, etc.
But for people who can use the add-the-diameter-symbol-to-anything approach, it certainly saves a lot more code than my suggestion does, since it reduces it all to one command.