Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use Lisp to test for Text Style

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
2034 Views, 11 Replies

Use Lisp to test for Text Style

Using AutoLISP, I want to test to see if the Text style "romans" exists in the drawing, and if not, create it. I know how to create the style, I am having trouble figuring out how to test for the style and if the text fails, create it. Any help would be appreciated.
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

(while (setq Style (tblnext "style" (null Style))) (if (= "ROMANS.SHX" (strcase (cdr (assoc 3 Style)))) (setq Romans (cdr (assoc 2 Style))) );end if );end while (if (not Romans (CreateTxtStyle "Romans" "Romans.shx" 0.0 1.0)) where: (defun CreateTxtStyle (Name File Height Width) (entmake (list '(0 . "STYLE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbTextStyleTableRecord") (cons 2 Name) (cons 3 File) '(70 . 0) '(71 . 0) (cons 40 Height) (cons 41 Width))) );end CreateTxtStyle
Message 3 of 12
Anonymous
in reply to: Anonymous

(if (not (tblsearch "style" "romans")) (progn ;create it here, it doesn't exist ) ) -- Jeff check out www.cadvault.com "dcouch" wrote in message news:32223267.1100131610726.JavaMail.jive@jiveforum2.autodesk.com... > Using AutoLISP, I want to test to see if the Text style "romans" exists in > the drawing, and if not, create it. I know how to create the style, I am > having trouble figuring out how to test for the style and if the text > fails, create it. Any help would be appreciated.
Message 4 of 12
Anonymous
in reply to: Anonymous

I use this to check for romand text style and if it exists check the height. If the height is not set to 0.0 recreate ir, or it does not exist create it.
Substitute romans for romand.
Hope this will help you.

(setq NEWTXTSTY (tblsearch "style" "romand"))
(if
(or
(= NIL NEWTXTSTY)
(/= (cdr (assoc 40 NEWTXTSTY)) 0.0)
) ;_ end of cond
;CREATE ROMAND IF NEEDED
(command "style" "romand" "romand" 0.0 1.0 0.0 "n" "n" "n")
) ;_ end of if
Message 5 of 12
Anonymous
in reply to: Anonymous

You don't need to test for it. You can simply create it, even if it already exists. After you enter a style name, it says either "New style" or "Existing style", but there's no "Do you want to replace..." prompt to account for, or anything. The only reason I can think of that you might NOT want to do that is if the existing style with that name might have characteristics (like an assigned height) that are different from what you would assign, and if you want to keep that style definition for some reason (e.g. because of existing text). -- Kent Cooper, AIA "dcouch" wrote... > Using AutoLISP, I want to test to see if the Text style "romans" exists in > the drawing, and if not, create it. I know how to create the style, I am > having trouble figuring out how to test for the style and if the text > fails, create it. Any help would be appreciated.
Message 6 of 12
Anonymous
in reply to: Anonymous

That code's excessively wordy. You could accomplish the same logic with: (if (and (setq NEWTXTSTY (tblsearch "style" "romand")) (not (zerop (cdr (assoc 40 NEWTXTSTY))))) (command "style" "romand" "romand" 0.0 1.0 0.0 "n" "n" "n")) However, as Kent noted, none of this testing is necessary at all. If you want to always set the style's height to 0, you can accomplish exactly the same thing with simply: (command "style" "romand" "romand" 0.0 1.0 0.0 "n" "n" "n")
Message 7 of 12
Anonymous
in reply to: Anonymous

One of my first stabs at writing lisp. Still need a lot of help, and am happy to get your comments. Next time I will know a little better.
BTW Logic is not my strong suite.

Thanks Tom
Ed Cable
Message 8 of 12
scot-65
in reply to: Anonymous

This is the method that is the most efficient!

Scot-65

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 9 of 12
Anonymous
in reply to: Anonymous

> This is the method that is the most efficient! Wrong, you didn't read the whole thread. Kent explained why it's unnecessary in this case to do any "if" test at all. Just make the style the way you want it, whether it already exists or not.
Message 10 of 12
scot-65
in reply to: Anonymous

Tom,

(if (desired textstyle)
(set textstyle as current)
(create textstyle)
);endIF

Now, lets have a closer look at this efficiency...

Program Writing Design Guidelines:
1) Do an internal search of the font style before going to exterior sources.
2) When no style is internally found, the support path is automatically used
in conjunction with the style command.

Please note the following conditions may be true:
a) Font file desired is not in support path.
b) When user input, font may be misspelled (create a list of choices instead).

Now we have to protect the program from crashing due to the possible errors shown above.
Employ FINDFILE first, to see if file exists, before starting the style command.
Create a prompt or alert message when the font file does not exist in the support path.

======================================

Now, to create a realistic environment, the following has been simplified for this example:
a) We have Five major divisions in our symbol library.
Each folder is declared in the support path and each folder contains 100 files.
b) We also have a "SHX" font folder with over 150 files.
c) We also have a "True Type Font" folder with over 500 files.
d) Other standard support path items can be summed up to around 50 files.


The threads you mention will have to browse some 1200 external files each time this font is called forward.


Now may I ask you what geometry is the most efficient?

======================================

The successful creation of this macro will not require an error handler.
Since no error handler, place macro in the "MNL" file.

======================================

My environment can instantly toggle between Drawing Scales while remaining in the same file!
We can have up to three unique drawing scales, which requires a minimum of four settings
to align for each drawing scale. One of these is the TEXTSTYLE switch.

The base drawing scale can be set to a minimum of 5 unique (permanent) drawing scales.
The other two unique drawing scales have 5 choices also.
This equals 125 possible combinations of drawing scales available in one drawing file!

Publishing the document will yield consistent text heights regardless of scale.

Scot-6
Message was edited by: Scot-65

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 11 of 12
Anonymous
in reply to: Anonymous

That would work, and it's literally what the OP asked for, but I still think that the test is unnecessary, per Kent's comments. The OP didn't address the scenario of what if the style exists but it isn't defined the way it should be? In that case, I assume it should be corrected AND set current. If you just go ahead and create the style as desired, regardless of whether that name already exists, it will always be correct and set current.
Message 12 of 12
scot-65
in reply to: Anonymous

Tom,

We are getting close.
The original poster' wanted hints as he himself has little expierence with LISP.
I did not originally want to go into detail any more than necessary.
Nobody is wrong here.

=====================

We have over 3000 archived documents available to our customers.
Many of them generated in R12 and R14.
Many of them drawn by hand.

Before I overhauled the menu system, the standard text was set to a height of 4-1/2 inches. The new standard we now use is 4 inches (modelspace). We do not employ the variable TEXTHEIGHT. Therefore, all of our styles are declared with a fixed height greater than zero (0). Oh, the beauty of many items to customize...

The macro has accounted for this new setting to a previous file that will now be released to the new customer. Not only does this macro test for an existing declared textstyle, it will also check the declared height. If one or the other does not pass, reload style.

When was the last time you waited for the mouse box to appear after typing STYLE? It has not changed since R13 (TTF files).

When was the last time your associates loaded a textstyle with the wrong height (relative to drawing scale)?


Scot-65

---------------------------

DCouch here is the code ("H1" is our regular text):

(if (and (tblsearch "style" c)
(= (rtos (cdr (assoc 40 (tblsearch "style" c))) 2 2) d) )
(setvar "textstyle" c)
(progn
(if (findfile "H1.shx")
(setq e "H1.shx")
(progn
(setq e "txt.shx")
(alert (strcat
"The font file called \"H1.shx\" is not in your support path."
"\nA default font file will be used instead.")) );progn
);if
(setvar "cmdecho" 0)(command ".style" c e d "" "" "" "")
(setvar "cmdecho" 1)(princ (strcat "\n" c " textstyle loaded. ")) );progn
);if

Where "c" and "d" is passed to this menu function as the style with desired height (chosen from a list).


See my above post for hints of other switches to set when changing drawing scales within a file (also incorporated in this same menu function macro).

If your environment declares text styles with a height of 0, do Kent's method (ensure a routine accounts for the desired height without the User entering a value).

[see if ya'll can find the bug I purposely designed into this routine]

It is only fair to give back to this fourm as much as it is to extract.


Scot-65

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost