Custom Hatch pattern in code

Custom Hatch pattern in code

Anonymous
Not applicable
1,292 Views
2 Replies
Message 1 of 3

Custom Hatch pattern in code

Anonymous
Not applicable

Hi group,

I have come up short trying to find code for creating custom Hatch pattern

in code rather than having to import a .pat file.  I assume it’s similar to

creating a custom (in code) Linetype but I’m not finding an example anywhere.

 

Is this possible?

 

Thanks,

 

Martin.

0 Likes
1,293 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Try this:

 

        [CommandMethod("CreateHatchPattern")]
        public static void CreateHatchPattern()
        {
            string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
            if (Environment.OSVersion.Version.Major >= 6)
            {
                path = Directory.GetParent(path).ToString();
            }

            //Adjust the Path According to your AutoCad version
            //FileName must be equal to pattern name
            path = path + "\\AppData\\Roaming\\Autodesk\\AutoCAD 2015\\R20.0\\enu\\Support\\Tile Test.pat";

            List<string> Pattern = new List<string>();

            //Pattern see https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Creating-new-Custom-Hatch-patterns.html
            //and https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Error-in-pattern-file-in-AutoCAD.html
            //FileName must be equal to pattern name
            Pattern.Add("*Tile Test");
            Pattern.Add("45, 0,0, 0,.125");
            Pattern.Add("135, 0,0, .25,.125, .3125,-.1875");
            //Last return needed!
            Pattern.Add("");

            if (!File.Exists(path))
            {
                File.AppendAllLines(path, Pattern);
            }
            else if (File.Exists(path))
            {
                File.Delete(path);
                File.AppendAllLines(path, Pattern);
            }
        }

I did'nt use TextWriter because the .pat file is in use.

There are a few rules to be followed when creating custom .pat patterns:

 

See: 

https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Error-...

 

PS. I suffered from this rules myself.

Message 3 of 3

Anonymous
Not applicable

Thanks Marcos,

I will have a look. 😄

0 Likes