Author Topic: How do I get a tablestyle object from activedocument?  (Read 1725 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
How do I get a tablestyle object from activedocument?
« on: December 20, 2007, 10:13:30 AM »
The Acad 2008 help file says that the tablestyle object is contained in the document object.  However, there is nothing under the document object about tablestyles.  How do I get a tablestyle from the document object?

Thanks,
Mike Weaver

Marco Jacinto

  • Newt
  • Posts: 47
Re: How do I get a tablestyle object from activedocument?
« Reply #1 on: December 20, 2007, 10:59:09 AM »
Try looking in the dictionaries collection, look for  "acad_tablestyle".

Saludos

Marco Jacinto

mkweaver

  • Bull Frog
  • Posts: 352
Re: How do I get a tablestyle object from activedocument?
« Reply #2 on: December 20, 2007, 11:14:20 AM »
Found it.  Here's a quick routine to get a table style if it exists, or create a new one if it doesn't exist

Suggestions welcome:

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Routine: GetOrCreateTableStyle ;;;
;;;  Purpose: Create or retrieve a tablestyle object - specific to Acad 2008, may have to be ;;;
;;; modified for later versions of acad. ;;;
;;;  Arguments: Doc - document object ;;;
;;; StyleName - string, the name of the tablestyle ;;;
;;;  Returns: IAcadTableStyle2 for the specified stylename ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetOrCreateTableStyle (doc StyleName / dict newstyle stylecount stylelist tablestyle tablestyles)
  (setq
    doc (if doc doc (vla-get-activedocument(vlax-get-acad-object)))
    dict (vla-get-dictionaries doc)
    tablestyles (vla-item dict "acad_tablestyle")
    StyleCount (vla-get-count tablestyle)
    )
  (vlax-for TableStyle TableStyles
    (setq StyleList (cons (cons (vla-get-name TableStyle) TableStyle) StyleList))
    )
  (if (assoc StyleName StyleList)
    (cdr (assoc StyleName StyleList))
    (progn
      (setq
NewStyle (vla-addobject tablestyles StyleName "AcDbTableStyle")
)
      (vla-put-name NewStyle StyleName)
      NewStyle
      )
    )
  )

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How do I get a tablestyle object from activedocument?
« Reply #3 on: December 20, 2007, 12:26:29 PM »
There is a mis-typing here
Code: [Select]
    StyleCount (vla-get-count tablestyle)
Forgot the 's' on tablestyles

Why not just see if the style exists in the dictionary, and if not create?  Like

Code: [Select]
(if
(vl-catch-all-error-p
(setq StyleObject
(vl-catch-all-apply
'vla-Item
(list
tablesstyles
StyleName
)
)
)
)
(progn
(setq StyleObject (vla-AddObject tablestyles StyleName "AcDbTableStyle"))
(vla-put-Name StyleObject StyleName)
)
)
Then just return StyleObject
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.