+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Senior Member ILoveMadoka's Avatar
    Using
    AutoCAD 2012
    Join Date
    Oct 2008
    Posts
    213

    Unhappy Add Prefix/Suffix to Multiple Dimensions?

    Registered forum members do not see this ad.

    I've looked around and have found Suffix/Prefix routines for Text, Mtext and Attributes. I thought it would be easy to modify one of those to work with dimensions but easier said than done. I cannot figure it out.
    I was hoping one of these two routines would be easy to rework to work with dimensions.

    For this first one, I thought adding DIMENSION to the associative list would work but my understanding is limited evidently...

    My desire is to add a prefix/suffix to multiple dimensions.

    As far as dimensions are concerned does
    Code:
    (0 . "DIMENSION")
    cover them all?

    Code:
    (defun c:ftxt(/ cMod cStr tSet)
      (vl-load-com)
      (initget 1 "Prefix Suffix")
      (setq cMod(getkword "\nAdd [Prefix/Suffix]: "))
      (if(and
           (setq cStr(getstring T "\nSpecify string: "))
           (setq tSet(ssget '((0 . "TEXT,MTEXT")))) ;Adding DIMENSION didn't work for me
           ); and
        (foreach tx(mapcar 'vlax-ename->vla-object
                     (vl-remove-if 'listp
                       (mapcar 'cadr(ssnamex tSet))))
          (if(= "Prefix" cMod)
        (vla-put-TextString tx
          (strcat cStr(vla-get-TextString Tx)))
            (vla-put-TextString tx
          (strcat(vla-get-TextString Tx)cStr))
        ); end if
          ); end foreach
        ); end if
      (princ)
      ); end of c:ftxt
    The other routine I thought would be easy was this one...

    Code:
    (defun c:test ( / as el en i ss str typ )
    
      (initget "Prefix Suffix")
      (setq typ (cond ((getkword "\nAdd Prefix or Suffix? [Prefix/Suffix] <Prefix>: ")) ("Prefix")))
      (setq str (getstring t (strcat typ " to Add: ")))
    
      (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
          (repeat (setq i (sslength ss))
              (setq en (ssname ss (setq i (1- i))))
              (while (eq "ATTRIB" (cdr (assoc 0 (setq el (entget (setq en (entnext en)))))))
                  (setq as (cdr (assoc 1 el)))
                  (if (eq "Prefix" typ)
                      (if (not (wcmatch as (strcat str "*")))
                          (entmod (subst (cons 1 (strcat str as)) (assoc 1 el) el))
                      )
                      (if (not (wcmatch as (strcat "*" str)))
                          (entmod (subst (cons 1 (strcat as str)) (assoc 1 el) el))
                      )
                  )
              )
          )
      )
      (princ)
    )

    Help please!!

    Big thanks to the original code writers!

  2. #2
    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,816

    Default

    How about using a Prefix/Suffix in the Dimension Style? Much easier to globally change than using a Text Override.
    Lee Mac Programming

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

    Just another Swamper

  3. #3
    Senior Member ILoveMadoka's Avatar
    Using
    AutoCAD 2012
    Join Date
    Oct 2008
    Posts
    213

    Default

    What I very often encounter is the need to add a "2X," "3X," or "10X," before dimensions.
    When it's just one here and there, I manually type it in.
    I'm working on a drawing at the moment that has 40 or more that need various prefixes like that added.
    A majority of drawings are laid out like this using this type of designator...

    If it's too much of a hassle, I can keep doing what I've been doing.
    Manual works every time.. I get paid either way.

    I was hoping it would be an easy fix (just beyond my novice ability..)

  4. #4
    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,816

    Default

    A quick modification of my code that you posted:

    Code:
    (defun c:test ( / typ str ss i en ds )
    
      (initget "Prefix Suffix")
      (setq typ (cond ((getkword "\nAdd Prefix or Suffix? [Prefix/Suffix] <Prefix>: ")) ("Prefix")))
      (setq str (getstring t (strcat "\n" typ " to Add: ")))
    
      (if (setq ss (ssget '((0 . "*DIMENSION"))))
          (repeat (setq i (sslength ss))
              (setq en (entget (ssname ss (setq i (1- i))))
                    ds (cdr (assoc 1 en))
              )
              (if (eq "Prefix" typ)
                  (if (not (wcmatch ds (strcat str "*")))
                      (entmod (subst (cons 1 (strcat str ds)) (assoc 1 en) en))
                  )
                  (if (not (wcmatch ds (strcat "*" str)))
                      (entmod (subst (cons 1 (strcat ds str)) (assoc 1 en) en))
                  )
              )
          )
      )
      (princ)
    )
    Lee Mac Programming

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

    Just another Swamper

  5. #5
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,666

    Default

    You don't need lisp for that, just the properties palette (Ctrl+1):
    1. Select the dimensions which would have the same prefix/suffix.
    2. Press Ctrl+1 to open the properties pallette
    3. Type into the Text override field (bottom of the Text group): Prefix<>Suffix
    The <> means the value of the dimension.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  6. #6
    Senior Member ILoveMadoka's Avatar
    Using
    AutoCAD 2012
    Join Date
    Oct 2008
    Posts
    213

    Default

    Lee...

    Won't I need
    Code:
     (assoc 42 en)
    in there somewhere?

    !DS is returning an empty string...

    I defer to the expert but don't you need the original dimension or am I totally confused??
    I am trying to understand....

    What it is doing is replacing the dimension with the text (suffix) that I enter...

  7. #7
    Senior Member ILoveMadoka's Avatar
    Using
    AutoCAD 2012
    Join Date
    Oct 2008
    Posts
    213

    Default

    Quote Originally Posted by irneb View Post
    You don't need lisp for that, just the properties palette (Ctrl+1):

    1. Select the dimensions which would have the same prefix/suffix.
    2. Press Ctrl+1 to open the properties pallette
    3. Type into the Text override field (bottom of the Text group): Prefix<>Suffix

    The <> means the value of the dimension.

    I understand completely...
    Do that 30-40-50 times per drawing and you will understand my point of view...

  8. #8
    Senior Member ILoveMadoka's Avatar
    Using
    AutoCAD 2012
    Join Date
    Oct 2008
    Posts
    213

    Default

    I'm really close with this:

    Code:
    (defun c:DP ( / typ str ss i en ds )
    
      (initget "Prefix Suffix")
      (setq typ (cond ((getkword "\nAdd Prefix or Suffix? [Prefix/Suffix] <Prefix>: ")) ("Prefix")))
      (setq str (getstring t (strcat "\n" typ " to Add: ")))
    
      (if (setq ss (ssget '((0 . "*DIMENSION"))))
          (repeat (setq i (sslength ss))
              (setq en (entget (ssname ss (setq i (1- i))))
                    ds (rtos (cdr (assoc 42 en)))                
              )
              (if (eq "Prefix" typ)
                  (if (not (wcmatch ds (strcat str "*")))
                      (entmod (subst (cons 1 (strcat str ds)) (assoc 42 en) en))
                  )
                  (if (not (wcmatch ds (strcat "*" str)))
                      (entmod (subst (cons 1 (strcat ds str)) (assoc 42 en) en))
                  )
              )
          )
      )
      (princ)
    )
    I have some more questions but it will have to wait until tomorrow...

    Here is one..

    I can enter "9x" but I can't enter 9X, (9X comma space)
    Last edited by ILoveMadoka; 16th Aug 2011 at 08:28 pm. Reason: edit

  9. #9
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,666

    Default

    So you mean there's 30-40-50 different prefixes you want to apply? Are you sure? Sounds a bit worrying to me! You know that you can select 30-40-50-1000000000..... dimensions at once and apply the change in one instruction?

    Sorry, I just can't understand this. If I had to code something where I'd have various prefixes to apply to various dimensions I'd not have the code ask me each time what that prefix was. I'd rather have different codes placing different prefixes onto the selected dimensions. Perhaps something like this?
    Code:
    (defun AffixDim (en prefix suffix / )
      (entmod (list (cons -1 en) (cons 1 (strcat prefix "<>" suffix))))
    )
    
    (defun SelectDimsAndAffix (prefix suffix / ss n)
      (if (setq ss (ssget '((0 . "*DIMENSION"))))
        (progn
          (setq n (sslength ss))
          (while (>= (setq n (1- n)) 0)
            (AffixDim (ssname ss n) prefix suffix)
          )
        )
      )
    )
    
    (defun c:PrefixDim-2X (/) (SelectDimsAndAffix "2X" "") (princ))
    (defun c:PrefixDim-9X (/) (SelectDimsAndAffix "9X" "") (princ))
    
    (defun c:AffixDim (/ prefix suffix)
      (or *AffixDim-Prefix* (setq *AffixDim-Prefix* ""))
      (or *AffixDim-Suffix* (setq *AffixDim-Suffix* ""))
      (if (and (setq prefix (getstring t (strcat "Prefix (. for None) <" *AffixDim-Prefix* ">: ")))
               (not (eq prefix ""))
          )
        (progn
          (if (eq prefix ".")
            (setq prefix "")
          )
          (setq *AffixDim-Prefix* prefix)
        )
        (setq prefix *AffixDim-Prefix*)
      )
      (if (and (setq suffix (getstring t (strcat "Suffix (. for None) <" *AffixDim-Suffix* ">: ")))
               (not (eq prefix ""))
          )
        (progn
          (if (eq suffix ".")
            (setq suffix "")
          )
          (setq *AffixDim-Suffix* suffix)
        )
        (setq suffix *AffixDim-Suffix*)
      )
      (SelectDimsAndAffix prefix suffix)
      (princ)
    )
    That way I can have a command for each of the most usual prefixes/suffixes - which I can place on a toolbar or so for quick selection. The last one is a general purpose one which remembers the previous prefix/suffix.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  10. #10
    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,816

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by ILoveMadoka View Post
    Lee...

    Won't I need
    Code:
     (assoc 42 en)
    in there somewhere?
    No, use "<>" to represent the dimension string otherwise your dimensions won't update and you'll screw up your drawings.

    I reference the existing text override so that it is not overwritten.

    When it prompts for a Prefix/Suffix, type "Prefix<>" or "<>Suffix" or, if you already have the dimension and prefix and want to add a suffix, just type "Suffix".

    EDIT: Added GIF to demonstrate...

    PrefSuffDim.gif
    Last edited by Lee Mac; 17th Aug 2011 at 11:17 am.
    Lee Mac Programming

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

    Just another Swamper

Similar Threads

  1. Add Prefix or suffix to all layers in a drawing
    By gman in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 10th Oct 2011, 12:26 pm
  2. Adding Prefix or Suffix to block attribute
    By harilalmn in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 28th Jul 2011, 02:20 pm
  3. Prefix for the dimensions-- dimlinear
    By raj in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 6th May 2011, 07:45 pm
  4. Lisp to add a prefix or suffix to selected text
    By JB_In_FLA in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 6th Jan 2011, 04:57 pm
  5. Removing the R prefix from radius dimensions
    By everglade in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 2nd Aug 2005, 11:24 am

Tags for this Thread

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