Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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.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:

The above code is give me output in command prompt but i want output on my drawing i.e.on dwg file plz help me to figure it out thanx.
Posted
Updated 28-Jun-16 21:05pm
v2
Comments
Sergey Alexandrovich Kryukov 29-Jun-16 3:25am    
The problem is unclear; I can only tell you for sure: nothing in any applications is related to "command prompt". The "prompt" is nothing as one of the many other applications which can start other applications; the command interpreter.
The creation of the files should be described in the AutoCAD API documentation; from your code, I cannot see where you try to save any file at all.
—SA
@j@y123 29-Jun-16 3:48am    
in autocad there is command prompt where i am trying this solution but i want that output on my drawing.
Sergey Alexandrovich Kryukov 29-Jun-16 3:53am    
Do you mean that you have to add some text to drawing?
—SA
@j@y123 29-Jun-16 4:11am    
yes exactly the output of above code i want to display in my drawing

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