AnsweredAssumed Answered

Add .dwg file to Map using Code

Question asked by veroniquexie2008 on Apr 12, 2016
Latest reply on Apr 13, 2016 by veroniquexie2008

     One of our customers have thousands of CAD .dwg files. The need an function on the Web that they can provide a .dwg file name, and get an .PDF file.

    Export to PDF  from .mxd or .lyr file is quite easy.  The problem is how to make an .mxd or .lyr file from a .dwg file.

    Of cause I can using ArcMap, add .dwg file using the Add Data Dialog. As I learn from the Desktop Help:

    "When you add CAD data to a map document, features are drawn to match the CAD drawing's original symbology as closely as possible. The default CAD renderer draws CAD features by unique values combining line type, color, and line weight properties."

    And I got a map like this, it's pretty good:

   1.png

 

  The problem is  we need to automate the process. so we using the flowing code to add the Cad Drawing to the Map:

 

  Set pCadDrawingDataset = GetCadDataset("d:\data\cad", "e-51878.dwg")

    If pCadDrawingDataset Is Nothing Then Exit Sub

    Set pCadLayer = New CadLayer

    Set pCadLayer.CadDrawingDataset = pCadDrawingDataset

    pCadLayer.Name = "e-51878.dwg"

    pMxDoc.FocusMap.AddLayer pCadLayer

 

It works, but the map looked like this:

 

   2.png

The line color is OK, but the  Annotation is too big compares the the first image, and the whole dwg file becomes one layer.  Since it is become one layer, we can not modify the display of the annotation.

      Of cause we can add the .dwg layer by layer using  .dwg:polyline, .dwg:polygon.  But this method can not do the automatic symbolization.

 

So my question is : Is it possible to do the "Add Data to Map"  by the ArcObjects Code? So that I can get the first map. I know there is a IAddDataDialog, but it will popup an dialog.

 

ArcMap using a special renderer for CAD .dwg file, it is very difficult to do it in Code:

 

3.png

Outcomes