Hi
I am trying to paint linetype patterns in my form. So far i have found the following solution.
Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim ltt As LinetypeTable = DirectCast(tr.GetObject(db.LinetypeTableId, OpenMode.ForRead), LinetypeTable)
Dim ltName As String = "Continuous"
Dim ltId As ObjectId = ltt(ltName)
Dim iPtr As IntPtr = Autodesk.AutoCAD.Internal.Utils.DrawLineTypePattern(ltId, 0, 0, 128, 32)
Dim img As System.Drawing.Image = System.Drawing.Image.FromHbitmap(iPtr)
img.Save(String.Format("C:\Temp\Image {0}.png", ltName), Imaging.ImageFormat.Png)
End Using
The problem now is that the returned image is completely white.
Can someone help?
Thanks
Frank
Hi Frank,
Sorry to say this ,the API you are using is an internal one which is unsupported and no relevant documentation is available for us.
Its is hard for us to comment on this.
Can you please more specific as what your trying to do ?
If you are looking to display linetype in your form , you can use LineTypeTableRecorder.Comments API which gives ascii description of LineType.
[CommandMethod("PaintTest")] public static void PaintTest() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction t = db.TransactionManager.StartTransaction()) { LinetypeTable ltype = t.GetObject(db.LinetypeTableId, OpenMode.ForWrite) as LinetypeTable; LinetypeTableRecord ltTblRec = t.GetObject(ltype["ZIGZAG"], OpenMode.ForRead) as LinetypeTableRecord; ed.WriteMessage("LineType Desc " + ltTblRec.Comments + "\n"); //IntPtr iPtr = Autodesk.AutoCAD.Internal.Utils.DrawLineTypePattern(ltTblRec.ShapeStyleAt, 0, 0, 128, 32); // System.Drawing.Image img = System.Drawing.Image.FromHbitmap // img.Save(String.Format("C:\\Temp\\Image_1 {0}.png", "ZIGZAG"), System.Drawing.Imaging.ImageFormat.Png); } }
Hi , hope this may help
I was trying to create image of text description of LineType.
Here is the full code and attached resultant image too.
[CommandMethod("PaintTest")] public static void PaintTest() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction t = db.TransactionManager.StartTransaction()) { LinetypeTable ltype = t.GetObject(db.LinetypeTableId, OpenMode.ForWrite) as LinetypeTable; LinetypeTableRecord ltTblRec = t.GetObject(ltype["ZIGZAG"], OpenMode.ForRead) as LinetypeTableRecord; ConvertTextToImage(ltTblRec.Comments); t.Commit(); } } public static void ConvertTextToImage(string txtText) { string text = txtText.Trim(); Bitmap bitmap = new Bitmap(1, 1); System.Drawing.Font font = new System.Drawing.Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel); Graphics graphics = Graphics.FromImage(bitmap); int width = (int)graphics.MeasureString(text, font).Width; int height = (int)graphics.MeasureString(text, font).Height; bitmap = new Bitmap(bitmap, new Size(width, height)); graphics = Graphics.FromImage(bitmap); graphics.Clear(Color.White); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.TextRenderingHint = TextRenderingHint.AntiAlias; int argb = Color.Black.ToArgb(); graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(argb)), 0, 0); graphics.Flush(); graphics.Dispose(); bitmap.Save(String.Format("C:\\Temp\\Image_1 {0}.png", "ZIGZAG"), ImageFormat.Png); }
Thanks for responding Madhukar. And for the examples.
The problem i face is that in many cases there is no description line or the description line does not represent the linetype. Also in a lot of cases shapes are used.
So that is why i try to find a solution to show the linetype with the same quality as AutoCAD does (like in Select Linetype).
The function in my example i found on internet using Google.
Best regards
Frank
Dear Frank ,
Sorry without noticing , I have given C# sample codes , hope it's not a problem for you.
Do let me know if this sample is of any help.