关于在AutoCAD捆绑应用中引用Forge Design Automation JSON信息的问询
Great question! Let's break this down into two key parts: accessing the JSON data from your AutoCAD plugin, and checking for any overlooked filename references in your curl request.
1. Reading the JSON Input in Your AutoCAD Application
When you define an Activity in Design Automation, any input parameters you specify (including your JSON) are downloaded to the task's working directory using the LocalName you set in the Activity definition. This is the filename you'll use to access the JSON from your plugin.
Step-by-Step:
First, confirm your Activity includes an Input for the JSON. For example, your Activity might have a section like this:
"Inputs": [ { "Name": "TaskParameters", "LocalName": "task-settings.json", "Description": "Configuration JSON for the AutoCAD task", "Optional": false, "StorageProvider": "Generic" } ]Here,
LocalName: "task-settings.json"is the filename that will exist in the task's working directory when your plugin runs.In your AutoCAD .NET/ARX plugin, read this file directly from the working directory (Design Automation sets the current working directory to the task's root, so relative paths work):
using System.IO; using Newtonsoft.Json; // Or your preferred JSON serializer // Read the JSON file string jsonFilePath = "task-settings.json"; string jsonContent = File.ReadAllText(jsonFilePath); // Deserialize into your custom class TaskSettings settings = JsonConvert.DeserializeObject<TaskSettings>(jsonContent); // Use the settings in your plugin logic Console.WriteLine($"Processing with scale: {settings.ScaleFactor}");Pro Tip: Avoid hardcoding absolute paths—Design Automation's environment is ephemeral, and the working directory is guaranteed to be the correct location for all input files.
2. Checking for Overlooked Filename References in Your Curl Request
Your curl request needs to map the JSON input to the Activity's defined Input parameter. The most common oversight here is mismatching the parameter name in your curl Arguments with the Name field in your Activity's Input definition.
Example Curl Request (with JSON Input):
curl -X POST "https://developer.api.autodesk.com/da/us-east/v3/WorkItems" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -d '{ "ActivityId": "YourCompany.YourActivity+Alias", "Arguments": { "TaskParameters": { // This MUST match the "Name" in your Activity's Input "Url": "https://your-oss-bucket.s3.amazonaws.com/your-settings.json", "Headers": { "Authorization": "Bearer YOUR_SIGNED_OSS_URL_TOKEN" } }, "InputDwg": { "Url": "https://your-oss-bucket.s3.amazonaws.com/input-file.dwg", "Headers": { "Authorization": "Bearer YOUR_SIGNED_OSS_URL_TOKEN" } }, "OutputDwg": { "Url": "https://your-oss-bucket.s3.amazonaws.com/output-file.dwg", "Headers": { "Authorization": "Bearer YOUR_SIGNED_OSS_URL_TOKEN" }, "Verb": "put" } } }'
Key Things to Verify:
- The
Argumentskey (TaskParametersin the example) exactly matches theNameof the JSON Input in your Activity. - The
Urlin the curl argument points to your JSON file hosted in Autodesk OSS (or another supported storage provider), with a valid signed token for access. - You haven't mixed up
LocalName(used in your plugin) with the Input'sName(used in the curl request)—these are two distinct values.
Common Mistakes to Double-Check
- Forgetting to include the JSON Input in your Activity definition entirely.
- Using the wrong filename in your plugin (not matching the
LocalNamefrom the Activity). - Failing to sign the JSON file's URL in your curl request, leading to access denied errors.
内容的提问来源于stack exchange,提问作者Charles Dodson

