Jump to content

REQ Lisp for Dimension divided by spacing with dimension value shown


Recommended Posts

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

image.png.fb4e2cc187763ed68f2c7d091530cb4a.png

hope to have some help to show this 

image.png.04be69469a9ce63579cd2c11659e6d36.png

thanks

Posted

@mhghonaim Could you please send a sample drawing? not sure what the dimension looks like overall and what it is dimensioning.

Posted (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 by pkenewell
Added clarification
  • Like 1
Posted

image.png.8dd3f376d1549a8751c28187b5984588.png

 

for 1st one : value is not correct 

and the second only shows spacing 

 

correct value is 3000/200 = 15 spaces

Lisp req style.dwg

Posted

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:

image.png.a3ada58c376d49dec0846fad3059a89d.png

 

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

image.png.64bfccca42f93b4060c8066c1c9d4227.png

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

  • Like 1
Posted

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

 

  • Like 1
Posted (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 by pkenewell
  • Like 1
Posted

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

Posted

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.

  • Like 1
Posted
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?

Posted
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

 

Posted

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

 

  • Like 1
  • Thanks 1
Posted
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.

 

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