Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows.Data;
using System;
using System.Text;
 
public class DataStuff
{
    [CommandMethod("HL")]
    static public void GetHatchPatterns()
    {
        Document acDoc = Application.DocumentManager.MdiActiveDocument;
        Database db = acDoc.Database;
        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
 
        Transaction tr = acDoc.Database.TransactionManager.StartTransaction();
        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
        PromptPointResult ppr;
        PromptPointOptions ppo = new PromptPointOptions("");
        ppo.Message = "\n Select the place for print output:";
        //get the coordinates from user
        ppr = ed.GetPoint(ppo);
        if (ppr.Status != PromptStatus.OK)
            return;
        Point3d startPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
 
        Vector3d disp = new Vector3d(0.0, -2.0 * db.Textsize, 0.0);
        //Vector3d disp2 = new Vector3d(0.0, -2.0 * db.Textsize, 0.0);
 
        // HatchPatterns hatc = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as HatchPatterns;
 
        Hatch hat = new Hatch();
        foreach (string str in HatchPatterns.Instance.AllPatterns)
        {
            if (hat.PatternName == "ANSI32" && hat.PatternScale == 10.0 ||
                hat.PatternName == "ANSI35" && hat.PatternScale == 10.00 ||
                hat.PatternName == "AR-CONC" && hat.PatternScale == 0.2 ||
                hat.PatternName == "AR-SAND" && hat.PatternScale == 0.2 ||
                hat.PatternName == "EARTH" && hat.PatternScale == 10 && hat.PatternAngle == 0 ||
                hat.PatternName == "EARTH" && hat.PatternScale == 10 && hat.PatternAngle == 315 ||
                hat.PatternName == "ANSI34" && hat.PatternScale == 3.0 && hat.PatternAngle == 45 ||
                hat.PatternName == "AR-HBONE" && hat.PatternScale == 0.5 && hat.PatternAngle == 270 ||
                hat.PatternName == "HONEY" && hat.PatternScale == 5.0 && hat.PatternAngle == 270 ||
                hat.PatternName == "ZIGZAG" && hat.PatternScale == 2.0 && hat.PatternAngle == 45 ||
                hat.PatternName == "ANSI31" && hat.PatternScale == 5.0 && hat.PatternAngle == 0 ||
                hat.PatternName == "ANSI31" && hat.PatternScale == 500.0 && hat.PatternAngle == 0 ||
                hat.PatternName == "GRASS" && hat.PatternScale == 0.15 && hat.PatternAngle == 0 ||
                hat.PatternName == "GRASS" && hat.PatternScale == 100.0 && hat.PatternAngle == 0 ||
                hat.PatternName == "SACNCR" && hat.PatternScale == 500.0 && hat.PatternAngle == 0 ||
                hat.PatternName == "NET3" && hat.PatternScale == 500 && hat.PatternAngle == 0 ||
                hat.PatternName == "ZIGZAG" && hat.PatternScale == 1000.0 && hat.PatternAngle == 0)
 
            {
                ed.WriteMessage("Valid hatch used:");
            }
            else
            {
                ed.WriteMessage("This hatches are not allowed:" + "\n" + hat.PatternName);
            }
        }
 
        tr.Commit();
    }
}


What I have tried:

I want to specify particular hatches in my code so only that hatches will be used in the autocad. First it identify hatches and then compare it with specify hatches but code not run properly.Please suggest me the solution for that.
Posted
Updated 20-Sep-16 20:11pm
v3

1 solution

"Not running properly" is one of the error reports we get that is completely useless - it tells us nothing, except that you have a problem (which we knew anyway because otherwise you wouldn't be asking a question).
So in future, tell us what it does that you didn't expect, or doesn't do that you did. Tell us what the software is supposed to do, what data you feed it to make it do it, what output you expect, and what you actually get! Tell us about any error messages, and where they occur.
Help us to help you!

In this case, we can't help you much anyway - we don't have your documents to work from, and they are likely to be very relevant.
So it's up to you.
Use the debugger. Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

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