TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TimSpangler on July 06, 2006, 01:10:02 PM

Title: Check for avalible linetypes?
Post 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
Title: Re: Check for avalible linetypes?
Post by: MP on July 06, 2006, 01:18:01 PM
Not exactly what you want but perhaps this (http://www.theswamp.org/index.php?topic=10018.msg128299#msg128299) post will help.
Title: Re: Check for avalible linetypes?
Post by: T.Willey on July 06, 2006, 01:19:29 PM
This should work for you.

Code: [Select]
(vl-catch-all-apply 'vla-Load
 (list
  (vla-get-Linetypes
   (vla-get-ActiveDocument
    (vlax-get-Acad-Object)
   )
  )
  "Testing"
 )
)
Title: Re: Check for avalible linetypes?
Post by: TimSpangler on July 06, 2006, 02:50:18 PM
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:
Code: [Select]
(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.
Title: Re: Check for avalible linetypes?
Post by: Andrea on July 06, 2006, 03:36:55 PM
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
Code: [Select]
(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:
Title: Re: Check for avalible linetypes?
Post by: T.Willey on July 06, 2006, 03:50:52 PM
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
Code: [Select]
(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.
Title: Re: Check for avalible linetypes?
Post by: TimSpangler on July 06, 2006, 04:02:49 PM
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
Title: Re: Check for avalible linetypes?
Post by: CAB on July 06, 2006, 04:35:18 PM
My version:  :-)
Code: [Select]
;;  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
)
Title: Re: Check for avalible linetypes?
Post by: CAB on July 06, 2006, 04:43:59 PM
Returns the first file where the Linetype is found.

Code: [Select]
(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"
Title: Re: Check for avalible linetypes?
Post by: TimSpangler on July 07, 2006, 07:43:23 AM
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)~ >
Title: Re: Check for avalible linetypes?
Post by: GDF on July 07, 2006, 09:27:15 AM
Returns the first file where the Linetype is found.

Code: [Select]
(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



Title: Re: Check for avalible linetypes?
Post by: CAB on July 07, 2006, 11:09:39 AM
Thanks Gary, fixed the code.
I changed the name after I tested it. :-(