mhghonaim Posted December 5, 2022 Posted December 5, 2022 (defun c:@Dims (/ dist ss n eo) (if (and (setq dist (getdist "\nSpecify increment distance: ")) (setq ss (ssget '((0 . "DIMENSION")))) ) (progn (setq n (sslength ss)) (while (> (setq n (1- n)) -1) (setq eo (vlax-ename->vla-object (ssname ss n))) (vla-put-AltUnitsScale eo dist) (vla-put-LinearScaleFactor eo (/ 1.0 dist)) (vla-put-TextOverride eo (strcat "[%<\\AcExpr (1+%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).Measurement \\f \"%lu2%pr0\">%) \\f \"%lu2%pr0\">%]\\X@ %<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).AltUnitsScale \\f \"%lu2%pr0\">% C/C" ) ) (vla-Update eo) ) ) ) (command "._UpdateField" ss "") (princ) ) hi i have been looking for a lisp dividing dim and showing n of spaces with original dim . this lisp is perfect but still missing dim value . hope to have some help to show this thanks Quote
pkenewell Posted December 5, 2022 Posted December 5, 2022 @mhghonaim Could you please send a sample drawing? not sure what the dimension looks like overall and what it is dimensioning. Quote
pkenewell Posted December 6, 2022 Posted December 6, 2022 (edited) Ok - try one of these 2 routines: (vl-load-com) (defun c:@Dims (/ dist div ss n eo) (if (and (setq dist (getdist "\nSpecify increment distance: ")) (setq ss (ssget '((0 . "DIMENSION")))) ) (progn (setq n (sslength ss)) (while (> (setq n (1- n)) -1) (setq eo (vlax-ename->vla-object (ssname ss n))) (vla-put-AltUnitsScale eo dist) (setq div (/ 1.0 dist)) (vla-put-TextOverride eo (strcat "<>\\X[%<\\AcExpr (" (rtos div 2 2) "*%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).Measurement \\f \"%lu2%pr0\">%) \\f \"%lu2%pr0\">%]@%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).AltUnitsScale \\f \"%lu2%pr0\">%" ) ) (vla-Update eo) ) ) ) (command "._UpdateField" ss "") (princ) ) (defun c:@Dims2 (/ dist ss n eo) (if (and (setq dist (getdist "\nSpecify increment distance: ")) (setq ss (ssget '((0 . "DIMENSION")))) ) (progn (setq n (sslength ss)) (while (> (setq n (1- n)) -1) (setq eo (vlax-ename->vla-object (ssname ss n))) (vla-put-AltUnitsScale eo dist) (vla-put-TextOverride eo (strcat"<>\\X(%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).AltUnitsScale \\f \"%lu2%pr0\">%)" ) ) (vla-Update eo) ) ) ) (command "._UpdateField" ss "") (princ) ) EDIT - don't forget a (vl-load-com) statement. Added to top of code block. Edited December 6, 2022 by pkenewell Added clarification 1 Quote
mhghonaim Posted December 6, 2022 Author Posted December 6, 2022 for 1st one : value is not correct and the second only shows spacing correct value is 3000/200 = 15 spaces Lisp req style.dwg Quote
pkenewell Posted December 6, 2022 Posted December 6, 2022 OK - I am not understanding your picture. it says "Correct n" is "16" yet you said divide the distance by the overall correctly at "15 spaces". The code I have updated below gives this - is it correct? Why the extra 1 division? The 2nd updated code below adds the 1 to it. 1st Code: (defun c:@Dims (/ dist ss n eo) (vl-load-com) (if (and (setq dist (getdist "\nSpecify increment distance: ")) (setq ss (ssget '((0 . "DIMENSION")))) ) (progn (setq n (sslength ss)) (while (> (setq n (1- n)) -1) (setq eo (vlax-ename->vla-object (ssname ss n))) (vla-put-AltUnitsScale eo dist) (vla-put-TextOverride eo (strcat "<>\\X[%<\\AcExpr (%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).Measurement \\f \"%lu2%pr0\">%/" (rtos dist 2 2) ") \\f \"%lu2%pr0\">%]@%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).AltUnitsScale \\f \"%lu2%pr0\">%" ) ) (vla-Update eo) ) ) ) (command "._UpdateField" ss "") (princ) ) 2nd Code: (defun c:@Dims2 (/ dist ss n eo) (vl-load-com) (if (and (setq dist (getdist "\nSpecify increment distance: ")) (setq ss (ssget '((0 . "DIMENSION")))) ) (progn (setq n (sslength ss)) (while (> (setq n (1- n)) -1) (setq eo (vlax-ename->vla-object (ssname ss n))) (vla-put-AltUnitsScale eo dist) (vla-put-TextOverride eo (strcat "<>\\X[%<\\AcExpr (1+(%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).Measurement \\f \"%lu2%pr0\">%/" (rtos dist 2 2) ")) \\f \"%lu2%pr0\">%]@%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectID eo)) ">%).AltUnitsScale \\f \"%lu2%pr0\">%" ) ) (vla-Update eo) ) ) ) (command "._UpdateField" ss "") (princ) ) Please let me know. 1 Quote
mhupp Posted December 6, 2022 Posted December 6, 2022 This should be what you want. getting rid off all the field id's unless you change them alot. you will have to rerun the lisp to update if you change any of the dimensions. (defun c:@Dims (/ dist SS eo len div) (vl-load-com) (if (and (setq dist (getdist "\nSpecify Increment Distance: ")) (setq SS (ssget '((0 . "DIMENSION")))) ) (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq eo (vlax-ename->vla-object dim)) (setq len (vlax-get eo 'Measurement)) (setq div (fix (/ len dist))) ;round to whole number 15.9 = 15 (vla-put-TextOverride eo (strcat (rtos len 2 0) "/" (rtos dist 2 0) " = " (rtos div 2 0) " Spaces")) ) ) (vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport) ;regen active viewport (princ) ) 1 Quote
pkenewell Posted December 6, 2022 Posted December 6, 2022 (edited) 13 minutes ago, mhupp said: This should be what you want. getting rid off all the field id's unless you change them alot. you will have to rerun the lisp to update if you change any of the dimensions. (defun c:@Dims (/ dist SS eo len div) (vl-load-com) (if (and (setq dist (getdist "\nSpecify Increment Distance: ")) (setq SS (ssget '((0 . "DIMENSION")))) ) (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq eo (vlax-ename->vla-object dim)) (setq len (vlax-get eo 'Measurement)) (setq div (fix (/ len dist))) ;round to whole number 15.9 = 15 (vla-put-TextOverride eo (strcat (rtos len 2 0) "/" (rtos dist 2 0) " = " (rtos div 2 0) " Spaces")) ) ) (vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport) ;regen active viewport (princ) ) I figured he wanted the fields in the first place so it would change when the dimension changed. You just have to run the UPDATEFIELD command on the drawing. Your way works the same since you just run the command again on all the dimensions. I was just trying to stick to the OPs intent. If the OP had several different divisions in the same drawing he would have to run the command again multiple times. Edited December 6, 2022 by pkenewell 1 Quote
mhghonaim Posted December 6, 2022 Author Posted December 6, 2022 ok all lisps are fine but still have 2 issues: 1- i need number rounded up Ex 10.1 = 11 as spacing can not exceed given value . 2- selection of multiple dimensions at once would be much better is i have to enter spacing each time . also its would be perfect if last entered space value is stored as a default so just tab. i use that for giving numbers to distribute reinforcement bars in structural elements which can be up to 50 element for each sheet . so repetitive steps does take long time. regards,,, Quote
pkenewell Posted December 6, 2022 Posted December 6, 2022 OK - I'll look into it. Since I am no expert with field expressions, I am not sure if it can be done that way. mhupp's solution might work better for you with a 1+ added. if the number rounds down. 1 Quote
mhupp Posted December 6, 2022 Posted December 6, 2022 55 minutes ago, mhghonaim said: ok all lisps are fine but still have 2 issues: 1- i need number rounded up Ex 10.1 = 11 as spacing can not exceed given value . 2- selection of multiple dimensions at once would be much better is i have to enter spacing each time . also its would be perfect if last entered space value is stored as a default so just tab. i use that for giving numbers to distribute reinforcement bars in structural elements which can be up to 50 element for each sheet . so repetitive steps does take long time. regards,,, 1 - How far do you want togo with the rounding? 10.09 = 11 10.009 = 11 any number that isnt whole add 1? 2 - all codes use ssget and allow for multi select. 2.2 - thats easy enought do you want tit to remeber between drawings or only last value in current drawing? Quote
mhghonaim Posted December 7, 2022 Author Posted December 7, 2022 5 hours ago, mhupp said: 1 - How far do you want togo with the rounding? 10.09 = 11 10.009 = 11 any number that isnt whole add 1? 2 - all codes use ssget and allow for multi select. 2.2 - thats easy enought do you want tit to remeber between drawings or only last value in current drawing? 1- any 2 digits after float to be rounded up 2-only current drawing Quote
mhupp Posted December 7, 2022 Posted December 7, 2022 This will round up any divide number that is in range of ##.99 - ##.01 And will also save the variable in the drawing as Ldata so it can be recalled the next time the command is run. If you want to use the number between the brackets just hit enter Specify Distance [200]: (defun c:@Dims (/ D dist SS eo len div) (or (setq D (vlax-ldata-get "Distance" "D")) (setq D 200.0)) ;set D with numbers not strings "200.0" (if (setq dist (getdist (strcat "\nSpecify Distance [" (rtos D 2 0) "]: "))) (vlax-ldata-put "Distance" "D" dist) ;updates with new distance (vlax-ldata-put "Distance" "D" (setq dist D)) ;sets dist to D also updates ldata ) (if (setq SS (ssget '((0 . "DIMENSION")))) (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq eo (vlax-ename->vla-object dim)) (setq len (vlax-get eo 'Measurement)) (if (> (- (/ len dist) (setq div (fix (/ len dist)))) 0.009) (setq div (1+ (fix (/ len dist)))) ) (vla-put-TextOverride eo (strcat (rtos len 2 0) "/" (rtos dist 2 0) " = " (rtos div 2 0) " Spaces")) ) (vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport) ;regen active viewport (princ) ) (princ) ) 1 1 Quote
mhghonaim Posted December 7, 2022 Author Posted December 7, 2022 5 hours ago, mhupp said: This will round up any divide number that is in range of ##.99 - ##.01 And will also save the variable in the drawing as Ldata so it can be recalled the next time the command is run. If you want to use the number between the brackets just hit enter Specify Distance [200]: (defun c:@Dims (/ D dist SS eo len div) (or (setq D (vlax-ldata-get "Distance" "D")) (setq D 200.0)) ;set D with numbers not strings "200.0" (if (setq dist (getdist (strcat "\nSpecify Distance [" (rtos D 2 0) "]: "))) (vlax-ldata-put "Distance" "D" dist) ;updates with new distance (vlax-ldata-put "Distance" "D" (setq dist D)) ;sets dist to D also updates ldata ) (if (setq SS (ssget '((0 . "DIMENSION")))) (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq eo (vlax-ename->vla-object dim)) (setq len (vlax-get eo 'Measurement)) (if (> (- (/ len dist) (setq div (fix (/ len dist)))) 0.009) (setq div (1+ (fix (/ len dist)))) ) (vla-put-TextOverride eo (strcat (rtos len 2 0) "/" (rtos dist 2 0) " = " (rtos div 2 0) " Spaces")) ) (vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport) ;regen active viewport (princ) ) (princ) ) Perfect Many thanks for your efforts. Quote
Recommended Posts
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.