Search code examples
autodesk-forgeautodesk-designautomation

How to import dxf into a dwg using Autodesk Forge


I have implemented a viewer using Autodesk Platform Services (former name Forge) on .NET Core. In the bucket I upload 2D drawings in .dwg format.

I enabled the markup feature in the viewer, so now I can make any markup on top of the .dwg

What I have for the moment looks like this: enter image description here

I need to save this dwg with the markups I did, and either have it as a 2nd dwg inside the bucket or to override the original one.

The steps I have taken until now:

  • In javascript behind I can get the markups only as .svg format using the .generateData() on the MarkupsCore extension:

    const markupCore = await viewer.loadExtension('Autodesk.Viewing.MarkupsCore');

    let svgMarkup = markupCore.generateData();

  • After getting the svg mark up, I convert it in .dxf file.

I think I need to use the Design Automation API to import this dxf file into the dwg, but I don't know how to handle this.

I have checked the following link on importing dxf into dwg but so far I can't find something for my case.

AutoDesk Design Automation tutorials on autocad

In case someone knows maybe another way on handling this, please let me know.


Solution

  • I think I need to use the Design Automation API to import this dxf file into the dwg, but I don't know how to handle this.

    Yes that is correct, you may insert the dxf into the main drawing, you should be knowing scaling and position, so that will placed correctly on top your drawing.

    Activity

    {
        "id": "{{ _.activityId }}",
        "commandLine": [
            "$(engine.path)\\accoreconsole.exe /i \"$(args[main].path)\" /s $(settings[script].path)"
        ],
        "parameters": {
            "main": {
                "verb": "get",
                "description": "test",
                "required": true,
                "localName": "$(inputFile)"
            },
            "overlay": {
                "verb": "get",
                "description": "",
                "required": true,
                "localName": "markups.dxf"
            },
            "result": {
                "verb": "put",
                "description": "",
                "required": true,
                "localName": "result.dwg"
            }
        },
        "engine": "Autodesk.AutoCAD+24_1",
        "description": "import markups",
        "settings": {
            "script": "-insert\nmarkups.dxf\n4,1,0\n1\n1\n0\nsaveas\n2018\nresult.dwg\n"
        }
    }
    

    WorkiItem

    {
        "activityId": "{{ _.nickName }}.{{ _.activityId }}+{{ _.alias }}",
        "arguments": {
            "main": {
                "url": "urn:adsk.objects:os.object:madlybuckets/main.dwg",
                "verb": "get",
                "headers": {
                    "Authorization": "Bearer {{ _.oAuthToken }}"
                }
            },
            "overlay": {
                "url": "urn:adsk.objects:os.object:madlybuckets/markups.dxf",
                "verb": "get",
                "headers": {
                    "Authorization": "Bearer {{ _.oAuthToken }}"
                }
            },
            "result": {
                "verb": "put",
                "url": "urn:adsk.objects:os.object:madlybuckets/result.dwg",
                "headers": {
                    "Authorization": "Bearer {{ _.oAuthToken }}"
                }
            }
        }
    }
    

    Here the main.dwg, markups.dxf is uploaded to APS Object Storage Service so that I can directly use object id of uploaded files instead of passing the object URL to the workitem.