Jump to content

Recommended Posts

Posted (edited)

Hello everyone!

How can I change the code so that the color of the dimensional text changes only for sizes whose text has been
changed manually?

; changes the color of the dimensional text by 1
 (defun C:ChDimTxtCol1 (/ int sel ent obj DimTextColor)
  (vl-load-com)
  (setq DimTextColor 1) 
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION")))
       ) 
       (while (setq int	(1+ int)
		    ent	(ssname sel int)) 
	 (setq obj (vlax-ename->vla-object ent))
	 (vla-put-TextColor obj DimTextColor) 
       ) 
  ) 
  (princ)
)

 

 

ChDimTxtCol1-.png

Edited by Nikon
Posted
  On 4/6/2025 at 4:34 PM, Nikon said:

Hello everyone!

How can I change the code so that the color of the dimensional text changes only for sizes whose text has been
changed manually?

; changes the color of the dimensional text by 1
 (defun C:ChDimTxtCol1 (/ int sel ent obj DimTextColor)
  (vl-load-com)
  (setq DimTextColor 1) 
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION")))
       ) 
       (while (setq int	(1+ int)
		    ent	(ssname sel int)) 
	 (setq obj (vlax-ename->vla-object ent))
	 (vla-put-TextColor obj DimTextColor) 
       ) 
  ) 
  (princ)
)

 

 

ChDimTxtCol1-.png

Expand  

 

You should simply condition the color change on the value of the 'TextHeight' property being different from '(getvar 'DIMTXT)

Posted
(defun C:ChDimTxtCol1 (/ int sel ent obj DimTextColor)
  (vl-load-com)
  (setq DimTextColor 1) 
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION")))
       ) 
       (while (setq int	(1+ int)
		    ent	(ssname sel int)) 
	 (setq obj (vlax-ename->vla-object ent))
	 (if (/= (vla-get-textHeight obj) (getvar'DIMTXT)) (vla-put-TextColor obj DimTextColor)) 
       ) 
  ) 
  (princ)
)

 

  • Thanks 1
Posted
  On 4/6/2025 at 5:18 PM, GLAVCVS said:
(defun C:ChDimTxtCol1 (/ int sel ent obj DimTextColor)
 (vl-load-com)
 (setq DimTextColor 1) 
 (and (setq int -1 sel (ssget '((0 . "*DIMENSION")))
 ) 
 (while (setq int (1+ int)
 ent (ssname sel int)) 
 (setq obj (vlax-ename->vla-object ent))
 (if (/= (vla-get-textHeight obj) (getvar'DIMTXT)) (vla-put-TextColor obj DimTextColor)) 
 ) 
 ) 
 (princ)
Expand  

thanks, but the text color hasn't changed...

Posted

WHY DID YOU REMOVE MY PROGRAM'S HEADER FROM THE CODES ?

REMOVE MY CODES FROM YOUR THREAD

Posted
  On 4/6/2025 at 5:39 PM, Tharwat said:

WHY DID YOU REMOVE MY PROGRAM'S HEADER FROM THE CODES ?

REMOVE MY CODES FROM YOUR THREAD

Expand  

I do not know your code, and I did not delete anything...

Posted

Is this an inherited drawing or did you create it yourself?

If the DIMENSION objects were created with the same height as the DIMTXT value, and your modifications were made to the text from there, it should work.

Posted (edited)
  On 4/6/2025 at 6:11 PM, GLAVCVS said:

Is this an inherited drawing or did you create it yourself?

If the DIMENSION objects were created with the same height as the DIMTXT value, and your modifications were made to the text from there, it should work.

Expand  

Why are you talking about the height of the text, I'm interested in the color.

Sometimes there are dimensions in the drawings, the text of which has been changed, in order to find them, I want to use a color change.

Edited by Nikon
Posted (edited)

Then I'm afraid I misunderstood. I thought you wanted to change the color of DIMENSION texts whose sizes have been changed after they were created.
Did I misunderstand then?

Edited by GLAVCVS
Posted (edited)
  On 4/6/2025 at 6:25 PM, GLAVCVS said:

Then I'm afraid I misunderstood. I thought you wanted to change the color of DIMENSION texts whose sizes have been changed after they were created.
misunderstand then?

Expand  

Yes, I have such intentions - change the color of DIMENSION texts whose sizes have been changed after they were created..

Edited by Nikon
Posted
  On 4/6/2025 at 5:53 PM, Nikon said:

I do not know your code, and I did not delete anything...

Expand  

Then where did you get the codes from ?

Posted

add xdata to create a dimstyle override , in python it would be

xd = [(1001, "ACAD"), (1000, "DSTYLE"), (1002, "{"), (1070, 178), (1070, 1), (1002, "}")]

 

# add dim override
@command
def doit2():
    ps, id, _ = Ed.Editor.entSel("\nSelect:", Db.Dimension.desc())
    if ps != Ed.PromptStatus.eOk:
        return
    dim = Db.Dimension(id, Db.OpenMode.kForWrite)

    # todo check if there's aready a dimstyle override
    # 178 = dimclrt
    # 1 is red
    xd = [(1001, "ACAD"), (1000, "DSTYLE"), (1002, "{"), (1070, 178), (1070, 1), (1002, "}")]
    dim.setXData(xd)

 

  • Thanks 1
Posted

You can check has text been overidden.

 

;   TextOverride = "<> ABC" ABC added

;   TextOverride = "" this has not been cahnged 

(vlax-get obj 'textoveride)

 

  • Thanks 1
Posted (edited)

see below:

(defun c:ChDimTxtCol1 (/ i sel ent obj)
(vl-load-com)
(setq i 0)
;(setq DimTextColor 1)
 (if (setq sel (ssget '((0 . "*DIMENSION"))))
  (progn
    (repeat (sslength sel)
      (setq ent (ssname sel i))
      (setq obj (vlax-ename->vla-object ent))
      (if (/= (vlax-get obj 'textoverride) "")
         (vlax-put-property obj 'TextColor 1)
         ;(vlax-put-property obj 'TextColor DimTextColor)
      );if
      (setq i (+ i 1))
    );end repeat 
  );end progn 
  (alert "No Dimensions selected")
 );end if sel
 (princ) 
);defun

 

*EDIT:

I removed the "DimTextColor" varaible because it is redandet and set the textcolor directly to 1 this way:

(vlax-put-property obj 'TextColor 1)

 

Edited by aridzv
  • Like 1
Posted

I think the only way to know what's going on is if you attach an example drawing.

Posted
  On 4/7/2025 at 9:01 AM, aridzv said:

see below:

(defun c:ChDimTxtCol1 (/ i DimTextColor sel ent obj)
(vl-load-com)
(setq i 0)
(setq DimTextColor 1)
 (if (setq sel (ssget '((0 . "*DIMENSION"))))
 (progn
 (repeat (sslength sel)
 (setq ent (ssname sel i))
 (setq obj (vlax-ename->vla-object ent))
 (if (/= (vlax-get obj 'textoverride) "")
 (vlax-put-property obj 'TextColor DimTextColor)
 );if
 (setq i (+ i 1))
 );end repeat 
 );end progn 
 (alert "No Dimensions selected")
 );end if sel
 (princ) 
);defun
Expand  

@aridzv I am very grateful to you!
That's what I need! Good luck!

  • Thanks 1
Posted

@Nikon As for Tharwat's claim, I think he's pretty sure that this code is his.
Perhaps this code reached you indirectly, and you didn't know who its author was.
Therefore, it might be smart to mention @Tharwat somewhere.

🙂

Posted
  On 4/7/2025 at 9:02 AM, GLAVCVS said:

I think the only way to know what's going on is if you attach an example drawing.

Expand  

@GLAVCVS Thank you for participating!

Posted
  On 4/7/2025 at 9:17 AM, GLAVCVS said:

@Nikon As for Tharwat's claim, I think he's pretty sure that this code is his.
Perhaps this code reached you indirectly, and you didn't know who its author was.
Therefore, it might be smart to mention @Tharwat somewhere.

🙂

Expand  

 

however... quite aggressive asking for the credit here today. Nicer ways to go "Hey, this was originally my code, can you credit me" and perhaps if possible the link to the original code to help the OP out. Code gets shared, the links and credits lost. Always good practice to add links to the sources and credits in case there are thing you want to go back and understand more from any discussions.

 

Having said that though, upload code, you have no control of it's use and I am not sure I'd want credited with a base code that is mine and then heavily modified, or just a snippet of my code included in something larger without me doing checks and testing.

  • Agree 5

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