• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Contributor
    Posts: 25
    Registered: ‎02-14-2010
    Accepted Solution

    Sharing "TEXT CHANGE TO PIPE DIA IN SINGLE CLICK"

    218 Views, 5 Replies
    10-02-2012 09:28 AM

    Hi 

     

    I am sharing a LISP,will help piping draughtsmans

     

    Example:

     

    Command:  25

    Select text:

    Selected text will changed to:   25x

     

                    Will work for All pipe sizes 

     

    http://lispandtips.blogspot.com/2012/10/text-change-to-pipe-dia-in-single-click.html

     

     

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    Re: Sharing "TEXT CHANGE TO PIPE DIA IN SINGLE CLICK"

    10-02-2012 10:20 AM in reply to: anoopvarrghese009

    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"))
      ); if
    ); defun
     
    (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"))

    Kent Cooper
    Please use plain text.
    Valued Mentor
    _Tharwat
    Posts: 460
    Registered: ‎07-02-2010

    Re: Sharing "TEXT CHANGE TO PIPE DIA IN SINGLE CLICK"

    10-02-2012 10:29 AM in reply to: anoopvarrghese009

    Hi ,

     

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

     Tharwat

    Please use plain text.
    *Expert Elite*
    dgorsman
    Posts: 3,293
    Registered: ‎10-12-2006

    Re: Sharing "TEXT CHANGE TO PIPE DIA IN SINGLE CLICK"

    10-02-2012 11:29 AM in reply to: anoopvarrghese009

    Sharing actual code is preferred to relatively "blind" links to who-knows-where.

    ----------------------------------
    If you are going to fly by the seat of your pants, expect friction burns.
    Adopt. Adapt. Overcome. Or be overcome.


    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    Re: Sharing "TEXT CHANGE TO PIPE DIA IN SINGLE CLICK"

    10-02-2012 12:03 PM in reply to: _Tharwat

    _Tharwat wrote:

    .... look at the following routine which would work instead of all your codes .

     

    ....
          (entmod (subst (cons 1 (strcat (cdr (assoc 1 (entget sn))) "%%c"))
    ....

     Tharwat


    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.

    Kent Cooper
    Please use plain text.
    Contributor
    Posts: 25
    Registered: ‎02-14-2010

    Re: Sharing "TEXT CHANGE TO PIPE DIA IN SINGLE CLICK"

    10-02-2012 09:39 PM in reply to: anoopvarrghese009

    Thank you, your suggestions from Kent1Cooper,  Tharwat incorporated.

    anoop

    Please use plain text.