TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TimSpangler on July 06, 2006, 01:10:02 PM
-
Hey guys/ gals,
just dropped by for a quick second. 'been racking my brain triing ro find a way to check for a linetype. In other words, if I try to load a linetype that doesn't exsist I get an error. How can I trap that error?
Thanks all
-
Not exactly what you want but perhaps this (http://www.theswamp.org/index.php?topic=10018.msg128299#msg128299) post will help.
-
This should work for you.
(vl-catch-all-apply 'vla-Load
(list
(vla-get-Linetypes
(vla-get-ActiveDocument
(vlax-get-Acad-Object)
)
)
"Testing"
)
)
-
Thanks for the quick response. I couldn't seem te get the exact result fom you examples but I pushed on and came up with this dirty bird:
(defun CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine Result)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(TGS:Stringtolist CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
Not the prettiest but it seems to work.
There is a string to list sub that isn't included so if anyone wants to test and needs the sub just let me know.
Thanks again,
That is why I love this place.
-
Tim..
What happen when your linetype isn't in the LIN file...but it is in your dwg file ?
What happen if isn't in your current LIN file...but it is in anothe LIN file ?
:?
maybe you should combine your routine with
(ai_table "LTYPE" 0)
or maybe put all your LIN file location in list and than check for each LIN file in this list..
suggestion.. :wink:
-
Tim..
What happen when your linetype isn't in the LIN file...but it is in your dwg file ?
What happen if isn't in your current LIN file...but it is in anothe LIN file ?
:?
maybe you should combine your routine with
(ai_table "LTYPE" 0)
or maybe put all your LIN file location in list and than check for each LIN file in this list..
suggestion.. :wink:
Good points. I don't use too many special linetypes, only ones supplied by Acad, or my Helpdesk people, so I don't really have to worry about this.
-
Good points indeed.
I first check the drawing to see if the supplied LT is in there. If it isn't I then check the acad.lin file. All of the variable are supplied by a macro with the exception of the .lin file. Like Tim said we only use what is supplied by autodesk. If we find a need for a special one we just add it to the .lin file.
This is part of a Quick hatching menu that we use here.
To give a little background:
I started this job about 3-4 mo. ago. They use ADT'06. They have a custom pulldown with quick hatching in it, like foundations, walls, etc. Well they change the system variable and change layers but never reset anything (they were doing it with macros) So I decided to take it upon my self to "fix" some of the issues, so i created a hatching program (I will post it tom. for all to see).This is part of the checking.
Thanks again for the suggestions. Keep them coming, it will only make it more robust.
Tim
-
My version: :-)
;; CAB 07/06/2006
(defun checkfile_linetype (linfile linetype / openfile currentline result)
(setq linetype (strcat "*" (strcase linetype)))
(and
(setq linfile (findfile linfile))
(setq openfile (open linfile "r"))
(while
(and (setq currentline (read-line openfile))
(not ; any failure, stay in loop
(and
(zerop (vl-string-search linetype (strcase currentline)))
(setq result t)
)
)
)
)
)
(and openfile (close openfile))
result
)
-
Returns the first file where the Linetype is found.
(defun c:test()
(setq lt "footsteps"
files '("acad.lin" "CAB.lin" "acasiso.lin"))
(vl-some '(lambda(x) (if (checkfile_linetype x lt) x)) files)
)
Command: test
"CAB.lin"
-
CAB,
as usual you da' man that is nice (I just checked it out his morning).
<going away to see if I can brak it :o)~ >
-
Returns the first file where the Linetype is found.
(defun c:test()
(setq lt "footsteps"
files '("acad.lin" "CAB.lin" "acasiso.lin"))
(vl-some '(lambda(x) (if (check_linetype x lt) x)) files)
)
Command: test
"CAB.lin"
Alan
Just a quick look..
(vl-some '(lambda(x) (if (checkfile_linetype x lt) x)) files)
still get
; error: bad argument type: numberp: nil
Gary
-
Thanks Gary, fixed the code.
I changed the name after I tested it. :-(