TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TimSpangler on November 21, 2005, 12:34:41 PM

Title: Linetype from ?.lin file
Post by: TimSpangler on November 21, 2005, 12:34:41 PM
Is there a way the tell what .lin file a loaded linetype came from?

[example]

In a drawing I have a line type called "Cable" this linetype came from "Tele.lin" file.

[/example]

Is there a way the find out that "Cable" came from "Tele.lin" file?

Clear?
Title: Re: Linetype from ?.lin file
Post by: deegeecees on November 21, 2005, 12:43:06 PM
Manually, or automated?
Title: Re: Linetype from ?.lin file
Post by: TimSpangler on November 21, 2005, 12:52:05 PM
Either way.
Title: Re: Linetype from ?.lin file
Post by: deegeecees on November 21, 2005, 01:01:55 PM
You can open .lin files with an ASCII editor as in "Notepad" and do a search, or do a search for files with the proper criteria contained within the file.

Make sense?
Title: Re: Linetype from ?.lin file
Post by: TimSpangler on November 21, 2005, 01:05:13 PM
OK.  to clearify.

If i were to export all of the layers in a dwg to a txt file, with all of there info (Color, Linetype, on, thawed, etc.) How would I know what .lin file the linetype came from?

Is there a way to get this info? DXF codes?  Xdata?  Dict?
Title: Re: Linetype from ?.lin file
Post by: LE on November 21, 2005, 01:13:57 PM
OK.  to clearify.

If i were to export all of the layers in a dwg to a txt file, with all of there info (Color, Linetype, on, thawed, etc.) How would I know what .lin file the linetype came from?

Is there a way to get this info? DXF codes?  Xdata?  Dict?

I do not think, it is going to be an easy task..... and mostly if those linetypes were defined/loaded from a custom .LIN file.

I have not tried any approach to do a similar task..... sorry.
Title: Re: Linetype from ?.lin file
Post by: TimSpangler on November 21, 2005, 01:32:34 PM
I didn't think it would be easy if at all.  The more I read the more I don't think that it is possible.  Once the definition is loaded it becomes part of the dwg until it is purged.

Thanks Luis
Title: Re: Linetype from ?.lin file
Post by: LE on November 21, 2005, 01:37:46 PM
I didn't think it would be easy if at all.  The more I read the more I don't think that it is possible.  Once the definition is loaded it becomes part of the dwg until it is purged.

Thanks Luis

 :-)

Yes.

I would simple give away the .LIN's, ask them to copy them in a support folder and let AutoCAD do the rest....
Title: Re: Linetype from ?.lin file
Post by: Sdoman on November 21, 2005, 05:58:21 PM
You can however create a new *.lin file of linetypes defined inside a particular drawing.   Paul Turvil has a routine on his web page. 

http://www.turvill.com/t2/index.htm

If I remember correctly, he also has a routine to harvest hatch patterns too.
Title: Re: Linetype from ?.lin file
Post by: Joe Burke on November 22, 2005, 04:49:52 AM
Tim,

Assuming the linetype in question came from some available .lin file and you
know what .lin files are available, something like this might work. Use the
following function to make a list of the linetypes in each .lin file. Then
search each list for the linetype name.

Uncomment the next to last line. If the linetype name is found in some list,
return (car lst).

If you don't know what .lin files are available, I suppose you could search the
support paths (getenv "ACAD") for .lin files.

Of course there's probably a number of which could go wrong. Such as duplicate
linetype names in various .lin files.

Code: [Select]
;; Based on code by Jason Piercey.
;; Argument: filename of linetype file such as "acad.lin"
;; which resides in a search path.
;; Returns: list of linetype names.
(defun GetLinetypes (filename / file line str lst)
  (setq file (open (findfile filename) "r"))
  (setq line (read-line File))
  (while line
    (if (wcmatch line "`**")
      (progn
        (setq str (substr (substr line 1 (vl-string-search "," line)) 2))
        (setq lst (cons str lst))
      )
    )
    (setq line (read-line file))
  )
  (close file)
  ;add filename
  ;(cons filename (reverse lst))
) ;end
Title: Re: Linetype from ?.lin file
Post by: TimSpangler on November 22, 2005, 07:48:45 AM
Thanks guys.

I will have to run a couple of test on the routine posted and see what kind of output i get.  Maybe I can cobble something up with it.

Thanks Again everyone.  It never seases to amaze me what comes out of this group.  You guys/ gals are amazing :mrgreen:
Title: Re: Linetype from ?.lin file
Post by: Joe Burke on November 22, 2005, 08:24:21 AM
Tim,

Hope I wasn't vague about the next to last line of code. As originally designed, the function returns (reverse lst). Which doesn't include the filename.
Title: Re: Linetype from ?.lin file
Post by: CAB on November 22, 2005, 09:00:18 AM
How about this to start with?  <Correction> To add to Joe's suggestion.


Code: [Select]
(defun c:test()  (get-line-types))

;;  CAB 11/22/2005
;;  returns a list of all linetypes found in all .lin files found
(defun get-line-types (/ path paths fname fnames fnamelist
                       ltnames lineTypeList)
 
  (defun getlinetypes (filename / file line str lst)
    (if (setq file (open (findfile filename) "r"))
      (progn
        (while (setq line (read-line file))
          (if (wcmatch line "`**")
            (setq str (substr (substr line 1 (vl-string-search "," line)) 2)
                  lst (cons str lst)
            )
          )
        )
        (close file)
      )
    )
    (reverse lst)
  )


  ;;   get a list of all ACAD paths
  ;;  removes "." ".." and needs error checking
  (setq paths (cdr (cdr (vl-directory-files nil nil -1))))

  ;;  get a list of all file names .lin
  (foreach path paths
    (if (setq fnames (vl-directory-files path "*.lin"))
      (setq fnamelist (append fnames fnamelist))
    )
  )

  (foreach fname fnamelist
    (if (setq ltnames (getlinetypes fname))
      (setq lineTypeList (append ltnames lineTypeList))
    )
  )

  (princ)
  lineTypeList
)
Title: Re: Linetype from ?.lin file
Post by: Joe Burke on November 22, 2005, 09:32:24 AM
Hmm... isn't that an an extension of what I suggested, rather than, "to start with"?
Title: Re: Linetype from ?.lin file
Post by: CAB on November 22, 2005, 09:41:41 AM
Quite so. Sorry i miss spoke. :oops:

I did take your suggestion and carry it to the next step.
What i meant was that is still not a finished routine.
Title: Re: Linetype from ?.lin file
Post by: CAB on November 22, 2005, 09:17:40 PM
And to take one more step closer.

Code: [Select]
(defun c:test ()
  (get-file-of-linetype "center")
)

(defun get-file-of-linetype (lt-name / lt-list file-names)
  (setq lt-name (strcase lt-name))
  (if (setq lt-list (get-line-types))
    (foreach file-list lt-list
      (if (member lt-name (mapcar 'strcase (cadr file-list)))
        (setq file-names (cons (car file-list) file-names))
      )
    )
  )
  file-names
)



;;  CAB 11/22/2005
;;  returns a list of all linetypes found in all .lin files found
(defun get-line-types (/ path paths fname fnames fnamelist ltnames linetypelist
                      )

  (defun getlinetypes (filename / file line str lst)
    (if (setq file (open (findfile filename) "r"))
      (progn
        (while (setq line (read-line file))
          (if (wcmatch line "`**")
            (setq str (substr (substr line 1 (vl-string-search "," line)) 2)
                  lst (cons str lst)
            )
          )
        )
        (close file)
      )
    )
    (reverse lst)
  )


  ;;   get a list of all ACAD paths
  ;;  removes "." ".." and needs error checking
  (setq paths (cdr (cdr (vl-directory-files nil nil -1))))

  ;;  get a list of all file names .lin
  (foreach path paths
    (if (setq fnames (vl-directory-files path "*.lin"))
      (setq fnamelist (append fnames fnamelist))
    )
  )

  (foreach fname fnamelist
    (if (setq ltnames (getlinetypes fname))
      (setq linetypelist (cons (list fname ltnames) linetypelist))
    )
  )

  (princ)
  linetypelist
)