Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Overriding a dimension value through AutoLISP

21 REPLIES 21
Reply
Message 1 of 22
Iz
3952 Views, 21 Replies

Overriding a dimension value through AutoLISP

Hi,

I am wondering how I can override a dimension value through AutoLISP. Is there a command line that I can use so that the pop up window won't show up? Thanks.

Iz
21 REPLIES 21
Message 2 of 22
Anonymous
in reply to: Iz

This adds " TYP" as an override to dims you pick. Is it what you were
looking for?

(defun c:ADDTYP ( / DIMSS DTX)
(setvar "cmdecho" 0)
(setq DIMSS (SSGET '((0 . "DIMENSION"))))
(setq c -1)
(repeat (sslength DIMSS)
(setq DTX (ENTGET (SSNAME DIMSS (setq c (1+ c)))))
(setq DTX (SUBST (CONS 1 "<> TYP") (ASSOC 1 DTX) DTX)
)
(ENTMOD DTX)
)
(PRINC)
)


"Iz" wrote in message
news:f0e8d3f.-1@WebX.maYIadrTaRb...
Hi,
I am wondering how I can override a dimension value through AutoLISP. Is
there a command line that I can use so that the pop up window won't show up?
Thanks.
Iz
Message 3 of 22
Iz
in reply to: Iz

I'm writing a code to dimension some drawings with break lines in them;therefore, the dimensions shown is actaully shorter than they're suppose to be. I'd like to be able to change the values through AutoLISP, but am not sure how. I'm still new at this so I'm not sure if the code you posted does what I'd like it to do, but I'll try to figure it out and give it a shot if it's what I want. Thank you very much for your help.
Message 4 of 22
petervose
in reply to: Iz

Jun - Try this
(defun c:ch_dimval ( / seldim cobj ns)
(vl-load-com)
(setq seldim (car (entsel "\nPick Dimension ")))
(setq cobj (vlax-ename->vla-object seldim))
(setq ns (getstring "\nNew Dimension ? : "))
(vlax-put-property cobj 'TextOverride ns)
(princ)
)

Peter
Message 5 of 22
ramesh.axis
in reply to: Anonymous

Thank you verymuch. It is very usefull to work fast

Message 6 of 22
ramesh.axis
in reply to: petervose

Ohh.... Thanks a lot... Iam searching for it since many days.very usefull lisp for me Thank you Smiley Very Happy

Message 7 of 22
ramesh.axis
in reply to: petervose

Dear Peter,

I saw you lisp for dimension edit. it is very usefull to me. Iam searching for a lisp
I want draw some circles(holes) on a selected diagonal / horizontal / vertical line by required dimensions.Not equal.
I have below mentioned lisps, but circles placing on horizontal or vertical lines, not placing on diagonal lines.
Please rectify my lisp or give new lisp to me. It is very helpful to me. May be I couldn't explain what I want,
I am sending a drawing what i want to draw exactly.Please find the attachment.

I am very sorry for my poor english.Smiley Frustrated


My Lisp Code :


(defun c:hh ( / cols dir rows rowd rowh rowv rowo hole )
(initget 0 "Left Right")
(setq dir (getkword "\nEnd of Object (Left/Right) <L>: ")
rowd (getdist (strcat "\nGauge Line from Heel <" (rtos 3) ">: "))
rowo (getdist (strcat "\nSheare Edge <" (rtos 25) ">: "))
rowh (getdist (strcat "\nHole to Hole / center <" (rtos 3) ">: "))
cols (getint "\nNo. of Holes <1>: ")
hole (getdist (strcat "\nHole diameter " (rtos 17.5) ">: "))
)
(if (= dir nil)(setq dir "Left"))
(if (= rows nil)(setq rows 0))
(if (= cols nil)(setq cols 1))
(if (= rowd nil)(setq rowd 3))
(if (= rowh nil)(setq rowh 3))
(if (= rowo nil)(setq rowo 25))
(if (= hole nil)(setq hole 17.5))
(setq ins (getpoint "\nSelect insertion point: "))
(if (= dir "Left")
(progn
(setq ins (polar ins 0 rowo))
(repeat cols
(setq lstpnt (polar ins (* pi 1.5) rowd))
(entmake (list (cons 0 "circle")(cons 10 lstpnt)(cons 40 (/ hole 2.0))))
(repeat (1- rows)
(setq lstpnt (polar lstpnt (* pi 1.5) rowv))
(entmake (list (cons 0 "circle")(cons 10 lstpnt)(cons 40 (/ hole 2.0))))
)
(setq ins (polar ins 0 rowh))
)
)
(progn
(setq ins (polar ins pi rowo))
(repeat cols
(setq lstpnt (polar ins (* pi 1.5) rowd))
(entmake (list (cons 0 "circle")(cons 10 lstpnt)(cons 40 (/ hole 2.0))))
(repeat (1- rows)
(setq lstpnt (polar lstpnt (* pi 1.5) rowv))
(entmake (list (cons 0 "circle")(cons 10 lstpnt)(cons 40 (/ hole 2.0))))
)
(setq ins (polar ins pi rowh))
)
)
)
(princ)
)

Message 8 of 22
Kent1Cooper
in reply to: ramesh.axis

I would suggest you start a new thread.  The question is not on the subject of this one.

 

For that new topic:  Are the Circle spacings always the same?  Are the selected Lines always the same length?  Will you be selecting that yellow dashed-dotted Line?  Will the two Circles close together always be at the start of the Line, or might they sometimes need to be at the other end?

Kent Cooper, AIA
Message 9 of 22
tom
Explorer
in reply to: Anonymous

Hi, this one's great! thanks. Would you mind to tweak the code a bit to help me more? I'd like to override the dimmension by mathematical expression "<> + 420". I need to make a longitudinal cross section with many dimensions and a defined base ground. and I need to add the given base ground to the dimension measured by autocad. I would appreciate your help, thank you! Lucie

Message 10 of 22
Kent1Cooper
in reply to: tom


@tom wrote:

Hi, this one's great! thanks. Would you mind to tweak the code a bit to help me more? I'd like to override the dimmension by mathematical expression "<> + 420". I need to make a longitudinal cross section with many dimensions and a defined base ground. and I need to add the given base ground to the dimension measured by autocad. I would appreciate your help, thank you! Lucie


[I haven't seen *pkirill around here recently [that's a more-than-12-year-old post, after all], but....]

 

If you want it to literally add text with the plus sign and the 420, you should be able to just replace their "<> TYP" with that string of yours [and presumably change the command name].  But do you really want the text changed to a single number that's the mathematical result of adding 420 to the measured dimension?  That would be a different problem, but not too difficult to do.  A Search may even find something that does it already.

Kent Cooper, AIA
Message 11 of 22
tom
Explorer
in reply to: Kent1Cooper

Hi, this is Lucie actually, writing from my boyfriend's account. Sorry 🙂 exactly, I need to make math addition of these two values: original dim value + number I will choose. Example: orig. Autocad dim value is 2.91m, the lisp will add 499m, final result then 501.91m. Is it possible? Thanks, Lucie
Message 12 of 22
Kent1Cooper
in reply to: tom


@tom wrote:
Hi, this is Lucie actually, writing from my boyfriend's account. Sorry 🙂 exactly, I need to make math addition of these two values: original dim value + number I will choose. Example: orig. Autocad dim value is 2.91m, the lisp will add 499m, final result then 501.91m. Is it possible? Thanks, Lucie

This adjustment to *pkirill's code seems to do that.  I changed the command name and some variable names to be more meaningful [to me, at least], but you'll get the idea.  The changes relevant to the question are shown in red.  [You can even use a negative constant, if you want.]

 

(defun c:DTAC (/ addon dimss c ddata); = Dimension Text: Add Constant value
  (setq
    addon (getreal "\nConstant value to add to text of selected Dimension(s): ")
    dimss (ssget ":L" '((0 . "DIMENSION")))
    c -1
  ); setq
  (repeat (sslength dimss)
    (setq
      ddata (entget (ssname dimss (setq c (1+ c))))
      ddata
        (subst
          (cons 1 (rtos (+ (cdr (assoc 42 ddata)) addon) 2 2)); <-- adjust mode/precision as desired
          (assoc 1 ddata)
          ddata
        ); subst & adjusted ddata
    ); setq
    (entmod ddata)
  ); repeat
  (princ)
); defun

Kent Cooper, AIA
Message 13 of 22
tom
Explorer
in reply to: Kent1Cooper

Wow! Kent, you're a king! thank you so much, this will save me a lot of time doing this manually... thanks again 🙂

Message 14 of 22
lawrebewhat
in reply to: Kent1Cooper

How do i get the lisp file to work in my dimensions.

 

Tags (1)
Message 15 of 22
Kent1Cooper
in reply to: lawrebewhat


@lawrebewhat wrote:

How do i get the lisp file to work in my dimensions.

 


Welcome to these Forums!

 

There are lots of threads here, and elsewhere, about how to save and load and use AutoLisp command definitions, but quickly:

 

Copy the code parts out and Paste them into a plain-text editor such as Notepad.  Save to a file with a .lsp filetype ending.  In a drawing, use the APPLOAD command, navigate to where you saved that file, select and Load it.  Then to use it, type the command name, which is what follows the (defun c: [in this case, DTAC].

Kent Cooper, AIA
Message 16 of 22
jonkugler44
in reply to: petervose

Petervose,

I like your lisp, any chance of getting an alternative that enters the dimensions "measurement" value into the text override and allows selection of multiple dimensions so i can do lots at once?

In simple terms i want to be able to fix the value of the dimension and be able to change the grip positions without the displayed value changing. So if i have a 2000mm long dimension, then drag it to say 500mm long, i still want it to show 2000. TIA.

Message 17 of 22
ВeekeeCZ
in reply to: jonkugler44


@jonkugler44 wrote:

Petervose,

I like your lisp, any chance of getting an alternative that enters the dimensions "measurement" value into the text override and allows selection of multiple dimensions so i can do lots at once?

In simple terms i want to be able to fix the value of the dimension and be able to change the grip positions without the displayed value changing. So if i have a 2000mm long dimension, then drag it to say 500mm long, i still want it to show 2000. TIA.


 

This came up before many times, you could find more routines doing this. Here is my version. 

(defun c:DimValueToOverride ( / ss i ent bent ed txt pos)

  (if (setq ss (ssget "_:L" '((0 . "DIMENSION"))))
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i)))
            bent (tblobjname "BLOCK" (cdr (assoc 2 (entget ent)))))
      (while (setq bent (entnext bent))
        (if (= (cdr (assoc 0 (setq bdef (entget bent)))) "MTEXT")
          (progn
            (setq txt (cdr (assoc 1 bdef)))
            (if (setq pos (vl-string-search ";" txt))
              (setq txt (substr txt (+ 2 pos)))))))
      (entmod (subst (cons 1 txt)
                     (assoc 1 (entget ent))
                     (entget ent)))))
  (princ)
)
Message 18 of 22
Kent1Cooper
in reply to: jonkugler44


@jonkugler44 wrote:

.... an alternative that enters the dimensions "measurement" value into the text override ....


 

That sounds like a really bad idea for a variety of reasons, but if:

A]  you have a carefully-considered legitimate reason to need to do it, and

B]  your current Units format and precision are the same as those in the Dimension Style definition(s), and

C]  the selected Dimensions won't ever already have an override that you don't want replaced,

it can be as simple as this:

(defun C:DIMMVO (/ ss n dim ddata) ; = DIMension Measured Value as Override
  (if (setq ss (ssget "_:L" '((0 . "DIMENSION"))))
    (repeat (setq n (sslength ss))
      (setq ddata (entget (ssname ss (setq n (1- n)))))
      (entmod (subst (cons 1 (rtos (cdr (assoc 42 ddata)))) (assoc 1 ddata) ddata))
    ); repeat
  ); if
  (princ)
); defun

 

That could be enhanced to pull the Units format and precision from the Dimension Style definition if those might differ from current settings, as well as get the usual enhancements [error handling, Undo begin/end wrapping, etc.].

Kent Cooper, AIA
Message 19 of 22
jonkugler44
in reply to: jonkugler44

Many thanks Kent1Cooper and BeekeeCZ. Both of your lisps achieve what i need to. I like the DimValueToOverride better as it retains pre-existing prefix and suffix overrides and maintains precision value. Thanks so much for your help guys!

Message 20 of 22
paliwal222
in reply to: petervose

sir

i need to select multiple dimension at a time and want to feed different value for each dimension

if that possible please give me the code please

Thanks

 

 

 

 

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost