首页 > 解决方案 > 使用 .NET 创建的自定义 CAD 脚本是否需要退出命令?

问题描述

我正在尝试使用设计自动化 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 发布 AppPackage、发布 Activity 和发布 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-> 选择 MyFirstProject.dll 文件 ->ADSKGREETING

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

标签: autodesk-forgeautodesk-designautomation

解决方案


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

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

namespace ...

推荐阅读