找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 4634|回复: 0

[分享] eInvalidInput while creating hatch with CustomDefined pattern

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2013-5-27 00:03:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
eInvalidInput while creating hatch with CustomDefined pattern                                                        By Balaji Ramamoorthy
If the "SetHatchPattern" method throws an "eInvalidInput" exception while creating a hatch using a CustomDefined hatch pattern, here are few points to check.
1) Is the pattern file that defines the custom hatch pattern named correctly ? The name of the hatch pattern and the pat file name should be the same.
2) Is the folder in which the pat file is placed, added to the AutoCAD support path ?
3) Is the line breaks in the pat file ok ? The easiest way to ensure that it is ok is to take an existing custom hatch pattern file and change the definitions to suit your requirements. AutoCAD is sensitive to line breaks in the pat file and "eInvalidInput" exception because of this can be hard to spot. You can find several online resources such as this to download a custom hatch pattern file.
Here is a sample code to try out the custom hatch pattern :
  1. Document doc = Application.DocumentManager.MdiActiveDocument;
  2. Database db = doc.Database;
  3. Editor ed = doc.Editor;
  4. PromptResult prHatchPatternName
  5.         = ed.GetString("\nEnter custom hatch pattern name : ");
  6. if (prHatchPatternName.Status != PromptStatus.OK)
  7.     return;
  8. string patName = prHatchPatternName.StringResult;
  9. PromptPointResult ppr = ed.GetPoint("Pick insertion point: ");
  10. if (ppr.Status != PromptStatus.OK)
  11.     return;
  12. Point3d insertionPt = ppr.Value;
  13. try
  14. {
  15.     using (Transaction tr = db.TransactionManager.StartTransaction())
  16.     {
  17.         BlockTable bt
  18.             = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  19.         BlockTableRecord btr
  20.             = tr.GetObject( bt[BlockTableRecord.ModelSpace],
  21.                             OpenMode.ForWrite
  22.                           ) as BlockTableRecord;

  23.         Point2d pt = new Point2d(insertionPt.X, insertionPt.Y);
  24.         Polyline plBox;
  25.         plBox = new Polyline(4);
  26.         plBox.Normal = Vector3d.ZAxis;
  27.         plBox.AddVertexAt(0, pt, 0.0, -1.0, -1.0);
  28.         plBox.AddVertexAt(1, new Point2d(pt.X + 10, pt.Y), 0.0, -1.0, -1.0);
  29.         plBox.AddVertexAt(2, new Point2d(pt.X + 10, pt.Y + 5), 0.0, -1.0, -1.0);
  30.         plBox.AddVertexAt(3, new Point2d(pt.X, pt.Y + 5), 0.0, -1.0, -1.0);
  31.         plBox.Closed = true;
  32.         ObjectId pLineId;
  33.         pLineId = btr.AppendEntity(plBox);
  34.         tr.AddNewlyCreatedDBObject(plBox, true);
  35.         ObjectIdCollection ObjIds = new ObjectIdCollection();
  36.         ObjIds.Add(pLineId);
  37.         Hatch hatchObj = new Hatch();
  38.         hatchObj.SetDatabaseDefaults();
  39.         Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
  40.         hatchObj.HatchObjectType = HatchObjectType.HatchObject;
  41.         hatchObj.Color
  42.                 = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Blue);
  43.         hatchObj.Normal = normal;
  44.         hatchObj.Elevation = 0.0;
  45.         hatchObj.SetHatchPattern(HatchPatternType.CustomDefined, patName);
  46.         btr.AppendEntity(hatchObj);
  47.         tr.AddNewlyCreatedDBObject(hatchObj, true);
  48.         hatchObj.Associative = true;
  49.         hatchObj.AppendLoop((int)HatchLoopTypes.Default, ObjIds);
  50.         hatchObj.EvaluateHatch(true);
  51.         tr.Commit();
  52.     }
  53. }

  54. catch (System.Exception ex)
  55. {
  56.     ed.WriteMessage(ex.ToString() + Environment.NewLine);
  57. }


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-6-28 13:59 , Processed in 0.365596 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表