通过设计自动化进行DWG比较

时间:2018-07-31 14:16:12

标签: autodesk-forge autodesk-designautomation

我想知道是否有可能,如果可以,如何通过设计自动化实现dwg比较?我有一种方法可以创建一个接受输入2 dwg的比较活动,并将布尔值发布为输出?

1 个答案:

答案 0 :(得分:0)

是的,您可以创建一个接受两个工程图的活动。 活动结束后,JSON使用内置的比较并输出结果差异图。

示例活动Json

{
    "HostApplication": "",
    "RequiredEngineVersion": "23.0",
    "Parameters": {
        "InputParameters": [
            {
                "Name": "HostDwg",
                "LocalFileName": "$(HostDwg)"
            },
            {
                "Name": "ToCompareWith",
                "LocalFileName": "ToCompareWith.dwg"
            }
        ],
        "OutputParameters": [
            {
                "Name": "Result",
                "LocalFileName": "output.dwg"
            }
        ]
    },
    "Instruction": {
        "CommandLineParameters": null,
        "Script": "COMPAREINPLACE\nON\n-COMPARE\n\nToCompareWith.dwg\n_SAVEAS\n\noutput.dwg\n"
    },
    "Id": "FPDCompare"
}

Workitem Json

{
    "Arguments": {
        "InputArguments": [
            {
                "Resource": "https://madhukar-fda.s3.us-west-2.amazonaws.com/Kitchens1.dwg",
                "Name": "HostDwg"
            },
            {
                "Resource": "https://madhukar-fda.s3.us-west-2.amazonaws.com/Kitchens2.dwg",
                "Name": "ToCompareWith"
            }
        ],
        "OutputArguments": [
            {
                "Name": "Result",
                "HttpVerb": "POST"
            }
        ]
    },
    "ActivityId": "FPDCompare"
}
  

如果您使用自己的自定义比较逻辑,则可以输出   结果转换为txt文件或json文件。

活动Json

{
    "HostApplication": "",
    "RequiredEngineVersion": "23.0",
    "Parameters": {
        "InputParameters": [
            {
                "Name": "HostDwg",
                "LocalFileName": "$(HostDwg)"
            },
            {
                "Name": "ToCompareWith",
                "LocalFileName": "ToCompareWith.dwg"
            }
        ],
        "OutputParameters": [
            {
                "Name": "Result",
                "LocalFileName": "output.txt"
            }
        ]
    },
    "Instruction": {
        "CommandLineParameters": null,
        "Script": "ISDWGSIMILAR\nToCompareWith.dwg\n"
    },
    "AppPackages":["Compare"],
    "Version": 1,
    "Id": "Compare"
}

Workitem Json

{
    "Arguments": {
        "InputArguments": [
            {
                "Resource":"https://madhukar-fda.s3.us-west-2.amazonaws.com/Kitchens.dwg",
                "Name": "HostDwg"
            },
            {
                "Resource":"https://madhukar-fda.s3.us-west-2.amazonaws.com/Kitchens1.dwg",
                "Name": "ToCompareWith"
            }
        ],
        "OutputArguments": [
            {
                "Name": "Result",
                "HttpVerb": "POST"
            }
        ]
    },
    "ActivityId": "Compare"
}

注意:在脚本参数-“ ISDWGSIMILAR”是一个自定义命令,您将在其中处理两个工程图,第一个是当前工程图,第二个是您要与[ToCompareWith]比较的工程图。

自定义NET命令

    [CommandMethod("FDACOMMANDS", "ISDWGSIMILAR", CommandFlags.Transparent)]
    public static void CompareDrawing()
    {
        var doc = Application.DocumentManager.MdiActiveDocument;
        var db = doc.Database;
        var ed = doc.Editor;
        var promptResult = ed.GetString("Select Drawing To Compare With");
        if (promptResult.Status != PromptStatus.OK) return;
        var drawingToCompareWith = promptResult.StringResult;
        ed = Application.DocumentManager.MdiActiveDocument.Editor;
        using (OpenCloseTransaction o = new OpenCloseTransaction())
        {
           /*

           {

           Here your logic code to compare two drawings

           }

           */

            /*output.txt / json is pushed to your cloud storage as provided in workitem json*/
            using (var writer = File.CreateText("output.txt"))
            {
                if (b != null) /*b value is result of your compare*/
                {
                    writer.WriteLine("TRUE Drawings are same");
                }
                else writer.WriteLine("FALSE Drawings aren't same");
            }
        }
    }