Jump to content

Keeping Tolerance overrides after changing dimstyles


KGehrels

Recommended Posts

I've got code that is switching the dimstyles of dimensions.  In order to keep the tolerances I have a section that records the tolerance settings before the change then reapplies them.  The issue that I'm having is that, even though the print lines I added for debugging are showing that the tolerance display numbers are the same the tolerance (2 in this case) the tolerance changes from deviation to symmetrical and the tolerance lower limit is changing from 0 to 0.0625.

 

Any thoughts on this odd behaviour?

(defun Collate (stylescale dimlist stylename / dimscale tdisp thscale tjust tllimit tprec tsuplz tsuptz tsupzf tsupzi tulimit)
  (Foreach dim dimlist
    (setq dimscale (vlax-get-property dim "LinearScaleFactor")) ; Find the scale of each dimension
    ; Get all tolerance properties
    (setq tdisp (vlax-get-property dim "ToleranceDisplay"))
    (setq thscale (vlax-get-property dim "ToleranceHeightScale"))
    (setq tjust (vlax-get-property dim "ToleranceJustification"))
    (setq tllimit (vlax-get-property dim "ToleranceLowerLimit"))
    (setq tprec (vlax-get-property dim "TolerancePrecision"))
    (setq tsuplz (vlax-get-property dim "ToleranceSuppressLeadingZeros"))
    (setq tsuptz (vlax-get-property dim "ToleranceSuppressTrailingZeros"))
    (setq tsupzf (vlax-get-property dim "ToleranceSuppressZeroFeet"))
    (setq tsupzi (vlax-get-property dim "ToleranceSuppressZeroInches"))
    (setq tulimit (vlax-get-property dim "ToleranceUpperLimit"))
      (if
        (equal dimscale stylescale 0.1) ; Check if the style scale matches the dimension scale
        (progn ; If true then:
          (vlax-put-property dim "StyleName" stylename) ; Assign the dimstyle to the dimension
          (print (strcat "old display: " (itoa tdisp)))
          ;Apply all tolerance properties from above
          (vlax-put-property dim "ToleranceDisplay" tdisp)
          (vlax-put-property dim "ToleranceHeightScale" thscale)
          (vlax-put-property dim "ToleranceJustification" tjust)
          (vlax-put-property dim "ToleranceLowerLimit" tllimit)
          (vlax-put-property dim "TolerancePrecision" tprec)
          (vlax-put-property dim "ToleranceSuppressLeadingZeros" tsuplz)
          (vlax-put-property dim "ToleranceSuppressTrailingZeros" tsuptz)
          (vlax-put-property dim "ToleranceSuppressZeroFeet" tsupzf)
          (vlax-put-property dim "ToleranceSuppressZeroInches" tsupzi)
          (vlax-put-property dim "ToleranceUpperLimit" tulimit)
          (princ (strcat "new display: " (itoa tdisp)))
        ) ; End progn
      ) ; End if
  ) ; End Foreach
) ; End Collate

 

Link to comment
Share on other sites

Have a look at my post here, a list of all the variables for dimensions (it is the second bit of code that contains the list), might be you need to change another variable?

Link to comment
Share on other sites

Can you please post the link that you are referring to.

I used some code that was posted on this site to get all of the variables for a dimension (I forget who posted so I can't give credit where it's due) and double checked that I used all tolerance related variables.  If there is another variable it is one that isn't obvious.  Or this is one of those things where there are 4 different ways to make it work but each of those can only be used in specific circumstances and the only way to know is to stumble across it or be told (sort of like setting the colour of various object to "bylayer", all of these work at some point: bylayer, -1, 0, 256).

Link to comment
Share on other sites

Those all look like dimstyle codes.  I'm not looking to change the dimstyle, just maintain some dimension overrides.

I tried looking through these codes but couldn't find anything that isn't controlled by the commands that I've already put in the code.

https://74mph.com/faq/FAQ00066.html

Link to comment
Share on other sites

Is there a way of applying dimstyle overrides to dimensions?

I found this thread which contains great information from @Lee Mac but I can't get the same idea to work in my code.

Change a system variable for a single Dim entity ... (theswamp.org)

 

My code is:

(defun LinearCollate (stylescale dimlist stylename / dimscale txtovr txtpre txtsuf tdisp thscale tjust tllimit tprec tsuplz tsuptz tsupzf tsupzi tulimit)
  (vl-load-com)
  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-activedocument acadObj))
  
  (Foreach dim dimlist
    (setq dimscale (vlax-get-property dim "LinearScaleFactor")) ; Find the scale of each dimension
    ; Get all tolerance properties
    (setq txtovr (vlax-get-property dim "TextOverride"))
    (setq txtpre (vlax-get-property dim "TextPrefix"))
    (setq txtsuf (vlax-get-property dim "TextSuffix"))
    (setq tdisp (vlax-get-property dim "ToleranceDisplay"))
    (setq thscale (vlax-get-property dim "ToleranceHeightScale"))
    (setq tjust (vlax-get-property dim "ToleranceJustification"))
    (setq tllimit (vlax-get-property dim "ToleranceLowerLimit"))
    (setq tprec (vlax-get-property dim "TolerancePrecision"))
    (setq tsuplz (vlax-get-property dim "ToleranceSuppressLeadingZeros"))
    (setq tsuptz (vlax-get-property dim "ToleranceSuppressTrailingZeros"))
    (setq tsupzf (vlax-get-property dim "ToleranceSuppressZeroFeet"))
    (setq tsupzi (vlax-get-property dim "ToleranceSuppressZeroInches"))
    (setq tulimit (vlax-get-property dim "ToleranceUpperLimit"))
    ;DIMLIM, 0=Symmetrical, 1=Bilateral, I think that this is a system variable
    (if
      (equal dimscale stylescale 0.1) ; Check if the style scale matches the dimension scale
      (progn ; If true then:
        (if (equal tdsip 2)
          ("ACAD"
            (1000 . "DSTYLE")
            (1002 . "{")
            (1070 . 72) (1070 . 1)
            (1002 . "}")
          )
        ) ; end if
        (vlax-put-property dim "StyleName" stylename) ; Assign the dimstyle to the dimension
        ;Apply all tolerance properties from above
        (vlax-put-property dim "TextOverride" txtovr)
        (vlax-put-property dim "TextPrefix" txtpre)
        (vlax-put-property dim "TextSuffix" txtsuf)
        (vlax-put-property dim "ToleranceDisplay" tdisp)
        (vlax-put-property dim "ToleranceHeightScale" thscale)
        (vlax-put-property dim "ToleranceJustification" tjust)
        (vlax-put-property dim "ToleranceLowerLimit" tllimit)
        (vlax-put-property dim "TolerancePrecision" tprec)
        (vlax-put-property dim "ToleranceSuppressLeadingZeros" tsuplz)
        (vlax-put-property dim "ToleranceSuppressTrailingZeros" tsuptz)
        (vlax-put-property dim "ToleranceSuppressZeroFeet" tsupzf)
        (vlax-put-property dim "ToleranceSuppressZeroInches" tsupzi)
        (vlax-put-property dim "ToleranceUpperLimit" tulimit)
      ) ; End progn
    ) ; End if
  ) ; End Foreach
) ; End LinearCollate

 

When I try this I get this error: bad function in expression: ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 72) (1070 . 1) (1002 . "}"))

What am I doing wrong?

Link to comment
Share on other sites

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