TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Peter2 on October 27, 2014, 06:05:03 PM

Title: How to get entire texstyle info via DBX?
Post by: Peter2 on October 27, 2014, 06:05:03 PM
Hi

in this thread Kerry showed some examples to get drawing info via DBX:
http://www.theswamp.org/index.php?topic=45935.msg510750#msg510750

The code
Code: [Select]
(defun kdub:listtextstyles ()
    (kdub:listcollmbrnames (vla-get-textstyles kglobal:activedoc))
)
returns the names of the existing textstyles ("Standard", "Bold", "Thin",..), but I need the used fonts (isocp.shx, simplex.shx, arial.ttf) too.

Any ideas how to get them?

Thanks

Peter

Title: Re: How to get entire texstyle info via DBX?
Post by: Lee Mac on October 27, 2014, 06:26:37 PM
Here's a quick example:
Code - Auto/Visual Lisp: [Select]
  1. (defun textstylefonts ( doc / rtn )
  2.     (vlax-for sty (vla-get-textstyles doc)
  3.         (setq rtn (cons (cons (vla-get-name sty) (vla-get-fontfile sty)) rtn))
  4.     )
  5.     (reverse rtn)
  6. )

Call with the Document object you wish to query:
Code - Auto/Visual Lisp: [Select]

You can use vlax-dump-object with a Textstyle object to view all available properties & methods.
Title: Re: How to get entire texstyle info via DBX?
Post by: Peter2 on October 27, 2014, 06:38:49 PM
Hi Lee

thanks a lot.

In the meantime I found a similar solution from the year 2006:
http://www.theswamp.org/index.php?topic=8587.msg109725#msg109725 (http://www.theswamp.org/index.php?topic=8587.msg109725#msg109725)

Regards

Peter
Title: Re: How to get entire texstyle info via DBX?
Post by: MP on October 27, 2014, 07:26:47 PM
Quick and dirty start point:

Code: [Select]
(defun _GetTextStyles ( doc dxf_flag / @Try @GetStylePropsAX @GetStylePropsDXF @Main )

    (defun @Try ( try_statement / try_result )
        (vl-catch-all-apply
            (function
                (lambda ( )
                    (setq try_result (eval try_statement))
                )
            )
        )
        try_result                       
    )
   
    (defun @GetStylePropsAX ( style )   
        (mapcar
            (function (lambda (p) (cons p (@Try '(vlax-get style p)))))
           '(   Name
                BigFontFile
                FontFile
                Height
                LastHeight
                ObliqueAngle
                TextGenerationFlag
                Width
            )   
        )
    )
   
    (defun @GetStylePropsDXF ( style )   
        (@Try
           '(vl-remove-if
                (function
                    (lambda ( p / key )
                        (or
                            (minusp (setq key (car p)))
                            (< 70 key)
                            (member key '(5))
                        )
                    )
                )
                (entget
                    (vlax-vla-object->ename style)
                )
            )       
        )   
    )
   
    (defun @Main ( doc dxf_flag / func result )
        (vl-load-com)
        (setq func (if dxf_flag @GetStylePropsDXF @GetStylePropsAX))
        (@Try
           '(vlax-for style (vla-get-textstyles doc)
                (setq result
                    (cons
                        (func style)
                        result
                    )
                )
            )
        )
        (reverse result)
    )
   
    (@Main doc dxf_flag)
   
)

Result (_GetTextStyles doc nil):

(
    (
        (NAME . "STANDARD")
        (BIGFONTFILE . "")
        (FONTFILE . "txt")
        (HEIGHT . 0.0)
        (LASTHEIGHT . 0.2)
        (OBLIQUEANGLE . 0.0)
        (TEXTGENERATIONFLAG . 0)
        (WIDTH . 1.0)
    )
    (
        (NAME . "SOME_MODEL|Standard")
        (BIGFONTFILE . "")
        (FONTFILE . "romans.shx")
        (HEIGHT . 0.0)
        (LASTHEIGHT . 2.5)
        (OBLIQUEANGLE . 0.0)
        (TEXTGENERATIONFLAG . 0)
        (WIDTH . 1.0)
    )
    ...
)


Result (_GetTextStyles doc T):

(
    (
        (0 . "STYLE")
        (2 . "STANDARD")
        (70 . 0)
        (40 . 0.0)
        (41 . 1.0)
        (50 . 0.0)
        (42 . 0.2)
        (3 . "txt")
        (4 . "")
    )
    (
        (0 . "STYLE")
        (2 . "SOME_MODEL|Standard")
        (70 . 48)
        (40 . 0.0)
        (41 . 1.0)
        (50 . 0.0)
        (42 . 2.5)
        (3 . "romans.shx")
        (4 . "")
    )
    ...
)
Title: Re: How to get entire texstyle info via DBX?
Post by: Lee Mac on October 27, 2014, 07:46:55 PM
Great to see you posting code again MP :-)
Title: Re: How to get entire texstyle info via DBX?
Post by: Peter2 on October 27, 2014, 07:57:54 PM
Thanks to MP too.

This posting will go to my archive.

Peter
Title: Re: How to get entire texstyle info via DBX?
Post by: MP on October 27, 2014, 09:01:45 PM
Thanks for the kind feedback guys. Wish I had time for more than the occasional 5 minute quick and dirty post. The good news is I'm so busy time is flying at break neck speed -- can't believe I've been with my employer over a year already -- feels like I started here just a couple months ago. :wack:
Title: Re: How to get entire texstyle info via DBX?
Post by: alanjt on October 28, 2014, 05:51:47 PM
I swear, looking at MP's code is like walking through a fine art gallery.
Title: Re: How to get entire texstyle info via DBX?
Post by: Kerry on October 28, 2014, 05:57:48 PM
I swear, looking at MP's code is like walking through a fine art gallery.

True, but it's a bit more functional than an old Rubins.
(http://clicks.robertgenn.com/images/artists/peter-paul_rubins/011607_peter-paul-rubins.jpg)
Title: Re: How to get entire texstyle info via DBX?
Post by: alanjt on October 28, 2014, 06:01:25 PM
I swear, looking at MP's code is like walking through a fine art gallery.

True, but it's a bit more functional than an old Rubins.
More like....
http://www.angelfire.com/hiphop/diablo4u/remedios.html (http://www.angelfire.com/hiphop/diablo4u/remedios.html)
 :-P
Title: Re: How to get entire texstyle info via DBX?
Post by: MP on October 28, 2014, 06:49:26 PM
lol, in before macabre Hieronymus Bosch references :-D
Title: Re: How to get entire texstyle info via DBX?
Post by: Peter2 on October 29, 2014, 07:15:12 PM
Code: [Select]
(defun @GetStylePropsAX ( style ) ...
Do I understand it right that the ActiveX-method does not return the group-code 70 (Shape, vertical, external, ..)?

Peter
Title: Re: How to get entire texstyle info via DBX?
Post by: MP on October 29, 2014, 07:26:54 PM
Bit flag states encoded in the 70 dxf group find residence in the TextGenerationFlag property.
Title: Re: How to get entire texstyle info via DBX?
Post by: Peter2 on October 29, 2014, 07:30:34 PM
OK, thanks  :-)

Peter
Title: Re: How to get entire texstyle info via DBX?
Post by: MP on October 29, 2014, 07:47:24 PM
You're most welcome Peter.