Jump to content

Please help me create a lisp to Change color of dimension


TINDANG
 Share

Recommended Posts

To change the dim color to red. I selected it, then edited the parameters in the properties panel.

Please help me create a lisp to do that🤔

Screenshot 2022-07-27 161842.jpg

Link to comment
Share on other sites

Here you go.

(defun c:Test (/ int sel ent nxt)
  ;; Tharwat Al Choufi.	- Date: 27.Jun.2022		;;
  ;; website: https://autolispprograms.wordpress.com	;;
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (setq nxt (tblobjname "BLOCK" (cdr (assoc 2 (entget ent)))))
         (while (setq nxt (entnext nxt))
           (entmod (append (entget nxt) '((62 . 1))))
         )
       )
       (command "_.REGEN")
  )
  (princ)
)

 

Like, Share and subscribe. :D 

  • Like 2
Link to comment
Share on other sites

 

10 hours ago, Tharwat said:

Here you go.

(defun c:Test (/ int sel ent nxt)
  ;; Tharwat Al Choufi.	- Date: 27.Jun.2022		;;
  ;; website: https://autolispprograms.wordpress.com	;;
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (setq nxt (tblobjname "BLOCK" (cdr (assoc 2 (entget ent)))))
         (while (setq nxt (entnext nxt))
           (entmod (append (entget nxt) '((62 . 1))))
         )
       )
       (command "_.REGEN")
  )
  (princ)
)

 

Like, Share and subscribe. :D 

Thanks, Tharwat!

Lisp has actually changed it to red, but when i moved it to another location, the red color was lost.

Can you change its properties?

  • Thanks 1
Link to comment
Share on other sites

Tharwat to the rescue, he'll get you back on the tracks. 

Is this something to be done ONLY to selected dimensions, or across the board to all dimensions in the drawing?

  • Like 1
Link to comment
Share on other sites

8 hours ago, TINDANG said:

 

Thanks, Tharwat!

Lisp has actually changed it to red, but when i moved it to another location, the red color was lost.

Can you change its properties?

Here is another way to change colours of selected dimensions and they won't be reverted back to original colours even if you carry / copy them to another DWG or layout ... etc.

(defun c:Test (/ int sel ent obj)
  ;; Tharwat Al Choufi.	- Date: 28.Jun.2022		;;
  ;; website: https://autolispprograms.wordpress.com	;;
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (setq obj (vlax-ename->vla-object ent))
         (mapcar '(lambda (f) ((eval f) obj 1))
                 '(vla-put-TextColor vla-put-ExtensionLineColor vla-put-DimensionLineColor)
                 )
       )
  )
  (princ)
)

 

 

 

 

Link to comment
Share on other sites

23 hours ago, Tharwat said:

Here is another way to change colours of selected dimensions and they won't be reverted back to original colours even if you carry / copy them to another DWG or layout ... etc.

(defun c:Test (/ int sel ent obj)
  ;; Tharwat Al Choufi.	- Date: 28.Jun.2022		;;
  ;; website: https://autolispprograms.wordpress.com	;;
  (and (setq int -1 sel (ssget '((0 . "*DIMENSION"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (setq obj (vlax-ename->vla-object ent))
         (mapcar '(lambda (f) ((eval f) obj 1))
                 '(vla-put-TextColor vla-put-ExtensionLineColor vla-put-DimensionLineColor)
                 )
       )
  )
  (princ)
)

 

 

 

 

Great! Thanks, it worked fine.👌👌👌
I have 1 more question. If i want to change more dim line lineweight, how do i do it? (eg dim line lineweight = 0.1)

Screenshot 2022-07-29 165722.jpg

  • Like 1
Link to comment
Share on other sites

2 hours ago, TINDANG said:

Great! Thanks, it worked fine.👌👌👌
I have 1 more question. If i want to change more dim line lineweight, how do i do it? (eg dim line lineweight = 0.1)

 

Put inside the while statement before or after the mapcar.

 

(vla-put-dimensionlineweight obj 0.1)

 

  • Like 1
Link to comment
Share on other sites

On 7/29/2022 at 7:38 PM, mhupp said:

 

Put inside the while statement before or after the mapcar.

 

(vla-put-dimensionlineweight obj 0.1)

 

I put it in . but the result is 0.00. is there something wrong?

(defun c:Test (/ int sel ent obj)
  ;; Tharwat Al Choufi.	- Date: 28.Jun.2022		;;
  ;; website: https://autolispprograms.wordpress.com	;;
  (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-dimensionlineweight obj 0.1)         
	 (mapcar '(lambda (f) ((eval f) obj 1))
                 '(vla-put-TextColor vla-put-ExtensionLineColor vla-put-DimensionLineColor)
                 )
       )
  )
  (princ)
)

Screenshot 2022-08-05 120338.jpg

Edited by TINDANG
insert code
Link to comment
Share on other sites

Seems to be a factor of 10 I don't have 0.1 so it gave an error

image.png.29601c6c58ccff8c75555589d0f7a52a.png

 

But this code set it to 0.13

(defun c:Test (/ int sel ent obj)
  ;; Tharwat Al Choufi.	- Date: 28.Jun.2022		;;
  ;; website: https://autolispprograms.wordpress.com	;;
  (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-dimensionlineweight obj 13)
      (mapcar '(lambda (f) ((eval f) obj 1))
              '(vla-put-TextColor vla-put-ExtensionLineColor vla-put-DimensionLineColor)
      )
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

I was gonna say, if you were just changing its colour (a general property), recording a macro would be the easier option without any need of LISP coding. Dimension line weight falls outside of general properties, so it looks like you need some coding. What mhupp put up there should work just fine. If anything, just use (ssget "_:L" '((0 . "*DIMENSION"))), otherwise the command will fail when dimensions in a locked layer happens to be accidentally selected.

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

 Share

×
×
  • Create New...