代码运行不正常。 [英] Code not running properly.

查看:98
本文介绍了代码运行不正常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
    }
}





我的尝试:



我想在我的代码中指定特定的阴影,所以只有那些阴影才能在autocad中使用。首先它识别阴影,然后将其与指定的阴影进行比较,但代码运行不正确。请为我建议解决方案。



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.

推荐答案

运行不正常是其中之一我们得到的错误报告完全没用 - 它告诉我们什么都没有,除了你有问题(无论如何我们都知道,否则你不会问一个问题)。

所以将来,告诉我们你没想到的是什么,或者你没做过。告诉我们该软件应该做什么,你用它做什么数据来做它,你期望什么输出,你实际得到什么!告诉我们任何错误信息,以及它们发生的位置。

帮助我们帮助你!



在这种情况下,我们不能无论如何帮助你 - 我们没有你的文件,它们可能非常相关。

所以这取决于你。

使用调试器。在函数的第一行放置一个断点,然后通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
"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!


这篇关于代码运行不正常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆