Jump to content

Recommended Posts

Posted

Hello all,

 

 

Trying to do a simple thing here but I can't figure it out. I'm trying to change the default text color of all tables in a drawing to black. I can do it by selecting each table, going to properties, and changing the Color property at the top of the list to black (as in attached picture where it's ByLayer), but I am trying to do this in autolisp

 

 

(vlax-for
  tablestyle 
  (vla-item (vla-get-Dictionaries (vla-get-ActiveDocument (vlax-get-acad-object))) "acad_tablestyle") 
  (vlax-put-property tablestyle 'Color 0 0 0) 
)

 

 

Above was me taking a stab at it by changing the tablestyles (seemed easier than going through each table), but after playing with it for a couple hours, I still couldn't get anywhere. Can anyone point me in the right direction?

screenshot.jpg

Posted

If I got you right , if you are trying to change the color of a number of tables that are already existed in a drawing , just make a global selection set and iterate through each table object then change the color with the function vla-put-color with your desired color .

 

HTH.

Posted

I thought it would be easier to change the styles, but you're right - cycling through a selection set is much easier. Thanks for the idea! :)

 

 

solution for anyone interested:

 

 

(vl-load-com)
(if (setq sset (ssget "X" '((0 . "ACAD_TABLE")))) 
  (progn
     (setq ctr 0)
     (repeat (sslength sset)
        (setq item (ssname sset ctr))
        (setq item (vlax-ename->vla-object item))
        (setq check (vlax-property-available-p item "Color" T))
        (if check
           (vlax-put-property item 'Color 0)
        )
        (setq ctr (1+ ctr))
     )
  )
(princ)
)

Posted

Have a close look at this .

 

(defun c:Test (/ ss i vl)
 (if (setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))
   (repeat (setq i (sslength ss))
     (if (vlax-write-enabled-p (setq vl (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
       (vla-put-color vl 0)
     )
   )
 )
 (princ)
)(vl-load-com)

Posted

Looks the same as what I posted except for the check to see whether the block is write-enabled. I don't expect blocks to be protected, but I suppose it's always better to check.

 

 

One thing I noticed was that this will not work for tables that are inside of blocks :/ Hopefully that will not happen though

Posted
Looks the same as what I posted except for the check to see whether the block is write-enabled. I don't expect blocks to be protected, but I suppose it's always better to check.

 

One thing I noticed was that this will not work for tables that are inside of blocks :/ Hopefully that will not happen though

 

Try this routine and read the comments at the top of the routine for more information .

 

(defun c:Test (/ doc ss i vl)
 ;;    Tharwat 08.July.2014        ;;
 ;; Function to change the color of     ;;
 ;; AutoCAD Tables in all layouts and     ;;
 ;; Blocks as well .            ;;
 ;;    -----------------------------    ;;
 ;; Tables on LOCKED layers should     ;;
 ;; be ignored             ;;
 (defun *error* (msg)
   (and doc (vla-endundomark doc))
   (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
     (princ msg)
     (princ (strcat "\n** Error: " msg " **"))
   )
   (princ)
 )
 (vla-startUndomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
 (if (ssget "_X" '((0 . "ACAD_TABLE")))
   (progn (vlax-for tbl (setq ss (vla-get-activeselectionset doc))
            (if (vlax-write-enabled-p tbl)
              (vla-put-color tbl 0)
            )
          )
          (vla-delete ss)
   )
 )
 (vlax-for bks (vla-get-blocks doc)
   (if (and (eq :vlax-false (vla-get-isxref bks)) (eq :vlax-false (vla-get-islayout bks)))
     (vlax-for bk bks
       (if (and (eq (vla-get-objectname bk) "AcDbTable") (vlax-write-enabled-p bk))
         (vla-put-color bk 0)
       )
     )
   )
 )
 (vla-regen doc AcAllviewports)
 (vla-endundomark doc)
 (princ)
)(vl-load-com)

Posted

Makes sense; first you change all the tables, then look inside blocks and change tables there. I don't have much knowledge about the vla-get-blocks command, looks like I need to read up on it.

 

Is there any particular reason you redefined the error function or is that just standard procedure when calling a vlax command?

Posted
Makes sense; first you change all the tables, then look inside blocks and change tables there. I don't have much knowledge about the vla-get-blocks command, looks like I need to read up on it.

 

Right on .

 

Is there any particular reason you redefined the error function or is that just standard procedure when calling a vlax command?

 

A very good question .

 

Actually I added the error function to get sure that if any error took a place , so the error function should end the start undo mark that is already started .

Posted
Try this routine and read the comments at the top of the routine for more information .

 

(defun c:Test (/ doc ss i vl)
 ;;    Tharwat 08.July.2014        ;;
 ;; Function to change the color of     ;;
 ;; AutoCAD Tables in all layouts and     ;;
 ;; Blocks as well .            ;;
 ;;    -----------------------------    ;;
 ;; Tables on LOCKED layers should     ;;
 ;; be ignored             ;;
 (defun *error* (msg)
   (and doc (vla-endundomark doc))
   (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
     (princ msg)
     (princ (strcat "\n** Error: " msg " **"))
   )
   (princ)
 )
 (vla-startUndomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
 (if (ssget "_X" '((0 . "ACAD_TABLE")))
   (progn (vlax-for tbl (setq ss (vla-get-activeselectionset doc))
            (if (vlax-write-enabled-p tbl)
              (vla-put-color tbl 0)
            )
          )
          (vla-delete ss)
   )
 )
 (vlax-for bks (vla-get-blocks doc)
   (if (and (eq :vlax-false (vla-get-isxref bks)) (eq :vlax-false (vla-get-islayout bks)))
     (vlax-for bk bks
       (if (and (eq (vla-get-objectname bk) "AcDbTable") (vlax-write-enabled-p bk))
         (vla-put-color bk 0)
       )
     )
   )
 )
 (vla-regen doc AcAllviewports)
 (vla-endundomark doc)
 (princ)
)(vl-load-com)

 

Since the Modelspace & Paperspace blocks are contained in the Block Collection of the document, there is no need to separately retrieve & iterate over a selection set of non-nested tables:

(defun c:tabcol ( / d )
   (vlax-for b (vla-get-blocks (setq d (vla-get-activedocument (vlax-get-acad-object))))
       (if (= :vlax-false (vla-get-isxref b))
           (vlax-for o b
               (if (and (= "AcDbTable" (vla-get-objectname o)) (vlax-write-enabled-p o))
                   (vla-put-color o 250)
               )
           )
       )
   )
   (vla-regen d acallviewports)
   (princ)
)
(vl-load-com) (princ)

Also note that ACI colour 0 is ByBlock, not black - for black you will need to use a True Colour.

Posted

Thank you Lee for the notes .

 

Yeah , I completely forgot about that way of iterating the Blocks collection for spaces .

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