Hatch C#

Hatch C#

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

Hatch C#

Anonymous
Not applicable
Hello,

I'm writing some code that lets to create Hatch programmatically
something like this ->


public Hatch hat;

public void mtHatchobject(ObjectIdCollection myobjects, string lay)
{


hat = new Hatch();

hat.Associative = true;

hat.AppendLoop(0,myobjects );

hat.EvaluateHatch(true);


}
Does anybody have a clue how I can do it ?
0 Likes
1,917 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
This code allways works for me:

public static void drawHatch(ObjectIdCollection idcBoundary, string pattern,
double angle, double scale, ObjectId layerid, int color)
{
//Lock the document
...

Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();

Hatch oHatch = new Hatch();

//Define style
oHatch.PatternAngle = angle;
oHatch.PatternScale = scale;
oHatch.SetHatchPattern(HatchPatternType.PreDefined, pattern);
oHatch.LayerId = layerid;
oHatch.Color = caAcColors.getAciColorByNumber(color);

//Add to database
if (!btr.IsWriteEnabled) btr.UpgradeOpen();
id = btr.AppendEntity(oHatch);
trans.AddNewlyCreatedDBObject(oHatch, true);

oHatch.Associative = true;

//Define loops
oHatch.AppendLoop(HatchLoopTypes.Default, idcBoundary);

//Evaluate
oHatch.EvaluateHatch(true);

trans.Commit();

//Unlock the document
...
}





schreef in bericht news:5681777@discussion.autodesk.com...
Hello,

I'm writing some code that lets to create Hatch programmatically
something like this ->


public Hatch hat;

public void mtHatchobject(ObjectIdCollection myobjects, string lay)
{


hat = new Hatch();

hat.Associative = true;

hat.AppendLoop(0,myobjects );

hat.EvaluateHatch(true);


}
Does anybody have a clue how I can do it ?
0 Likes
Message 3 of 3

Anonymous
Not applicable
I saw I did forgot something: before you can acces the blocktablerecord
(btr) you first have to define it 🙂
In the code below I did this by getting the "owner" of the first entity in
the list of boundaries (usually this is modelspace).


BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
OpenMode.ForRead);

Entity ent = (Entity)trans.GetObject(idcBoundary[0], OpenMode.ForRead);

BlockTableRecord btr = (BlockTableRecord)trans.GetObject(ent.BlockId,
OpenMode.ForWrite);
0 Likes