I have a floor plan created in HTML Canvas element. I want to generate a .dwg file of the floor plan, so that it can be opened in CAD softwares. I'm not getting enough clue or tutorials on how to take the second step. For the first step, I've managed to get all possible data from HTML Canvas, such as dimensions of the objects, co-ordinates of every element in the 2d plane and so on. Any inputs/pointers would be really helpful. Thanks in advance!

I tried going through Autodesk Forge platform but there is no clear tutorial on how to go about my problem statement.

1

There are 1 best solutions below

1
Madhukar Moogala On

You need to get comfortable with AutoCAD ObjectARX API programming. Start small, like learning how to construct a simple rectangle using dimension data retrieved from your HTML canvas. Determine whether the data is in JSON or another format. You also need to build a mapping data structure to convert your data into a format that AutoCAD can understand.

Please note that the example provided is very superficial, and many details have been omitted. The purpose of the following example is to give you a fair idea of what you will be working on during the onboarding APS Design Automation which ultimately gives you DWG.

For example, you have Polyline on your HTML canvas, you have extracted the data in the form of JSON.

[
  [
    {
      "closed": true,
      "color": "#00ff00",
      "layer": "Freeform",
      "locations": [
        {
          "x": -1550.1759452132346,
          "y": 4887.014246226463,
          "z": 0
        },
        {
          "x": -993.9682927037948,
          "y": 4898.365423687235,
          "z": 0
        },
        {
          "x": -903.1588800491928,
          "y": 4444.318325256378,
          "z": 0
        },
        {
          "x": -1476.3932974313693,
          "y": 4427.291559065221,
          "z": 0
        }
      ],
      "size": 1.3692946877862155,
      "x": 2073.68717853449,
      "y": 7444.259067776275,
      "type": "POLYLINE"
    }
  ]
]

You need to serialize this in to a .NET Object like this,

public class Markup
    {

        [JsonProperty("text", NullValueHandling = NullValueHandling.Ignore)]
        public string Text { get; set; }

        [JsonProperty("locations", NullValueHandling = NullValueHandling.Ignore)]
        public LineCoord[] Locations { get; set; }


        [JsonProperty("closed"), DefaultValue(false)]
        public bool Closed { get; set; }

        [JsonProperty("x", NullValueHandling = NullValueHandling.Ignore)]
        public double XCoord { get; set; }

        [JsonProperty("y", NullValueHandling = NullValueHandling.Ignore)]
        public double YCoord { get; set; }

        [JsonProperty("type")]
        public string Type { get; set; }

        [JsonProperty("layer")]
        public string Layer { get; set; }

        [JsonProperty("color")]
        public string Color { get; set; }

        [JsonProperty("size", NullValueHandling = NullValueHandling.Ignore)]
        public double Size { get; set; }

        [JsonProperty("image")]
        public string RawImage { get; set; }
        public Bitmap Icon
        {
            get
            {
                byte[] arr = Convert.FromBase64String(RawImage);
                MemoryStream ms = new MemoryStream(arr);
                Image streamImage = Image.FromStream(ms);

                return (Bitmap)streamImage;
            }
        }

Then, you need to use AutoCAD .NET SDK to build the polyline.

internal class AcadPolyline : IAcadFeature
    {
        public AcadPolyline (Markup markup, string layerName) : base(markup, layerName) { }

        public override Entity getAcObj()
        {
            Polyline acPoly = new Polyline
            {
                Layer = Layer,
                Closed = m_markup.Closed,
                Transparency = m_markup.Type == "HIGHLIGHT" ? new Transparency(255 / 2) : new Transparency(255),
            };


            for (int i = 0; i < m_markup.Locations.Length; i++)
            {
                acPoly.AddVertexAt(i, new Point2d(m_markup.XCoord + m_markup.Locations[i].XCoord, m_markup.YCoord + m_markup.Locations[i].YCoord), 0, m_markup.Size, m_markup.Size);
            }

            return acPoly;
        }
    }

Once you get comfortable with building an AutoCAD plugin, next step would be understanding the APS Design Automation [FKA Forge].

  1. NET Training

  2. My First AutoCAD Plugin

  3. Developer Documentation

  4. APS Design Automation Tutorial