Author Topic: Can't load my linetype  (Read 1779 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Can't load my linetype
« on: November 16, 2011, 02:34:24 AM »
Hi all.
***********************
AutoCAD 2009 SP3 x86 Enu
.Net Framework 3.5 SP1
Windows XP SP3 x86 Rus
***********************

I write next method:
Code: [Select]
/// <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):
Code: [Select]
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) {

    }
}
« Last Edit: November 16, 2011, 02:39:39 AM by Andrey »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Can't load my linetype
« Reply #1 on: November 16, 2011, 04:04:20 AM »
The question is solved. I thought that in a method the name, and actually - a sampling template is transferred.

From help ObjectARX the function description :
Quote
acutWcMatch:
Character  Definition 
# (Pound)  Matches any single numeric digit. 
@ (At)  Matches any single alphabetic character. 
. (Period)  Matches any single non-alphanumeric character. 
* (Asterisk)  Matches any character sequence, including an empty one. You can use an asterisk anywhere in the search pattern--at the beginning, middle, or end. 
? (Question mark)  Matches any single character. 
~ (Tilde)  If it is the first character in the pattern, then it matches anything except the pattern. 
[...]  Matches any one of the characters enclosed. 
[~...]  Matches any single character not enclosed. 
- (Hyphen)  Uses inside brackets to specify a range for a single character. 
, (Comma)  Separates two patterns. 
' (Reverse quote)  Escapes special characters (reads next character literally).
But in help an error: instead of ' character there should be ` character.

Just in case I screen all characters:
Code: [Select]
StringBuilder sb = new StringBuilder();
foreach (char item in ltName) {
    sb.Append('`');
    sb.Append(item);
}
ltName = sb.ToString();
« Last Edit: November 16, 2011, 05:54:54 AM by Andrey »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Can't load my linetype
« Reply #2 on: November 16, 2011, 05:56:14 AM »
I has written some methods which can be useful when it is required to load the drawing linetypes from lin-files. Brief information on methods:
  • LinetypeInfo - a class into which the complete information about the linetypes, received of lin-files is packed.
  • FindAllLintypes - to find all lin-files and to derive from them the information on all linetypes, having packed it into objects of class LinetypeInfo.
  • GetSuitableLinFiles - to find all lin-files in which contents of linetype with the name specified by us.
  • LinetypeLoad - to load in the drawing from the specified lin-file the given linetype.
It will be possible to someone interesting. The code here.
« Last Edit: November 16, 2011, 07:43:35 AM by Andrey »