Pre-selected dimension text insert/replace

Pre-selected dimension text insert/replace

Anonymous
Not applicable
2,489 Views
12 Replies
Message 1 of 13

Pre-selected dimension text insert/replace

Anonymous
Not applicable

Hello everyone,

 

In my day to day work, I am constantly drawing aligned dimensions across a slab (or any shape) and then replacing the dimension number with multiline text.  There are basically 4-5 types of slab we use and each has its own specs.  An example of this would be:

 

120 RC SLAB
SL82 CENTRAL MESH
F'c=32 MPa

 

So the above would be centered mline text.  I keep these little notes in each drawing, so after I draw the aligned dimension, click into the required note, highlight all, copy, return to dimension and paste the text over the number.  Thought ther must be a better way and so after much googling I found:

https://www.cadtutor.net/forum/topic/23429-autotext-edit-for-dimension-text/

Theres a routine there written by Lee Mac that does the exact thing I want except it can only handle single line text.  I guess you'll have to be a member to see the code and I wasn't sure on the rules about copying and pasting from another site/forum.  Please let me know if it is okay to do this and I'll add it.  Have attached his Lisp file here.

I also found:

http://www.theswamp.org/index.php?topic=1392.0

Here there was a lisp routine called "TextInsert" and came with accompanying .dcl files that could be edited to hold the text a user wanted to deploy.  Have included these in the attachments

This lisp allows you to click anywhere and insert a predetermined block of text.  This one can do mline but it doesn't replace the dimension text; simply places the selected block of text over it.

Also downloaded "DimNotes" from JTB World.  Again, close but no cigar - single line text only.

I feel like between the three sources I've mentioned it may not be too hard for someone to cobble together a tool that could replace the default dimension measurement number with a selected block of mline text..?  Perhaps like the others mentioned above, the text could be stored and edited in a seperate data/text file..?

 

Please let me know if any of you require me to copy and paste the code from the other sites to help you and if that is allowed here.

 

Thanks for reading guys.

0 Likes
Accepted solutions (1)
2,490 Views
12 Replies
Replies (12)
Message 2 of 13

devitg
Advisor
Advisor

Please upload your sample.dwg 

0 Likes
Message 3 of 13

Anonymous
Not applicable

Here is a heavily stripped down version of my drawing template.  Just shows you the text I use and how its placed etc.

0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant

Simple as this one? 1st/re-load by pre-selection.

1st you need to hit RT/space to repeat.

2nd... autorepeat until <done>

 

(defun c:DimSlab nil
  
  (if (setq *ds-text* (cond ((setq s (ssget "_I" '((0 . "MTEXT"))))
			     (getpropertyvalue (ssname s 0) "Text"))
			    (*ds-text*)
			    ((setq s (ssget  ":S:E" '((0 . "MTEXT"))))
			     (getpropertyvalue (ssname s 0) "Text"))))
    (progn
      (command "_.dimaligned" pause pause "_non" "@")
      (setpropertyvalue (entlast) "DimensionText" *ds-text*)))
  (princ)
  )


(defun c:DimSlab2 (/ pnt)
  
  (if (setq *ds-text* (cond ((setq s (ssget "_I" '((0 . "MTEXT"))))
			     (getpropertyvalue (ssname s 0) "Text"))
			    (*ds-text*)
			    ((setq s (ssget  ":S:E" '((0 . "MTEXT"))))
			     (getpropertyvalue (ssname s 0) "Text"))))
    (while (setq pnt (getpoint "\nSpecify first point <done>: "))
      (command "_.dimaligned" "_non" pnt pause "_non" "@")
      (setpropertyvalue (entlast) "DimensionText" *ds-text*)))
  (princ)
  )

 

 

Message 5 of 13

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous ,

 

Here's my approach. It allows you to pre-program the values, and easily select them in the command by entering a number. That way you don't need to bounce back and forth between selecting text / selecting dims.

(defun c:TEST ( / dyn cnt strList iStr gStr e ans)
  (defun *error* (msg)
    (if dyn (setvar 'DYNMODE dyn))
    (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  );error defun
;defaults
(setq cnt 0 dyn (getvar 'DYNMODE))
(setq strList
  (list
    ;add strings like this '(cons "Quick_identifying_text" "Full_String_of_Text_to_Use")
    ; Do NOT include a forwardslash character / or backslash character \ (unless escaping)
    (cons "STANDARD HOUSE" "100 RAFT SLAB\nSL82 MESH TOP\n25 COVER")
    (cons "STANDARD GARAGE" "100 RAFT SLAB\nSL82 MESH TOP\n30 COVER")
    (cons "SUSPEND HOUSE" "120 RC SLAB\nSL82 CENTRAL MESH\nF'c=32 MPa")
    (cons "SUSPEND GARAGE" "125 RC SLAB\nSL82 TOP & BOTTOM\n30 COVER\nF'c=32 MPa")
    (cons "RIGID SLAB-FILL-SOFT SPOT" "100 RAFT SLAB\nSL82 CENTRAL\nMESH")
  );list
);setq
;prep prompts for user in 'while' loop
(setq iStr "" gStr "")
;(setvar 'DYNMODE 3)
(while (<= (setq cnt (1+ cnt)) (length strList))
  (setq iStr (strcat iStr (itoa cnt) " "))
  (setq gStr (strcat gStr (itoa cnt) " ... " (car (nth (1- cnt) strList)) "/"))
);while
(setq iStr (substr iStr 1 (1- (strlen iStr)))
      gStr (substr gStr 1 (1- (strlen gStr))))
;get dimensions
(while (progn (prompt "\nSelect Dimension (Enter to exit): ") (setq e (ssget "_+.:E:S" '((0 . "DIMENSION")))))
  ;ask which string to use
  (initget 1 iStr) (setq ans (getkword (strcat "\nSelect text: [" gStr "]")))
  (setpropertyvalue (ssname e 0) "DimensionText" (cdr (nth (1- (atoi ans)) strList)))
);while
;(setvar 'DYNMODE dyn)
(prompt "\nTEST Complete.")
(princ)
);defun

 

NOTE: I feel this type of routine works best when DYNMODE is set to 3. That can be implemented into the routine, but was commented out. To include it, just remove the semicolons before the (setvar ...at the 2 lines they were commented out.

 

Best,

~DD

Message 6 of 13

devitg
Advisor
Advisor

My humble approach

 

(DEFUN CHANGE-DIM-TEXT  ()
  (VL-LOAD-COM)
  (PRINC "\n Select dim :")
  (SETQ DIM-SS (SSGET "_:S+." '((0 . "*DIMENSION"))))
  (SETQ DIM (SSNAME DIM-SS 0))
  (SETQ DIM-OBJ (VLAX-ENAME->VLA-OBJECT DIM))
  (PRINC "\nSelect text to override")
  (SETQ TEXT-SS (SSGET "_:S+." '((0 . "mtext"))))
  (SETQ TEXT-OBJ (VLAX-ENAME->VLA-OBJECT (SSNAME TEXT-SS 0)))
  (SETQ TEXT-$ (VLA-GET-TEXTSTRING TEXT-OBJ))
  (VLA-PUT-TEXTOVERRIDE DIM-OBJ TEXT-$)
  (VLA-UPDATE DIM-OBJ)
  )
;end change-dim-text



(defun c:c-d-t ()
  (change-dim-text)
  )
; end  c:ch-dim-text 
Message 7 of 13

CodeDing
Advisor
Advisor

@Anonymous ,

 

Likewise, this version will create the dimension first (as @ВeekeeCZ has incorporated).

(defun c:TEST ( / dyn lyr cnt strList tmp iStr gStr e ans)
  (defun *error* (msg)
    (if dyn (setvar 'DYNMODE dyn))
    (if lyr (setvar 'CLAYER lyr))
    (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  );error defun
;defaults
(setq cnt 0 dyn (getvar 'DYNMODE) lyr (getvar 'CLAYER))
(setq strList
  (list
    ;add strings like this (cons "Quick_identifying_text" "Full_String_of_Text_to_Use")
    ; Do NOT include a forwardslash character / or backslash character \ (unless escaping)
    (cons "STANDARD HOUSE" "100 RAFT SLAB\nSL82 MESH TOP\n25 COVER")
    (cons "STANDARD GARAGE" "100 RAFT SLAB\nSL82 MESH TOP\n30 COVER")
    (cons "SUSPEND HOUSE" "120 RC SLAB\nSL82 CENTRAL MESH\nF'c=32 MPa")
    (cons "SUSPEND GARAGE" "125 RC SLAB\nSL82 TOP & BOTTOM\n30 COVER\nF'c=32 MPa")
    (cons "RIGID SLAB-FILL-SOFT SPOT" "100 RAFT SLAB\nSL82 CENTRAL\nMESH")
  );list
);setq
;prep prompts for user
(setq iStr "" gStr "")
;(setvar 'DYNMODE 3)
(if (setq tmp (tblsearch "LAYER" "03timber_wall")) (setvar 'CLAYER (cdr (assoc 2 tmp))))
(while (<= (setq cnt (1+ cnt)) (length strList))
  (setq iStr (strcat iStr (itoa cnt) " "))
  (setq gStr (strcat gStr (itoa cnt) " ... " (car (nth (1- cnt) strList)) "/"))
);while
(setq iStr (substr iStr 1 (1- (strlen iStr)))
      gStr (substr gStr 1 (1- (strlen gStr))))
;create dimension
(command "_.DIMALIGNED" pause pause "_non" "@")
(setq e (entlast))
;ask which string to use
(initget 1 iStr) (setq ans (getkword (strcat "\nSelect text: [" gStr "]")))
(setpropertyvalue e "DimensionText" (cdr (nth (1- (atoi ans)) strList)))
;(setvar 'DYNMODE dyn)
(setvar 'CLAYER lyr)
(prompt "\nTEST Complete.")
(princ)
);defun

PLEASE NOTE: Again, DYNMODE is commented out, but I highly recommend incorporating it.

 

Best,

~DD

Message 8 of 13

ВeekeeCZ
Consultant
Consultant

@CodeDing wrote:

@Anonymous ,

 

Here's my approach. It allows you to pre-program the values, and easily select them in the command by entering a number....

NOTE: I feel this type of routine works best when DYNMODE is set to 3...

 

Best,

~DD


 

 

Agree. But feel like something small is still missing... SEE 😉

 

    (cons "standard house" "100 RAFT SLAB\nSL82 MESH TOP\n25 COVER")
    (cons "standard garage" "100 RAFT SLAB\nSL82 MESH TOP\n30 COVER")
    (cons "suspend house" "120 RC SLAB\nSL82 CENTRAL MESH\nF'c=32 MPa")
    (cons "suspend garage" "125 RC SLAB\nSL82 TOP & BOTTOM\n30 COVER\nF'c=32 MPa")
    (cons "rigid slab-fill-soft spot" "100 RAFT SLAB\nSL82 CENTRAL\nMESH")
  );list
...
(while (<= (setq cnt (1+ cnt)) (length strList))
  (setq iStr (strcat iStr (itoa cnt) " "))
  (setq gStr (strcat gStr (itoa cnt) " " (car (nth (1- cnt) strList)) "/"))
);while
 
Message 9 of 13

CodeDing
Advisor
Advisor

@ВeekeeCZ ,

 

Agreed. I updated to reflect the space so users can select the option with their mouse.

Message 10 of 13

CodeDing
Advisor
Advisor

FIX: My last routine should incorporate the error handling item in the local variables list:

(defun c:TEST ( / *error* dyn lyr cnt strList tmp iStr gStr e ans)
0 Likes
Message 11 of 13

Anonymous
Not applicable

I'm sorry I don't know how to directly reply/quote someone (have their username show up as a blue hyperlink) but ALL of you guys are unbelievable!  I posted this request late last night (AUS time) and my phone did not stop dinging all night as people replied straight away.   I  apologise for the delayed response but I had to wait until I went to work today and could test what you guys had given me.  No surprises here - worked beautifully and was exactly what I wanted.  Actually ended up using almost everyones contributions... for one task or another in my workflow.  The old dinosaurs in my drafting office (still using AutoCad 2000) know only of a "lisp" if it refers to a speech impediment so when I show them the tools/results people have made for me here, they're beyond astounded.  Its great!

The level of knowledge and generosity here just blows my mind.  Thank you to EVERYONE who chimed in.

Message 12 of 13

Sea-Haven
Mentor
Mentor

Codeding really like the initget screen choice I wrote a library dcl to do the same, as many as needed, but like the idea.

 

Using Autocad for years ver 1.4 learn something new all the time.

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

I am in AUS as well near Newcastle, happy to provide help or commercial arrangement lots of structural knowledge.

0 Likes