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.
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 :
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 }}"
}
}
}
}
}