Create a dimension with vla-AddDimAligned that has text fillcolor set to background

Create a dimension with vla-AddDimAligned that has text fillcolor set to background

mdolanVQYAA
Enthusiast Enthusiast
770 Views
8 Replies
Message 1 of 9

Create a dimension with vla-AddDimAligned that has text fillcolor set to background

mdolanVQYAA
Enthusiast
Enthusiast
I am creating dimensions.  I want to set the Text Fill Color to Background but I have not been able to find a way to do so. 
 
image.png
 
The code below sets the fill color to white.  I have tried everything.  I believe in .NET it is .UseBackgroundColor = true for text I have not been able to find this for LISP.  Somebody please let me know the trick to get the fill color = Background.
 
(setq dim (vla-AddDimAligned ms pt3dCrossingRw1 pt3dCrossingCL pt3dCrossingCL))
  (vla-put-Layer dim "DIM")
  (vla-put-Arrowhead1Type dim acArrowArchTick)
  (vla-put-Arrowhead2Type dim acArrowArchTick)
  ;Set text fill color to background
  (vla-put-TextFill dim :vlax-true)
  (vla-put-TextFillColor dim 7) ; this sets it to white
  (vla-Update dim)

 

0 Likes
Accepted solutions (3)
771 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Mentor
Mentor

@mdolanVQYAA 

Try TextFillColor = 0

0 Likes
Message 3 of 9

mdolanVQYAA
Enthusiast
Enthusiast

@ronjonp

That sets the fillcolor to ByLayer.  And 256 sets it to ByBlock.

The only thing I have been able to figure out is that a Dimension Style can be created and the fill color set to Background in the Dim Style.  Unfortunately, I have not been able to do this via LISP, it can only be done through the interface.

Then I can set the dimension style with this while placing the dimensions.

(vla-put-StyleName dim "MyStyle")
0 Likes
Message 4 of 9

ronjonp
Mentor
Mentor
Accepted solution

@mdolanVQYAA Oooops! Apparently it's buried in the XDATA. Give this a try: (not heavily tested)

(defun c:foo (/ n s xd)
  ;; RJP » 2025-07-17
  ;; Sets dimension textfill color to 'background'
  (cond	((setq s (ssget ":L" '((0 . "DIMENSION"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq xd (assoc -3 (entget e '("ACAD"))))
	   (setq n 0)
	   (setq xd (mapcar '(lambda (x)
			       (if (= 7 (setq n (1+ n)))
				 '(1070 . 1)
				 x
			       )
			     )
			    (cadr xd)
		    )
	   )
	   (entmod (append (entget e) (list (list -3 xd))))
	 )
	)
  )
  (princ)
)

ronjonp_0-1752771446992.png

 

 

0 Likes
Message 5 of 9

komondormrex
Mentor
Mentor

@mdolanVQYAA 

check the following out

(defun c:set_dimtext_background_fill (/ dim_dxf)
  (foreach dim (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "dimension"))))))
    (if (assoc -3 (setq dim_dxf (entget dim '("*"))))
      (setq dim_dxf (append (vl-remove (assoc -3 dim_dxf) dim_dxf) '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))))
      (setq dim_dxf (append dim_dxf '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))))
    )
    (entmod dim_dxf)
  )
  (princ)
)
0 Likes
Message 6 of 9

mdolanVQYAA
Enthusiast
Enthusiast

@komondormrex and @ronjonp


it seems you both have the same solution.  I have not messed with this XData yet but this is great t...

 

komondormrex I was able to get your version working as a standalone, but am having trouble getting it integrated into my dimension creation routine.  Below is my latest attempt to integrate it. Any help with what I am missing would be greatly appreciated.

 

(setq dim (vla-AddDimAligned ms pt3dCrossingBOC1 pt3dCrossingBore pt3dCrossingBore))
(vla-put-Layer dim "DIM")
(vla-put-Arrowhead1Type dim acArrowArchTick)
(vla-put-Arrowhead2Type dim acArrowArchTick)

(setq dimEnt (vlax-vla-object->ename dim)) ; convert vla object to ename
(setq dimDxf (entget dimEnt '("ACAD")))
          
      (setq dim_dxf (append (vl-remove (assoc -3 dim_dxf) dim_dxf) '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))))

;; Append the background fill definition
(setq dimDxf (append dimDxf '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))))
          
(entmod dimDxf)
(vla-Update dim)

 

 

0 Likes
Message 7 of 9

komondormrex
Mentor
Mentor
Accepted solution

@mdolanVQYAA

ttry it that way

(setq dim (vla-AddDimAligned ms pt3dCrossingBOC1 pt3dCrossingBore pt3dCrossingBore))
(vla-put-Layer dim "DIM")
(vla-put-Arrowhead1Type dim acArrowArchTick)
(vla-put-Arrowhead2Type dim acArrowArchTick)

(setq dim_Ent (vlax-vla-object->ename dim)) ; convert vla object to ename
(if (assoc -3 (setq dim_dxf (entget dim_Ent '("ACAD"))))
      (setq dim_dxf (append (vl-remove (assoc -3 dim_dxf) dim_dxf) '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))))
      (setq dim_dxf (append dim_dxf '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))))
)
          
(entmod dim_Dxf)
(vla-Update dim)
0 Likes
Message 8 of 9

mdolanVQYAA
Enthusiast
Enthusiast

@ronjonp

 

I am curious how you got that XData dump of the dimstyle in the image?  Seems like this is the only way to hunt that info down.

0 Likes
Message 9 of 9

ronjonp
Mentor
Mentor
Accepted solution

@mdolanVQYAA 

 

I used this to dump the data:

(defun c:dxflist (/ e)
  (cond	((setq e (car (entsel "\nPick something to see DXF data: ")))
	 (mapcar 'print (entget e '("*")))
	 (textscr)
	)
  )
  (princ)
)

Then pasted those values into the VLIDE and took a couple of screen shots to compare.

 

This gave me the idea to write a quick comparison code:

(defun c:dxfcompare (/ e e2)
  ;; RJP » 2025-07-18
  ;; Print DXF differences between two entities
  (cond	((and (setq e (car (entsel "\nPick something to see DXF data: ")))
	      (setq e2 (car (entsel "\nPick something to compare: ")))
	 )
	 (mapcar '(lambda (r j)
		    (if	(not (equal r j))
		      (print (list r j))
		    )
		  )
		 (entget e '("*"))
		 (entget e2 '("*"))
	 )
	 (textscr)
	)
  )
  (princ)
)