我使用 .NET 创建的自定义 CAD 脚本是否需要退出命令?

Does my custom CAD script created with .NET require a command for quitting?

我正在尝试使用设计自动化 API 对存储在存储桶中的 DWG 文件执行 CAD 脚本。它只是在文件上写 "Hello World!!!"。

为了创建脚本,我遵循了本教程:

https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-BA686431-C8BF-49F2-946E-9CEB2F7AE4FA

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

namespace MyFirstProject
{
    public class Class1
    {
        [CommandMethod("AdskGreeting")]
        public void AdskGreeting()
        {
            // Get the current document and database, and start a transaction
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            // Starts a new transaction with the Transaction Manager
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                /* Creates a new MText object and assigns it a location,
                text value and text style */
                using (MText objText = new MText())
                {
                    // Specify the insertion point of the MText object
                    objText.Location = new Autodesk.AutoCAD.Geometry.Point3d(2, 2, 0);

                    // Set the text string for the MText object
                    objText.Contents = "Hello World!!!";

                    // Set the text style for the MText object
                    objText.TextStyleId = acCurDb.Textstyle;

                    // Appends the new MText object to model space
                    acBlkTblRec.AppendEntity(objText);

                    // Appends to new MText object to the active transaction
                    acTrans.AddNewlyCreatedDBObject(objText, true);
                }

                // Saves the changes to the database and closes the transaction
                acTrans.Commit();
            }
        }
    }
}

我完成了设计自动化工作流程。我能够使用 Forge Node.js SDK post AppPackage,post Activity 和 post WorkItem。

但是,WorkItem 的状态返回为 FailedExecution

我不会显示整个错误日志,因为它包含机密信息,但这里有一些要点:


[01/17/2019 21:30:44] End download phase.
[01/17/2019 21:30:44] Start preparing script and command line parameters.
[01/17/2019 21:30:44] Start script content.
[01/17/2019 21:30:44] _ADSKGREETING
[01/17/2019 21:30:44] End script content.

//Blah

[01/17/2019 21:30:44] End preparing script and command line parameters.
[01/17/2019 21:30:44] Start script phase.

//Blah

[01/17/2019 21:30:44] Start AutoCAD Core Engine standard output dump.

//Blah blah blah

[01/17/2019 21:30:44] AutoCAD Core Engine Console - Copyright 2015 Autodesk, Inc.  All rights reserved. (M.49.Z.1)
[01/17/2019 21:30:44] Running at low integrity.
[01/17/2019 21:30:45] Loading AEC Base...
[01/17/2019 21:30:45] Loading AEC Base Extended...
[01/17/2019 21:30:45] Loading AEC Project Base...
[01/17/2019 21:30:45] Loading AEC Architectural Base...
[01/17/2019 21:30:46] Loading AEC Schedule...
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-l.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-l.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-l.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-l.shx].
[01/17/2019 21:30:46] Substituting [simplex.shx] for [fed-s.shx].
[01/17/2019 21:30:46] Regenerating model.
[01/17/2019 21:30:47] Command:
[01/17/2019 21:30:47] Command:
[01/17/2019 21:30:47] Command:
[01/17/2019 21:30:47] Command: _ADSKGREETING_quit
[01/17/2019 21:30:47] Unknown command "ADSKGREETING_QUIT".  Press F1 for help.
[01/17/2019 21:31:47] Error: AutoCAD Core Console is shut down due to timeout.
[01/17/2019 21:31:47] End script phase.
[01/17/2019 21:31:47] Error: An unexpected error happened during phase CoreEngineExecution of job.
[01/17/2019 21:31:47] Job finished with result FailedExecution

我认为脚本没问题,因为我可以 运行 通过在我的计算机上使用 AutoCAD 成功地执行此操作:

NETLOAD -> select MyFirstProject.dll 文件 -> ADSKGREETING

我的脚本中是否缺少某些内容?我是否必须包含退出脚本的命令?如果是这样,如何?

是也不是。如果在终止阶段没有要执行的任务,只需将处理程序留空即可。但是您仍然需要在脚本的开头指定必要的程序集属性。有关详细信息,请参阅 here

[assembly: CommandClass(typeof(MyFirstProject.Class1))]
[assembly: ExtensionApplication(null)]

namespace ...

我认为您的问题很简单,就是缺少 space 或在 ADSKGREETING 命令末尾输入。请将 ADSKGREETING 更改为 ADSKGREETING\n 您的 Activity 定义。

创建 activity 时,您的命令行应包含 /al 参数,该参数用于在启动 accoreconsole 时加载您的包。

像这样:

{
 "id": "{{activity name}}",
 "commandLine": "$(engine.path)/accoreconsole.exe /i \"$(args[InputFile].path)\" /s \"$(settings[script].path)\" /al \"$(appbundles[{{appBundle Name}}].path)\""
...
}