Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Need a script to (xx)

  1. #1
    100 Club aharris's Avatar
    Join Date
    2003-08
    Location
    Lubbock, TX
    Posts
    106
    Login to Give a bone
    0

    Default Need a script to (xx)

    I'm needing some sort of script that will put ( ) around numbers. I don't think I have any over 99, so if it worked with 2 digits it would save me a ton of time.

    Example:So I've got an existing number of 25 and I need it to read (25).

    Thanks!!!

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    Do you want something like this one?
    Code:
    (setq num 25)
    (setq res (vl-princ-to-string (read (strcat "(" (itoa num) ")"))))
    or:
    Code:
    (setq num "25")
    (setq res (strcat "(" num ")"))
    ~'J'~

  3. #3
    100 Club aharris's Avatar
    Join Date
    2003-08
    Location
    Lubbock, TX
    Posts
    106
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    If I understand the code correctly, neither...???

    Let me expand it a little more: I've got text numbered 1 through 99 through out the drawing, multiple times. Now I need to change 1 to 99 to (1) to (99). So, I guess I gave a bad example, 25 was just a number, but I've got numbers from 1 all the way to 99. I even have 23-1, 23-2, 23-3 numbers or even 23-1A in a few places. But to keep the code simple, I'd be happy with .lsp program that does 10 to 99.

  4. #4
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    Here is an old one you can change to suit you needs.

    Code:
    (defun c:PAR(/ tset1 tlng1 to1 to2 tx1 tx2 ntx to3)
        ; Adds parenthes to ending and beginning
        
        (command "_.undo" "_end")
        (command "_.undo" "_group")
        
        (prompt "\nSelect text to put parenthesis around: ")
        (setq tset1 (ssget '((0 . "*TEXT"))))
        (if (= tset1 nil)
            (setq tlng1 0)
            (setq tlng1 (sslength tset1))
        )
        
        (while (/= tlng1 0)
            (setq to1 (ssname tset1 0))
            (setq to2 (entget to1))
            (setq tx1 (assoc 1 to2))
            (setq tx2 (cdr tx1))
            (setq ntx (strcat "(" tx2 ")"))
            (setq to3 (subst (cons 1 ntx) tx1 to2))
            (entmod to3)
            (entupd to1)
            (ssdel to1 tset1)
            (setq tlng1 (1- tlng1))
        )
        
        (command "_.undo" "_end")
        (princ)
    )

  5. #5
    100 Club aharris's Avatar
    Join Date
    2003-08
    Location
    Lubbock, TX
    Posts
    106
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    I got an error loading it.

    ; error: bad argument type: numberp: nil

  6. #6
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    Can you post what the command lines says when you run the code. Are you able to select objects? I just tried it, and it worked when I selected something and when I didn't, so I'm not sure why it errored one you.

  7. #7
    100 Club aharris's Avatar
    Join Date
    2003-08
    Location
    Lubbock, TX
    Posts
    106
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    Well, maybe I should start off by saying after 20 years in AutoCAD, I still don't really do .lsp. I know just enough to hack someone elses code, but to start new, I just can't do it. Html code, I'm not bad at that .

    Anyway, this is the error I get:

    Command: (LOAD "PAR")
    ; error: bad argument type: numberp: nil

    Oh, also running AutoCAD MAP 2007 on this computer.

  8. #8
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    You can just copy/paste the code to the command line, and the just type 'par' at the command line to run it. If you want to put it in a file, then you need to copy/paste it to a file, and save the file with a .lsp extension, and then load the file. If the file is in the search path, then you can just type '(load "filename.lsp")' if it's not then you need to type in the whole path.

    Hope the helps.

  9. #9
    100 Club aharris's Avatar
    Join Date
    2003-08
    Location
    Lubbock, TX
    Posts
    106
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    Quote Originally Posted by T.Willey View Post
    You can just copy/paste the code to the command line, and the just type 'par' at the command line to run it. If you want to put it in a file, then you need to copy/paste it to a file, and save the file with a .lsp extension, and then load the file. If the file is in the search path, then you can just type '(load "filename.lsp")' if it's not then you need to type in the whole path.

    Hope the helps.

    Well, that did the trick...couldn't remember if I could c/p code directly to the command line or not. However, I did open Notepad, c/p code into it. Save the file as par.lsp (okay, first I had to go to a dos command and rename it from par.lsp.txt to par.lsp). I moved the file to where the dwg is located and did the load thing.

    Oh well, if I can't load it from lsp, I'll c/p.

    Thanks for your help!!!!!!!!!!!!!!!!!!!!!

  10. #10
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Need a script to (xx)

    Another things you could do is make the lisp file you did, then in acad type 'appload'. Then in the bottom right, the Startup Suite, you can add your file there so it will load with every drawings.

    You're welcome. Glad you got it to work.

Page 1 of 2 12 LastLast

Similar Threads

  1. Script Help
    By geoffrey.m.reynolds in forum AutoCAD Customization
    Replies: 6
    Last Post: 2012-03-20, 10:24 AM
  2. Script
    By robert.josi in forum AutoCAD LT - General
    Replies: 3
    Last Post: 2009-08-07, 07:35 PM
  3. Looking for a script
    By jsteinhauer in forum Revit Architecture - General
    Replies: 0
    Last Post: 2009-04-22, 07:41 PM
  4. script help
    By mark.momper in forum AutoLISP
    Replies: 9
    Last Post: 2008-02-22, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •