Create new dwg file and load existing dwg model in it using Autodesk Design Automation API for AutoCAD

huangapple go评论53阅读模式
英文:

Create new dwg file and load existing dwg model in it using Autodesk Design Automation API for AutoCAD

问题

使用Autodesk Design Automation API for AutoCAD如何以编程方式创建新的DWG文件并将现有的DWG模型加载到其中?

我正在开展一个项目,需要我自动化在AutoCAD中创建新的DWG文件,然后使用Autodesk Design Automation API加载现有的DWG模型。目标是在没有任何手动干预的情况下自动化整个过程。

我在实施所需步骤时遇到了一些困难,需要创建新的DWG文件并将现有的DWG模型加载到其中。

是否有人可以提供示例代码或详细的逐步说明,说明如何使用Autodesk Design Automation API for AutoCAD 2022以编程方式创建新的DWG文件并将现有的DWG模型加载到其中?如果解决方案包括来自Autodesk Design Automation API的必要方法和属性,那将非常好。

我将非常感激在这个问题上的任何帮助或指导。

输入模型DWG文件

我们有这个球阀模型作为输入,我们希望创建一个新的DWG文件,添加页面边框,并使用设计自动化API将这个现有的DWG模型加载到页面边框中。

期望的输出:

期望的输出DWG文件

英文:

How to programmatically create a new DWG file and load an existing DWG model into it using Autodesk Design Automation API for AutoCAD?

I am working on a project that requires me to automate the process of creating a new DWG file in AutoCAD and then load an existing DWG model into it using Autodesk Design Automation API. The goal is to automate the entire process without any manual intervention.

I am facing some difficulties in implementing the steps required to create a new DWG file and load an existing DWG model into it.

Can anyone provide a sample code or a detailed step-by-step explanation of how to programmatically create a new DWG file and load an existing DWG model into it using Autodesk Design Automation API for AutoCAD 2022? It would be great if the solution includes the necessary methods and properties to be used from the Autodesk Design Automation API.

I would highly appreciate any help or guidance in this matter.

input model dwg file

We have this ball valve model as input , we want to create a new dwg file add page border and load this existing dwg model inside page border using design automation api.

Expected Output :

expected output dwg file

答案1

得分: 0

我鼓励你阅读此教程https://tutorials.autodesk.io/tutorials/design-automation/,你的目标应该是可能的,你需要启动带有你的边框图纸的accoreconsole实例,并从其他图纸中插入块。
您可以将从外部图纸导入块的逻辑封装在自定义命令中。
参考https://through-the-interface.typepad.com/through_the_interface/2006/08/import_blocks_f.html
以下是一个示例活动,从“blocks.dwg”中导入“Microwave”块并插入“border.dwg”中。

活动:

{
"id": "{{ _.activityId }}",
"commandLine": [
"$(engine.path)\accoreconsole.exe "$(args[main].path)" /s $(settings[script].path)"
],
"parameters": {
"main": {
"verb": "get",
"description": "要加载到AutoCAD中的主绘图。",
"required": true,
"localName": "border.dwg"
},
"blocks": {
"verb": "get",
"description": "包含块的绘图",
"required": true,
"localName": "blocks.dwg"
},
"BlockName": {
"verb": "read",
"description": "要插入的块名称。",
"required": true
},
"BlockPosition": {
"verb": "read",
"description": "要插入块的位置"
},
"ScaleX": {
"verb": "read",
"description": "X比例因子",
"required": true
},
"ScaleY": {
"verb": "read",
"description": "Y比例因子",
"required": true
},
"Rotation": {
"verb": "read",
"description": "块的旋转角度",
"required": true
},
"result": {
"verb": "put",
"description": "",
"required": true,
"localName": "result.dwg"
}
},
"engine": "Autodesk.AutoCAD+23_1",
"description": "blah",
"settings": {
"script": "ImportBlocks\n"$(args[BlockName].value)"\n"$(args[BlockPosition].value)"\n"$(args[ScaleX].value)"\n"$(args[ScaleX].value)"\n"$(args[ScaleY].value)"\n"$(args[Rotation].value)"\n_SAVEAS\n2018\nresult.dwg\n"
}
}

Workitem

{
"activityId": "{{ _.nickName }}.{{ _.activityId }}+{{ _.alias }}",
"arguments": {
"main": {
"verb": "get",
"url": "urn:adsk.objects:os.object:madlybuckets/main.dwg",
"headers": {
"Authorization": "Bearer {{ _.oAuthToken }}"
}
},
"blocks": {
"verb": "get",
"url": "urn:adsk.objects:os.object:madlybuckets/blocks.dwg",
"headers": {
"Authorization": "Bearer {{ _.oAuthToken }}"
}
},
"BlockName": "Microwave",
"BlockPosition": "198.241 162.455 0.0",
"ScaleX": "1.0",
"ScaleY": "1.0",
"Rotation": "0.0",
"result": {
"verb": "put",
"url": "urn:adsk.objects:os.object:madlybuckets/result.dwg",
"headers": {
"Authorization": "Bearer {{ _.oAuthToken }}"
}
}
}
}

英文:

I would encourage you to go through this tutorial https://tutorials.autodesk.io/tutorials/design-automation/, your objective should possible, you need to launch accoreconsole instance with your border drawing and insert the block from other drawing.
You can wrap the logic of importing blocks from external drawing in custom command .
Refer https://through-the-interface.typepad.com/through_the_interface/2006/08/import_blocks_f.html
Below is an example activty that importas "Microwave" block from "blocks.dwg" and inserts in "border.dwg"

Activity:

{
	"id": "{{ _.activityId }}",
	"commandLine": [
		"$(engine.path)\\accoreconsole.exe  \"$(args[main].path)\" /s $(settings[script].path)"
	],
	"parameters": {
		"main": {
			"verb": "get",
			"description": "Main drawing to be loaded into AutoCAD.",
			"required": true,
			"localName": "border.dwg"
		},
		"blocks": {
			"verb": "get",
			"description": "The drawing which contains the blocks",
			"required": true,
			"localName": "blocks.dwg"
		},
		"BlockName": {
			"verb": "read",
			"description": "The block name to insert.",
			"required": true
		},
		"BlockPosition": {
			"verb": "read",
			"description": "The position to insert block"
		},
		"ScaleX": {
			"verb": "read",
			"description": "The X scale factor",
			"required": true
		},
		"ScaleY": {
			"verb": "read",
			"description": "The Y scale factor",
			"required": true
		},
		"Rotation": {
			"verb": "read",
			"description": "The rotation angle of block",
			"required": true
		},
		"result": {
			"verb": "put",
			"description": "",
			"required": true,
			"localName": "result.dwg"
		}
	},
	"engine": "Autodesk.AutoCAD+23_1",
	"description": "blah",
	"settings": {
		"script": "ImportBlocks\n"$(args[BlockName].value)\"\n\"$(args[BlockPosition].value)\"\n\"$(args[ScaleX].value)\"\n\"$(args[ScaleX].value)\"\n\"$(args[ScaleY].value)\"\n\"$(args[Rotation].value)\"\n_SAVEAS\n2018\nresult.dwg\n"
	}
}

Workitem

{
	"activityId": "{{ _.nickName }}.{{ _.activityId }}+{{ _.alias }}",
	"arguments": {
		"main": {
			"verb": "get",
			"url": "urn:adsk.objects:os.object:madlybuckets/main.dwg",
			"headers": {
				"Authorization": "Bearer {{ _.oAuthToken }}"
			}
		},
		"blocks": {
			"verb": "get",
			"url": "urn:adsk.objects:os.object:madlybuckets/blocks.dwg",
			"headers": {
				"Authorization": "Bearer {{ _.oAuthToken }}"
			}
		},
		"BlockName": "Microwave",
		"BlockPosition": "198.241 162.455 0.0",
		"ScaleX": "1.0",
		"ScaleY": "1.0",
		"Rotation": "0.0",
		"result": {
			"verb": "put",
			"url": "urn:adsk.objects:os.object:madlybuckets/result.dwg",
			"headers": {
				"Authorization": "Bearer {{ _.oAuthToken }}"
			}
		}
	}
}
}

huangapple
  • 本文由 发表于 2023年2月8日 14:13:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381976.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定