+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    May 2009
    Posts
    9

    Default Adding number to a text string

    Registered forum members do not see this ad.

    I would like to create a routine to add the current dimscale variable to the end of text string.

    Thanks
    Derek

  2. #2
    Super Member
    Computer Details
    wannabe's Computer Details
    Operating System:
    XP
    Using
    AutoCAD 2007
    Join Date
    Oct 2008
    Location
    Birmingham, UK
    Posts
    772

    Default

    Would the dimscale need to be concurrent with the live dimscale? i.e will you need the text string to be updated to reflect changes to the dimscale value, automatically?

    If you don't need it to be automatically updated you could just add a field that is assigned the value of the dimscale system variable.

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Quick fix:

    Code:
    (defun c:AddDim  (/ ss)
      (vl-load-com)
      (if (setq ss (ssget (list (cons 0 "*TEXT")
                                (if (getvar "CTAB")
                                  (cons 410 (getvar "CTAB"))
                                  (cons 67 (- 1 (getvar "TILEMODE")))))))
        (progn
          (foreach x  (mapcar 'entget
                        (vl-remove-if 'listp
                          (mapcar 'cadr (ssnamex ss))))
            (entmod (subst (cons 1 (strcat (cdr (assoc 1 x)) (chr 32)
                                           (rtos (getvar "DIMSCALE"))))
                           (assoc 1 x) x))))
        (princ "\<!> No Text Selected <!>"))
      (princ))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  4. #4
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    May 2009
    Posts
    9

    Default

    I will better describe my intent:

    I am trying to automate the process of inserting a block and have it inserted on the correct layer, grab the correct scale factor (based on the current dimscale). Our layers are standard with a suffix for a particular scale.

    The layer the block is inserted on is static, except for the scale suffix, (i.e. Layer-25, Layer-50) from drawing to drawing.

    Ideally, if the layer does not exist I would like it to be created. Most likely the layer will exist in the drawing the block is being inserted into.

    I was thinking that I could read the current dimscale and place it at the end of the layer name and make that layer current prior to inserting the block.

    Thanks
    Derek

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Ok, I think I understand your intents, will see what I can do
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Perhaps:

    Code:
    (defun c:Blklay (/ lDim)
      (vl-load-com)
      (setq lDim (strcat "Layer-" (rtos (getvar "DIMSCALE"))))
      (or (tblsearch "LAYER" lDim)
          (vla-add (vla-get-Layers
                     (vla-get-ActiveDocument
                       (vlax-get-acad-object))) lDim))
      (setvar "CLAYER" lDim)
      (princ))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    This assumes that your DIMSCALE is a whole number
    Code:
    (defun SetLayer (name / ldef flag)
      (cond ((or (not name)
                 (not (snvalid name)))
             (princ "\nBad Aurgment Passed To SetLayer - ")
             (prin1 name)
             (exit)))
      (command "_.LAYER")
      (if (not (tblsearch "LAYER" name))
          (command "_Make" name)
          (progn
            (setq ldef (tblsearch "LAYER" name)
                  flag (cdr (assoc 70 ldef)))
            (and (= (logand flag  1)  1)
                 (command "_Thaw" name))
            (and (minusp (cdr (assoc 62 ldef)))
                 (command "_On" name))
            (and (= (logand flag  4)  4)
                 (command "_Unlock" name))
            (and (= (logand flag 16) 16)
                 (princ "\nCannot Set To XRef Dependent Layer")
                 (quit))
            (command "_Set" name)))
      (command "")
      name)
    Code:
    (SetLayer (strcat "LAYER-" (rtos (getvar "DIMSCALE") 2 0)))
    -David
    R12 (Dos) - A2K

  8. #8
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    May 2009
    Posts
    9

    Default

    That was perfect...thanks a whole bunch!!!!

    Derek

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    I suppose a reactor could be used also - hasn't got the error trapping standard of Davids though

    Code:
    (defun c:Ron  ()
      (vl-load-com)
      (if (not blk:react)
        (setq blk:react
               (vlr-command-reactor nil
                 '((:vlr-commandWillStart . Blklay)
                   (:vlr-commandEnded . Blkend)
                   (:vlr-commandCancelled . Blkcan)))))
      (princ "\n<<--  Block Reactor ON  -->>")
      (princ))
    
    (defun c:Roff  ()
      (if blk:react
        (progn
          (vlr-remove blk:react)
          (setq blk:react nil)
          (princ "\n<<--  Block Reactor OFF  -->>")))
      (princ))
    
    (defun Blklay  (Reac Args / lDim)
      (vl-load-com)
      (and (eq "INSERT" (car Args))
           (setq oLay (getvar "CLAYER")
                 lDim (strcat "Layer-" (rtos (getvar "DIMSCALE"))))
           (or (tblsearch "LAYER" lDim)
               (vla-add (vla-get-Layers
                          (vla-get-ActiveDocument
                            (vlax-get-acad-object))) lDim))
           (setvar "CLAYER" lDim))
      (princ))
    
    (defun Blkend  (Reac Args)
      (if oLay
        (setvar "CLAYER" oLay))
      (princ))
    
    (defun Blkcan  (Reac Args)
      (if oLay
        (setvar "CLAYER" oLay))
      (princ))
    Type "Ron" to turn on and "Roff" to turn off
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  10. #10
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    May 2009
    Posts
    9

    Default

    Registered forum members do not see this ad.

    Is there an advantage of error trapping?

Similar Threads

  1. Cannot Find Resource String Number 4384
    By awill81 in forum AutoCAD Bugs, Error Messages & Quirks
    Replies: 0
    Last Post: 9th Apr 2009, 08:13 pm
  2. Divided a text number for a text number
    By HelloWorld in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 17th Apr 2008, 02:48 am
  3. adding text string to multiple lines at once?
    By Lucid in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 18th Oct 2007, 07:31 pm
  4. Adding a String to the Text Command
    By muppetfan88 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 29th Apr 2006, 03:49 am
  5. (code) extract number from string
    By Mark Thomas in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 18th Jan 2005, 02:01 pm

Bookmarks

Posting Permissions

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