PDA

View Full Version : Add Prefix/Suffix to Multiple Dimensions?



ILoveMadoka
16th Aug 2011, 06:39 pm
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!

Lee Mac
16th Aug 2011, 06:41 pm
How about using a Prefix/Suffix in the Dimension Style? Much easier to globally change than using a Text Override.

ILoveMadoka
16th Aug 2011, 06:48 pm
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..)

Lee Mac
16th Aug 2011, 07:15 pm
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)
)

irneb
16th Aug 2011, 07:19 pm
You don't need lisp for that, just the properties palette (Ctrl+1):


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

The <> means the value of the dimension.

ILoveMadoka
16th Aug 2011, 08:11 pm
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...

ILoveMadoka
16th Aug 2011, 08:12 pm
You don't need lisp for that, just the properties palette (Ctrl+1):



Select the dimensions which would have the same prefix/suffix.
Press Ctrl+1 to open the properties pallette
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...

ILoveMadoka
16th Aug 2011, 08:23 pm
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)

irneb
16th Aug 2011, 08:59 pm
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.

Lee Mac
17th Aug 2011, 10:43 am
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...

29429

paulmcz
17th Aug 2011, 12:40 pm
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)
)

ILoveMadoka
17th Aug 2011, 01:25 pm
<irneb> (http://www.cadtutor.net/forum/member.php?59919-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...

ILoveMadoka
17th Aug 2011, 01:33 pm
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!

irneb
17th Aug 2011, 01:41 pm
<irneb> (http://www.cadtutor.net/forum/member.php?59919-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).