Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Function on multiple objects at once

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
879 Views, 6 Replies

Function on multiple objects at once

Hello, I am trying to create a function which reads a dimension and changes the dimension precision to the minimum amount with _AIDIMPREC:

e.g. 12.345000 --> 12.345

       12.000 --> 12

       12.345678  --> 12.345678

 

The code I have right now is as so:

^C^C^P(SETQ EN (CAR (ENTSEL "Select Dimention: "))
VAL (CDR (ASSOC 42 (ENTGET EN)))
COUNTER 6
CHECKER 6)
\(WHILE (> CHECKER 0)
(SETQ VALTEMP (RTOS VAL 2 COUNTER)
VALLEN (STRLEN VALTEMP)
SUBSTRING (SUBSTR VALTEMP VALLEN 1)
COUNTER (IF (EQUAL SUBSTRING "0") (- COUNTER 1) (* COUNTER 1))
CHECKER (IF (/= SUBSTRING "0") (- CHECKER 100) (- CHECKER 1))))
^C(COMMAND "._AIDIMPREC" COUNTER EN "") ^C^C^P

 

This does work, but it can only choose and affect one dimension at a time.

Is there a way to allow this function to affect multiple dimensions, all chosen at once?

would: (ssget '((0 . "DIMENSION")))  work? and if so, how do I allow each selected object to be affected by my function?

 

I just starting with AutoCAD LISP, so any help would be really helpful. Thank you.

6 REPLIES 6
Message 2 of 7
Kent1Cooper
in reply to: Anonymous

You should be able to control that without any routine, with an appropriate setting of the DIMZIN System Variable, which controls [among other things] the display of [leading and] trailing zeros, and/or in the Dimension Style modifying dialog box, Primary Units tab, Zero suppression area.

Kent Cooper, AIA
Message 3 of 7
Anonymous
in reply to: Kent1Cooper

I understand that is possible using DIMZIN, but what I am aiming for is to minimize the dimension precision, while not changing the dimension style. So the decimal becomes minimized but still allows me to dimension precision later on without re-using DIMZIN.

Message 4 of 7
Anonymous
in reply to: Anonymous

I've gotten this far with my code:

 

^C^C^P(SETQ SS1 (SSGET '((0 . "DIMENSION"))))
\(SETQ i 0)
(REPEAT (SSLENGTH SS1)
   (SETQ EN (SSNAME SS1 i)
   ED (CDR (ASSOC 42 (SETQ ENTS (ENTGET EN))))
   COUNTER 6
   CHECKER 6
   i (+ i 1))
   (WHILE (> CHECKER 0)
      (SETQ VALTEMP (RTOS ED 2 COUNTER)
      VALLEN (STRLEN VALTEMP)
      SUBSTRING (SUBSTR VALTEMP VALLEN 1)
      COUNTER (IF (EQUAL SUBSTRING "0") (- COUNTER 1) (* COUNTER 1))
      CHECKER (IF (/= SUBSTRING "0") (- CHECKER 100) (- CHECKER 1))))
(COMMAND "_AIDIMPREC" COUNTER EN "")) ^C^C^P

 

If I run the SSGET (first line of code) and REPEAT (all the rest of the code) sections one by one, it works fine,

but for some reason, when I run all the code at once as a command macro, it does nothing.

 

Can anyone help me with this predicament?

Message 5 of 7
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....what I am aiming for is to minimize the dimension precision, while not changing the dimension style. So the decimal becomes minimized but still allows me to dimension precision later on without re-using DIMZIN.


It sounds dangerous to me to assign displayed-value precisions to individual Dimension objects overriding the precision in the Dimension Style.  Say you have a Dimension [one of your examples] whose measured value is 12.000, and you therefore change its display precision so that it shows just 12.  Later, you have reason to adjust something in the drawing, and that Dimension gets stretched, so that its measured value is now 12.4723.  If it has a round-to-the-nearest-whole-number precision override, won't it still show just 12?  I would have to assume you don't  want that result.  I think you would need to run the routine again to "fix" the displayed value.

 

Also, I don't understand how setting DIMZIN and the Style's Zero-suppression setting to suppress trailing zeros in any way interferes with your ability to "dimension precision later on."  All Dimensions will give you as many decimal places as the precision setting calls for, until  the remaining ones are all zeros, which will be omitted.

 

Am I mis-reading something?

Kent Cooper, AIA
Message 6 of 7
Anonymous
in reply to: Kent1Cooper

I fully understand your concern and what you say is true. I normally just use the Zero-suppression setting in situations like this too. But there is a catch.

First of all, apologies for saying "...using DIMZIN to change the precision", that was my mistake.

What I meant to say was "minimizing the dimensions' precision, while allowing me to change the precision freely, without the need of turning on and off the Zero-suppression setting depending on the need".

Also, I plan on using the Zero-suppression setting in tandem with this code to ensure any errors can be detected.

 

It's just that in my work, dimensions on drawings all have a different amount of decimal values to show the amount of precision needed when manufacturing that drawing.

For example, if a dimension says "12.0", while another says "12.000", this means the margin of error allowed for the "12.000" dimension is much smaller than the "12.0" one. (i.e. if the product of the drawing is manufactured with an actual value of "12.01", meaning there is an error of +0.01. If the dimension on the drawing was "12.0", then the product is OK to be shipped. BUT if the dimension on the drawing was "12.000", the product is deemed bad, and the production must stop.)

And representing the precision of each dimension by hand will take time, well as using the Zero-suppression setting won't allow me to change the decimal precision as I want. So that is why I need this code.

 

I did find a way to make my code work though, it's not pretty but it's a start I guess:

 

^C^C^P_PICKFIRST;1;_SELECT;\(SETQ i 0
     SS1 (SSGET "P" '((0 . "DIMENSION"))))
(REPEAT (SSLENGTH SS1)
     (SETQ EN (SSNAME SS1 i)

          ED (CDR (ASSOC 42 (SETQ ENTS (ENTGET EN))))
          COUNTER 6
          CHECKER 6
          i (+ i 1))
     (WHILE (> CHECKER 0)
          (SETQ VALTEMP (RTOS ED 2 COUNTER)
          VALLEN (STRLEN VALTEMP)
          SUBSTRING (SUBSTR VALTEMP VALLEN 1)
          COUNTER (IF (EQUAL SUBSTRING "0") (- COUNTER 1) (* COUNTER 1))
          CHECKER (IF (/= SUBSTRING "0") (- CHECKER 100) (- CHECKER 1))))
(COMMAND "_AIDIMPREC" COUNTER EN ""))
^C^C^P

 

I just added the SELECT up front, and it worked like a charm!

Thank you for your replies!!

Message 7 of 7
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... if a dimension says "12.0", while another says "12.000", this means the margin of error allowed for the "12.000" dimension is much smaller than the "12.0" one. ....


Isn't that exactly what Dimensioning tolerances are for?  Dimension Styles can include tolerances, and if you make Styles with them for each degree of precision you need, switching the precision or tolerance level of a given Dimension would be simply changing its Style.  These are the same dimensioned length with different Styles assigned:

Tolerances.PNG

You get lots of choices beyond the level of precision, such as height and position relative to the main measured-distance number, and you can have a greater or lesser tolerance in the plus direction than minus, etc.

Kent Cooper, AIA

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report