Hi all.
***********************
AutoCAD 2009 SP3 x86 Enu
.Net Framework 3.5 SP1
Windows XP SP3 x86 Rus
***********************
I write next method:
/// <summary>
/// To receive all *.lin-files in which there is a determination of linetypes with the necessary name
/// </summary>
/// <param name="linetypeName">linetype name</param>
/// <returns>The array of *.lin-files, in each of which is present of linetype definition with the specified name</returns>
public string[] GetSuitableLinFiles(string linetypeName) {
string[] all_linFiles = acad.UserConfigurationManager.OpenCurrentProfile().OpenSubsection("General")
.ReadProperty("ACAD", string.Empty).ToString().Split(';').Where(n => n != string.Empty)
.SelectMany(n => Directory.GetFiles(n, "*.lin", SearchOption.TopDirectoryOnly)).ToArray();
List<string> linFiles = new List<string>();
foreach (string file in all_linFiles) {
using (FileStream fs = new FileStream(file, FileMode.Open)) {
using (StreamReader sr = new StreamReader(fs, Encoding.Default)) {
while (!sr.EndOfStream) {
string str = sr.ReadLine();
if (str.StartsWith("*" + linetypeName, StringComparison.InvariantCultureIgnoreCase)) {
linFiles.Add(file);
}
}
fs.Close();
sr.Close();
}
}
}
return linFiles.ToArray();
}
It works correctly.
After suitable *.lin-files are found, I need to take the first of them and to load from it linetype (problem has described in the comment):
string ltName = "Штрихпунктирная с двумя точками тонкая [-4х18]";//It value get exeption "eUndefinedLineType" below in the code
//string ltName = "ACAD_ISO02W100";// It value work successfully below in the code!
string[] linFiles = GetSuitableLinFiles(ltName);
if (linFiles.Length > 0) {
try {
//I need load linetype with name:
//"Штрихпунктирная с двумя точками тонкая [-4х18]"
// from my file "ГОСТ 2.303-68. Линии.lin" (look attached file below)...
//Next code string work correctly always, (but I don't want to load all linetypes):
//db.LoadLineTypeFile("*", linFiles[0]);
//I want load my linetype only (not all linetypes):
db.LoadLineTypeFile(ltName, linFiles[0]);
//If I try to load standard linetype, for example "ACAD_ISO02W100" from a file "acadiso.lin" - all boots successfully!
//But if I try load my linetype - I get exeption "eUndefinedLineType"...
//WARNING!!!
//If I try loading my linetype manually - is happens successfully!
//Why I can't load one my linetype only?
}
catch (Autodesk.AutoCAD.Runtime.Exception ex) {
}
}