Jump to content

Recommended Posts

Posted

Using this line
(mapcar 'print (tblsearch "dimstyle" "ISO-25"))

for the text style "ISO-25", the command line outputs

(147 . 1.2) this is the offset of the text from the dimension line.

I want to change the text's offset from the dimension line - (147 . 0.425).

But I can't do it, the change is not happening, how can I fix it, please...

(defun c:Ch-DimTxtOff ( / ss entData)
  (setq ss (ssget '((0 . "DIMENSION")))) 
  (if (and dim (= (cdr (assoc 0 (entget dim))) "DIMENSION"))
    (progn
      (setq entData (entget dim))
     (setq entData (subst (cons 147 0.425) (assoc 147 entData) entData))
      (entmod entData)
         )
  )
  (princ)
)

 

DIM-147.png

DIMENSION-147.dwg

Posted
1 hour ago, hosneyalaa said:

TRY

It's hard for me to figure out what needs to be fixed in the code...

Posted

(ENTGET DIM).. DIM is not defined

  • Thanks 1
Posted (edited)
(defun c:Ch-DimTxtOff ( / ss entData n)
  (setq ss (ssget '((0 . "DIMENSION")))) 
  (while (and (setq dim (ssname ss (setq n (if n (1+ n) 0)))) (= (cdr (assoc 0 (entget dim))) "DIMENSION"))
    (progn
      (setq entData (entget dim))
     (setq entData (subst (cons 147 0.425) (assoc 147 entData) entData))
      (entmod entData)
         )
  )
  (princ)
)

 

I just added the code to define 'dim'
I haven't checked anything else.

Edited by GLAVCVS
  • Thanks 1
Posted
16 minutes ago, GLAVCVS said:

 

I just added the code to define 'dim'
I haven't checked anything else.

It doesn't work for some reason...

Posted

Okay
I guess it was also necessary to update from 'if' to 'while'

I edited that a few minutes ago, too.

  • Thanks 1
Posted
4 minutes ago, GLAVCVS said:

Okay
I guess it was also necessary to update from 'if' to 'while'

I edited that a few minutes ago, too.

And it didn't solve the problem...

Posted

The problem is that there's no DXF code 147 to control the text gap. That's controlled directly from the coordinate associated with code 11.
From VLA, you can control the gap using the "TextGap" property.

  • Thanks 1
Posted

You just need to replace the entire block under 'progn' with

(vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)

 

 

  • Thanks 1
Posted

Like This

(defun c:Ch-DimTxtOff ( / ss entData n)
  (setq ss (ssget '((0 . "DIMENSION")))) 
  (while (and (setq dim (ssname ss (setq n (if n (1+ n) 0)))) (= (cdr (assoc 0 (entget dim))) "DIMENSION"))
    (vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)
  )
  (princ)
)

 

  • Like 1
Posted
21 minutes ago, GLAVCVS said:

Like This

(defun c:Ch-DimTxtOff ( / ss entData n)
 (setq ss (ssget '((0 . "DIMENSION")))) 
 (while (and (setq dim (ssname ss (setq n (if n (1+ n) 0)))) (= (cdr (assoc 0 (entget dim))) "DIMENSION"))
 (vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)
 )
 (princ)
)

Now this code works very well. Thank you very much!

  • Like 1
Posted (edited)

You can also change the text colors to red.

There may be errors in the code, but the code works...

;; Added a text color change to red for resized text...
;; Thanks GLAVCVS  22.04.2025
;; https://www.cadtutor.net/forum/topic/97558-change-the-texts-offset-from-the-dimension-line/

(defun c:Ch-DimTxtOffCol ( / ss entData n oldGap)
  (setq ss (ssget '((0 . "DIMENSION"))))
  (while (and (setq dim (ssname ss (setq n (if n (1+ n) 0))))
              (= (cdr (assoc 0 (entget dim))) "DIMENSION"))
    (setq entData (entget dim))
    (setq oldGap (cdr (assoc 0 entData)))
   
(if (not (equal oldGap 0.425))
      (progn
        (vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)
        (vlax-put-property (vlax-ename->vla-object dim) "TextColor" 1) 
      )
      (vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)
    )
  )
  (princ)
)

 

Edited by Nikon
Posted
3 hours ago, Nikon said:

You can also change the text colors to red.

There may be errors in the code, but the code works...

;; Added a text color change to red for resized text...
;; Thanks GLAVCVS  22.04.2025
;; https://www.cadtutor.net/forum/topic/97558-change-the-texts-offset-from-the-dimension-line/

(defun c:Ch-DimTxtOffCol ( / ss entData n oldGap)
  (setq ss (ssget '((0 . "DIMENSION"))))
  (while (and (setq dim (ssname ss (setq n (if n (1+ n) 0))))
              (= (cdr (assoc 0 (entget dim))) "DIMENSION"))
    (setq entData (entget dim))
    (setq oldGap (cdr (assoc 0 entData)))
   
(if (not (equal oldGap 0.425))
      (progn
        (vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)
        (vlax-put-property (vlax-ename->vla-object dim) "TextColor" 1) 
      )
      (vlax-put-property (vlax-ename->vla-object dim) "TextGap" 0.425)
    )
  )
  (princ)
)

 

 

If 'oldGap' is '(cdr (assoc 0 entData)))' then it will always be different from 0.425 because oldGap= "DIMENSION"
If you want to get the current value of "TextGap" from the object contained in 'dim' you should call
'(vlax-get-property (vlax-ename->vla-object dim) "TextGap")'
But not '(cdr (assoc 0 entData))'

  • Thanks 1
Posted

Just a comment in this situation these two do the same task.

 

(vlax-put-property

(vlax-put

Another

"Textgap"

'Textgap

 

  • Thanks 1

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