Message 1 of 11
Associative Hatch Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am writing a function to create Hatch. Everything works just fine except Associative. if I put the
oHatch.Associative = true;
get a error message:
eNotInDatabase
It will work if I remove this line.
does anybody know how to fix it? thank you very much.
Here is the code:
public static Hatch CreateHatch(Entity pline, BlockTableRecord btr, short HatchColor,
string HatchLayer, string HatchPattern, double HatchScale, double HatchAngle, bool HatchAssociate)
{
if (pline == null) return null;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForWrite);
bool IsSolid = (HatchPattern == "SOLID");
LayerLibrary.IsLayerLocked(HatchLayer);
if (HatchPattern.Substring(0,3).Equals("ISO")) {HatchPattern = "ACAD_" + HatchPattern;}
ObjectId oId;
if (HatchAssociate)
{
Entity pline2 = (Entity)trans.GetObject(pline.ObjectId,OpenMode.ForWrite);
oId = pline2.ObjectId;
}
else { oId = pline.ObjectId;}
ObjectIdCollection ObjIds = new ObjectIdCollection();
ObjIds.Add(oId);
Hatch oHatch = new Hatch();
try
{
oHatch.SetHatchPattern(HatchPatternType.PreDefined,HatchPattern);
oHatch.AppendLoop(0, ObjIds);
oHatch.Layer = HatchLayer;
oHatch.ColorIndex = HatchColor;
oHatch.Associative = HatchAssociate;
if (!IsSolid)
{
oHatch.PatternAngle = HatchAngle;
oHatch.PatternScale = HatchScale;
}
oHatch.EvaluateHatch(true);
btr.AppendEntity(oHatch);
trans.AddNewlyCreatedDBObject(oHatch,true);
trans.Commit();
}
catch (System.Exception caught)
{
// ddebug
ed.WriteMessage(caught.Message.ToString());
oHatch = null;
}
finally
{
trans.Dispose();
}
return oHatch;
}
Wes
I am writing a function to create Hatch. Everything works just fine except Associative. if I put the
oHatch.Associative = true;
get a error message:
eNotInDatabase
It will work if I remove this line.
does anybody know how to fix it? thank you very much.
Here is the code:
public static Hatch CreateHatch(Entity pline, BlockTableRecord btr, short HatchColor,
string HatchLayer, string HatchPattern, double HatchScale, double HatchAngle, bool HatchAssociate)
{
if (pline == null) return null;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForWrite);
bool IsSolid = (HatchPattern == "SOLID");
LayerLibrary.IsLayerLocked(HatchLayer);
if (HatchPattern.Substring(0,3).Equals("ISO")) {HatchPattern = "ACAD_" + HatchPattern;}
ObjectId oId;
if (HatchAssociate)
{
Entity pline2 = (Entity)trans.GetObject(pline.ObjectId,OpenMode.ForWrite);
oId = pline2.ObjectId;
}
else { oId = pline.ObjectId;}
ObjectIdCollection ObjIds = new ObjectIdCollection();
ObjIds.Add(oId);
Hatch oHatch = new Hatch();
try
{
oHatch.SetHatchPattern(HatchPatternType.PreDefined,HatchPattern);
oHatch.AppendLoop(0, ObjIds);
oHatch.Layer = HatchLayer;
oHatch.ColorIndex = HatchColor;
oHatch.Associative = HatchAssociate;
if (!IsSolid)
{
oHatch.PatternAngle = HatchAngle;
oHatch.PatternScale = HatchScale;
}
oHatch.EvaluateHatch(true);
btr.AppendEntity(oHatch);
trans.AddNewlyCreatedDBObject(oHatch,true);
trans.Commit();
}
catch (System.Exception caught)
{
// ddebug
ed.WriteMessage(caught.Message.ToString());
oHatch = null;
}
finally
{
trans.Dispose();
}
return oHatch;
}
Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023