Jump to content

Text style and layer routine


CAD89

Recommended Posts

Is there any way to make a lisp routine that can append all layers and styles of text existent in a drawing to a list?!

I.E.: I have a drawing that has 5 different layers (let's say "0" "Dimensions" "Lines" "Text" and "Paper space"), and I want to make a lisp that searches through the dwg and appends the layers to a list ... is that possible?

And

I have about 3 text styles ("Standard" "Title" and "Date") and an empty list! How do I get my routine to find the text styles and store them into the empty list?

 

Or it would be much better if I could make a list box containing all available fonts just to select one of them!

 

Thanks in advance!

With regards Csaba Arpad Dobai!

Link to comment
Share on other sites

Solved the layer problem:

 

(defun pad:ll ()
 (setq la (cdr (assoc 2 (tblnext "Layer" T))))
 (setq lal (list la))
 (while (/= (setq la (cdr (assoc 2 (tblnext "Layer")))) nil)
   (setq lal (append	lal (list la))
   )
 )
)

 

I think it works the same with the text styles!

 

Still need help with the fonts though!

Link to comment
Share on other sites

(defun _List (typ / lst)
 (while (setq e (tblnext typ (null e))) (setq lst (cons (cdr (assoc 2 e)) lst)))
 lst
)

 

usage ...

With Layers ...

 

(_List "Layer")

 

usage ...

With Text Styles ...

 

(_List "Style")

  • Like 1
Link to comment
Share on other sites

Thank you for your help!

 

You're welcome .

 

Any idea about the fonts list? I would need something like in the text style dialog box! Is it possible?

 

Do you mean to list all the fonts that are used in the text styles list ?

Link to comment
Share on other sites

Yes! Is that in any way possible?

 

Updated the layer code:

(defun pad:ll ()
 (setq la (cdr (assoc 2 (tblnext "Layer" T))))
 (setq lal (list la))
 (while (/= (setq la (cdr (assoc 2 (tblnext "Layer")))) nil)
   (setq lal (append lal (list la))
   )
 )
 (if (= lal (list nil))
   (setq lal (list (cdr (assoc 2 (tblnext "Layer" T)))))
   (setq lal (append lal (list "Use current" "Make new ...")))
 )
)

 

... for some reason the code gave me a nil list if there was only one layer so I updated and added two more items that I will need later on!

 

Thank you for your time Tharwat!

Link to comment
Share on other sites

I'm sorry but the code you wrote will return a list of only the fonts that are currently set or assigned to existent text styles and not a font list of every font that AutoCAD has in it's fonts library!

Link to comment
Share on other sites

I'm sorry but the code you wrote will return a list of only the fonts that are currently set or assigned to existent text styles and not a font list of every font that AutoCAD has in it's fonts library!

 

That's why I asked you before as you can see below ..

 

Do you mean to list all the fonts that are used in the text styles list ?

 

Anyway here is a routine to list all your shx fonts from the FONTS folder but

don't forget to change the path according to yours .

 

(defun _List-Fonts nil
 (foreach shx (vl-directory-files "C:\\Program Files\\Autodesk\\AutoCAD 2013\\Fonts" "*.shx" 1)
   (print shx)
 )
)

Link to comment
Share on other sites

Perhaps something like:

 

([color=BLUE]defun[/color] _getfontlist ( [color=BLUE]/[/color] _parsepaths )

   ([color=BLUE]defun[/color] _parsepaths ( s [color=BLUE]/[/color] p )
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] p ([color=BLUE]vl-string-position[/color] 59 s))
           ([color=BLUE]vl-remove[/color] [color=MAROON]""[/color] ([color=BLUE]cons[/color] ([color=BLUE]substr[/color] s 1 p) (_parsepaths ([color=BLUE]substr[/color] s ([color=BLUE]+[/color] p 2)))))
           ([color=BLUE]list[/color] s)
       )
   )

   ([color=BLUE]vl-sort[/color]
       ([color=BLUE]apply[/color] '[color=BLUE]append[/color]
           ([color=BLUE]cons[/color] ([color=BLUE]vl-directory-files[/color] (LM:SpecialFolder [color=MAROON]"Fonts"[/color]) [color=MAROON]"*.ttf"[/color] 1)
               ([color=BLUE]mapcar[/color]
                   ([color=BLUE]function[/color]
                       ([color=BLUE]lambda[/color] ( p ) ([color=BLUE]vl-directory-files[/color] p [color=MAROON]"*.shx"[/color] 1))
                   )
                   (_parsepaths ([color=BLUE]getenv[/color] [color=MAROON]"ACAD"[/color]))
               )
           )
       )
       '[color=BLUE]<[/color]
   )
)

[color=GREEN];; Special Folder  -  Lee Mac[/color]
[color=GREEN];; Queries the WshSpecialFolders collection for the specified folder[/color]
[color=GREEN];; Ref: http://msdn.microsoft.com/en-us/library/9x9e7edx%28v=vs.85%29.aspx[/color]

([color=BLUE]defun[/color] LM:SpecialFolder ( folder [color=BLUE]/[/color] res spf wsh )
   ([color=BLUE]setq[/color] res
       ([color=BLUE]vl-catch-all-apply[/color]
           ([color=BLUE]function[/color]
               ([color=BLUE]lambda[/color] ( )
                   ([color=BLUE]setq[/color] wsh ([color=BLUE]vlax-get-or-create-object[/color] [color=MAROON]"wscript.shell"[/color])
                         spf ([color=BLUE]vlax-get-property[/color] wsh 'specialfolders)
                   )
                   ([color=BLUE]vlax-invoke-method[/color] spf 'item folder)
               )
           )
       )
   )
   ([color=BLUE]if[/color] spf  ([color=BLUE]vlax-release-object[/color]  spf))
   ([color=BLUE]if[/color] wsh  ([color=BLUE]vlax-release-object[/color]  wsh))
   ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] res))
       res
   )
)

 

(untested code)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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