.NET

.NET

Reply
New Member
sinhhoainguyen
Posts: 1
Registered: ‎09-09-2013
Message 1 of 2 (251 Views)

Need for help: hatch.appendloop function get message eInvalidInput

251 Views, 1 Replies
09-09-2013 07:18 PM

 i have a .dwg fille with some block reference.
 
I want to fill color for block reference, but when I debug to hatch.appendloop function, I get message eInvalidInput, and block don’t fill color.
 
This is my code:
 
[CommandMethod("FillColor")]
public void FillColor()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed =
doc.Editor;
Database db =
HostApplicationServices.WorkingDatabase;
Transaction tr =
db.TransactionManager.StartTransaction();
 
// Start the transaction
try
{
// Build a filter list so that only
// block references are selected
TypedValue[] filList = new TypedValue[1] {
new TypedValue((int)DxfCode.Start, "INSERT")
};
SelectionFilter filter =
new SelectionFilter(filList);
PromptSelectionOptions opts =
new PromptSelectionOptions();
opts.MessageForAdding = "Select block references: ";
PromptSelectionResult res =
ed.GetSelection(opts, filter);
 
 
// Do nothing if selection is unsuccessful
if (res.Status != PromptStatus.OK)
return;
 
SelectionSet selSet = res.Value;
ObjectId[] idArray = selSet.GetObjectIds();
foreach (ObjectId blkId in idArray)
{
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.PaperSpace],
OpenMode.ForWrite
);
 
 
 
Hatch hat = new Hatch();
hat.SetDatabaseDefaults();
 
hat.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
hat.Color = Color.FromRgb(0, 0, 255);
 
// Add the hatch to the model space
// and the transaction
ObjectId hatId = btr.AppendEntity(hat);
tr.AddNewlyCreatedDBObject(hat, true);
 
// Add the hatch loop and complete the hatch
ObjectIdCollection ids = new ObjectIdCollection();
ids.Add(blkId);
hat.Associative = true;
hat.AppendLoop(HatchLoopTypes.Default, ids); // error here....
 
hat.EvaluateHatch(true);
 
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(("Exception: " + ex.Message));
}
finally
{
tr.Dispose();
}
}
 
Please help me, if you can!

Distinguished Mentor
gasty1001
Posts: 582
Registered: ‎04-11-2010
Message 2 of 2 (235 Views)

Re: Need for help: hatch.appendloop function get message eInvalidInput

09-09-2013 09:36 PM in reply to: sinhhoainguyen

Hi,

 

Not sure, but I think  that a HatchLoop should be a curve derived object like a polyline, and you are using a block reference which it's not. 

 

Gaston Nunez

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.