Jump to content

Add Prefix/Suffix to Multiple Dimensions?


ILoveMadoka

Recommended Posts

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...:cry:

 

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

 

As far as dimensions are concerned does

(0 . "DIMENSION")

cover them all?

 

(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...

 

(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!

Link to comment
Share on other sites

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.:D

 

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

Link to comment
Share on other sites

A quick modification of my code that you posted:

 

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

Link to comment
Share on other sites

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

The means the value of the dimension.

Link to comment
Share on other sites

Lee...

 

Won't I need

 (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...

Link to comment
Share on other sites

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

 

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

Link to comment
Share on other sites

I'm really close with this:

 

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

Edited by ILoveMadoka
edit
Link to comment
Share on other sites

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?

(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.

  • Thanks 1
Link to comment
Share on other sites

Lee...

 

Won't I need

 (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

Edited by Lee Mac
Link to comment
Share on other sites

Why not use 'dimedit'?

 

(defun c:wr (/ a b)
 (if c1
   ()
   (setq c1 "%%c<>\"\\P(Typ.)")
 )
 (princ "\n Overwrite with:  ")
 (princ c1)
 (princ " ? ")
 (setq b (getstring t))
 (if (= b "")
   (setq b c1)
 )
 (setq c1 b)
 (princ "\nSelect Dimensions to overwrite ")
 (setq a (ssget '((0 . "DIMENSION"))))
 (if (not (eq a nil))
   (command "._DimEdit" "_N" b a "")
 )
 (princ)
)

Link to comment
Share on other sites

irneb>

 

Now THAT is awesome! :D

Presets are definitely the way to go.

 

Thanks so very much!!

 

 

(I misunderstood your original post...):oops:

I thought you were showing me how to do an override...

  • Like 1
Link to comment
Share on other sites

Lee and everyone...

 

Thanks so much for the instruction and the different takes on how to do something!!

 

You guys are all very appreciated!

 

Thank you!

  • Like 1
Link to comment
Share on other sites

irneb>

 

Now THAT is awesome! :D

Presets are definitely the way to go.

 

Thanks so very much!!

 

 

(I misunderstood your original post...):oops:

I thought you were showing me how to do an override...

You're welcome! Glad we finally got to the same wave-length :thumbsup:

 

IMO the Properties Palette is still one of the most powerful things ADesk has ever made for ACad. If not the most powerful. That's not to say you can't get something which is even more efficient for your specific scenario (like these preset commands).

  • Like 1
Link to comment
Share on other sites

  • 12 years later...
On 8/16/2011 at 9:59 PM, irneb said:

Vous voulez dire qu’il y a 30-40-50 préfixes différents que vous voulez appliquer ? Es-tu sûr? Cela me semble un peu inquiétant ! Vous savez que vous pouvez sélectionner 30-40-50-10000000000..... dimensions à la fois et appliquer le changement dans une instruction ?

 

Désolé, je n’arrive pas à comprendre. Si je devais coder quelque chose où j’aurais plusieurs préfixes à appliquer à différentes dimensions, je n’aurais pas le code qui me demanderait à chaque fois quel était ce préfixe. Je préférerais avoir des codes différents plaçant différents préfixes sur les dimensions sélectionnées. Peut-être quelque chose comme ça ?

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

De cette façon, je peux avoir une commande pour chacun des préfixes/suffixes les plus courants - que je peux placer sur une barre d’outils ou plus pour une sélection rapide. Le dernier est un usage général qui se souvient du préfixe/suffixe précédent.

HELLO 

DON'T WORK WITH ME 

BRICSCAD 2024 FRENCH 

error : no function definition <AFFIXDIM> ; expected FUNCTION at [eval]

Edited by DELLA MAGGIORA YANN
Link to comment
Share on other sites

Just now, DELLA MAGGIORA YANN said:

HELLO 

DON'T WORK WITH ME 

BRICSCAD 2024 FRENCH 

error : no function definition <AFFIXDIM> ; expected FUNCTION at [eval]

 

Link to comment
Share on other sites

2 hours ago, DELLA MAGGIORA YANN said:

 

 

@DELLA MAGGIORA YANN Looks like you didn't copy the complete code. It is missing the "AffixDim" function, which is in the post above.

(defun AffixDim (en prefix suffix / )
 (entmod (list (cons -1 en) (cons 1 (strcat prefix "<>" suffix))))
)

 

Edited by pkenewell
Link to comment
Share on other sites

On 3/25/2024 at 2:30 PM, pkenewell said:

 

@DELLA MAGGIORA YANN Il semble que vous n’ayez pas copié le code complet. Il manque la fonction « AffixDim », qui se trouve dans le post ci-dessus.

(defun AffixDim (en prefix suffix / )
 (entmod (list (cons -1 en) (cons 1 (strcat prefix "<>" suffix))))
)

 

Good morning,
it seems that it still doesn't work,
Ares the selection of dimensions I validate with "Enter" and it asks me to select more entities.
no prefix or suffix

Link to comment
Share on other sites

19 hours ago, DELLA MAGGIORA YANN said:

Good morning,
it seems that it still doesn't work,
Ares the selection of dimensions I validate with "Enter" and it asks me to select more entities.
no prefix or suffix

I just tested the code and it works fine for me without any alterations. If you've changed it in any way, post the full code you're using, along with a sample drawing where it doesn't work, pointing to a dimension you're trying to change.

 

Je viens de tester le code et il fonctionne correctement pour moi sans aucune altération. Si vous l'avez modifié de quelque manière que ce soit, publiez le code complet que vous utilisez, ainsi qu'un exemple de dessin dans lequel il ne fonctionne pas, en pointant vers une dimension que vous essayez de modifier.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...