Prod.: Engine, ver.: 6, ID: 60001281, HowTo : User defined HatchPatterns are not added to the patterns collection when saved in DXF DWG formats

HowTo : User defined HatchPatterns are not added to the patterns collection when saved in DXF DWG formats

Article60001281
TypeHowTo
ProductEngine
Version6
Date Added1/7/2011
Submitted bySami Tainio
Keywords

Subject

User defined HatchPatterns are not added to the patterns collection when saved in DXF DWG formats

Summary

User defined HatchPatterns are not added to the patterns collection when saved in .DXF/.DWG formats.

Solution

Hatched objects are correctly saved (with their “custom” hatches) in DWG/DXF files from VDF. You can see this by using the “Collections” sample and the Hatch patterns there and just add a “SaveAs (xxx.dwg)” code. The issue is that the hatches created with code are not added to the “hatch-pattern-collection” of the .DWG/.DXF files, because these files do not have such collection. This is an ACAD limitation at the moment as the Hatch Patterns in ACAD (DWG/DXF) are defined ONLY by .PAT files. There are some generic hatch-patterns files (acad.pat and acadiso.pat) that ACAD loads and uses and if the ACAD-user wants to add another pattern then he needs to create a .PAT file and add there ONE (only) hatch patern.
 
 
These pat files will be like :
filename : HELLO2.PAT
that will contain a string like :
    *HELLO2, This is my pattern
    0, 0, 0, 0, .275, .2, -.075
    90, 0, 0, 0, .275, .2, -.075
You can use a code like below in order to export the hatch patterns to .pat files :
        private void SaveHatchPatterns()
        {
            foreach (VectorDraw.Professional.vdPrimaries.vdHatchPattern myHatch in vdFramedControl1.BaseControl.ActiveDocument.HatchPatterns)
            {
                string name = myHatch.Name;
                if (name == "SOLID" || name == "" ) continue;
                string fileString = "";
                fileString = "*"+ myHatch.Name +", " + myHatch.Label + "\r\n";
                foreach (VectorDraw.DrawElements.grPatternLine patline in myHatch.PatternLines)
                {
                    double[] dashes = new double[patline.Dashes.Count];
                    for (int i = 0; i < patline.Dashes.Count; i++) dashes[i] = patline.Dashes[i];
                    
                    VectorDraw.Geometry.gPoint _offset = new VectorDraw.Geometry.gPoint(patline.Offset.x, patline.Offset.y);
                    double _angle = 0.0d;
                    VectorDraw.Geometry.Matrix m = new VectorDraw.Geometry.Matrix();
                    _angle = VectorDraw.Geometry.Globals.RadiansToDegrees(patline.Angle);
                    m.RotateZMatrix(-patline.Angle);
                    _offset = m.Transform(_offset);

                    fileString=fileString + _angle.ToString() + ", ";
                    fileString=fileString + patline.Origin.x.ToString()+", ";
                    fileString=fileString + patline.Origin.y.ToString()+", ";
                    fileString=fileString + _offset.x.ToString()+", ";
                    fileString=fileString + _offset.y.ToString();
                    if (dashes.Length > 0)
                    {
                        foreach (double var in dashes)
                        {
                            fileString = fileString+ ", " + var.ToString()  ;
                        }
                    }
                    fileString = fileString + "\r\n";
                }
                try
                {
                    System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test\\" + myHatch.Name + ".pat");
                    file.WriteLine(fileString);
                    file.Close();
                }
                catch (Exception e)
                {
                   MessageBox.Show( e.ToString());
                }

            }
        }