Click here to Skip to main content
16,017,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
[CommandMethod("FindAllHatches")]
public static void FindAllHatches()
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;

    acDoc.Editor.WriteMessage("\nSearching for Hatches");

    var db = acDoc.Database;
    using (Transaction transaction = db.TransactionManager.StartTransaction())
    {
        ObjectId idModelSpace = SymbolUtilityServices.GetBlockModelSpaceId(db);

        BlockTableRecord modelSpace = transaction.GetObject(idModelSpace, OpenMode.ForRead) as
            BlockTableRecord;

        foreach (var objId in modelSpace)
        {
            var entity = transaction.GetObject(objId, OpenMode.ForRead);
            Hatch hatch = entity as Hatch;
            if (hatch == null)
                continue; //not hatch

            acDoc.Editor.WriteMessage("\nFound Hatch Area={0}", hatch.Area);
        }            
    }
}


What I have tried:

Try to generate the output vertically so each area shows seprately
Posted
Updated 8-Jul-16 1:36am
Comments
@j@y123 6-Jul-16 6:14am    
namespace allhatch
{
public class Class1
{
[CommandMethod("HA")]
public static void FindAllHatches()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;

acDoc.Editor.WriteMessage("\nSearching for Hatches");

var db = acDoc.Database;
using (Transaction transaction = db.TransactionManager.StartTransaction())
{
ObjectId idModelSpace = SymbolUtilityServices.GetBlockModelSpaceId(db);

BlockTableRecord modelSpace = transaction.GetObject(idModelSpace, OpenMode.ForWrite) as
BlockTableRecord;

foreach (var objId in modelSpace)
{
var entity = transaction.GetObject(objId, OpenMode.ForRead);
Hatch hatch = entity as Hatch;
if (hatch == null)
continue; //not hatch
MText actext = new MText();
actext.SetDatabaseDefaults();
actext.Height = 16;
actext.Width = 2;

actext.Contents = ("\n The area of hatch is =" + hatch.Area);
acDoc.Editor.WriteMessage("\n The area of hatch is:" + hatch.Area);

modelSpace.AppendEntity(actext);
transaction.AddNewlyCreatedDBObject(actext, true);
}
transaction.Commit();
}
}
}
}
@j@y123 6-Jul-16 6:14am    
This is the whole code for the same

1 solution

try this

C#
[CommandMethod("FindAllHatches")]
public static void FindAllHatches()
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
 var str=new StringBuilder();
    str.Append("\nSearching for Hatches");
 
    var db = acDoc.Database;
    using (Transaction transaction = db.TransactionManager.StartTransaction())
    {
        ObjectId idModelSpace = SymbolUtilityServices.GetBlockModelSpaceId(db);
 
        BlockTableRecord modelSpace = transaction.GetObject(idModelSpace, OpenMode.ForRead) as
            BlockTableRecord;
 
        foreach (var objId in modelSpace)
        {
            var entity = transaction.GetObject(objId, OpenMode.ForRead);
            Hatch hatch = entity as Hatch;
            if (hatch == null)
                continue; //not hatch

           str.Append("\nFound Hatch Area={0}", hatch.Area);
        } 
 acDoc.Editor.WriteMessage(str.ToString());           
    }
}
 
Share this answer
 
v2
Comments
@j@y123 11-Jul-16 0:26am    
it gives me error Suppression Error CS1503 Argument 1: cannot convert from 'string' to 'char'and 'double' to 'int'.
@j@y123 11-Jul-16 0:30am    
And second thing is that i want output on my drawing not on the prompt.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900