Accessing members that control the CAD drawing dataset
To access members that control the CAD drawing dataset, perform the following steps:
-
Instantiate a CAD Workspace Factory.
-
Get the file workspace by accessing the directory that contains the CAD file.
-
Cast the IWorkspace interface to ICadDrawingWorkspace.
-
Open the CAD drawing dataset by providing it the name of a CAD file, and set it to ICadDrawingDatatset.
-
Print whether or not the CAD file exists and print the full path name of the CAD file by accessing the ICadDrawingDataset members.
-
Instantiate a CadLayer.
-
Set the CadLayer CadDrawingDataset property to ICadDrawingDataset.
-
Print the property values, such as Is2d, Is3d, IsAutoCad and IsDGN, by accessing the members of CadLayer.
See the following code:
[C#] // Set variables for the path and filename.
String nameOfPath="C:\\data\\CAD";
String nameOfCADFile="PARCELS.DWG";
//Set the workspace.
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWorkspaceFact=new
ESRI.ArcGIS.DataSourcesFile.CadWorkspaceFactory();
//Open the workspace.
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace=pWorkspaceFact.OpenFromFile
(nameOfPath, 0);
//Get the CADDrawingWorkspace.
ESRI.ArcGIS.DataSourcesFile.ICadDrawingWorkspace pCadDwgWorkspace;
pCadDwgWorkspace=(ESRI.ArcGIS.DataSourcesFile.ICadDrawingWorkspace)pWorkspace;
//Open the CadDrawingDataset.
ESRI.ArcGIS.DataSourcesFile.ICadDrawingDataset pCadDwgDataset;
pCadDwgDataset=pCadDwgWorkspace.OpenCadDrawingDataset(nameOfCADFile);
//Get and print Exists and Filepath.
System.Console.WriteLine("Exists={0}", pCadDwgDataset.Exists);
System.Console.WriteLine("FilePath={0}", pCadDwgDataset.FilePath);
//Open the CadLayer interface.
ESRI.ArcGIS.Carto.ICadLayer pCadLayer=new ESRI.ArcGIS.Carto.CadLayer()as
ESRI.ArcGIS.Carto.ICadLayer;
//Get the CadDrawingDatsaset.
pCadLayer.CadDrawingDataset=pCadDwgDataset;
//Get and print the property value for IS2D.
System.Console.WriteLine("Is2d={0}", pCadLayer.Is2d);
//Get and print the property value for IS3D.
System.Console.WriteLine("Is3d={0}", pCadLayer.Is3d);
//Get and print the property value for IsAutoCAD.
System.Console.WriteLine("IsAutoCAD={0}", pCadLayer.IsAutoCad);
//Get and print the property value for IsDgn.
System.Console.WriteLine("IsDgn={0}", pCadLayer.IsDgn);
[VB.NET] ' Set variables for the filename and feature class.
Dim nameOfPath As String="C:\\arcgis\\ArcTutor\\Editor\\ExerciseData\\EditingCAD"
Dim nameOfCADFile As String="PARCELS.DWG"
'Set the Workspace Factory.
Dim pWorkspaceFact As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory=New ESRI.ArcGIS.DataSourcesFile.CadWorkspaceFactory()
'Open the workspace.
Dim pWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace=pWorkspaceFact.OpenFromFile(nameOfPath, 0)
'Get the CADDrawingWorkspace.
Dim pCadDwgWorkspace As ESRI.ArcGIS.DataSourcesFile.ICadDrawingWorkspace
pCadDwgWorkspace=DirectCast(pWorkspace, ESRI.ArcGIS.DataSourcesFile.ICadDrawingWorkspace)
'Open the CadDrawingDataset.
Dim pCadDwgDataset As ESRI.ArcGIS.DataSourcesFile.ICadDrawingDataset
pCadDwgDataset=pCadDwgWorkspace.OpenCadDrawingDataset(nameOfCADFile)
'Get and print Exists and Filepath.
System.Console.WriteLine("Exists={0}", pCadDwgDataset.Exists)
System.Console.WriteLine("FilePath={0}", pCadDwgDataset.FilePath)
'Open the CadLayer interface.
Dim pCadLayer As ESRI.ArcGIS.Carto.ICadLayer=TryCast(New ESRI.ArcGIS.Carto.CadLayer(), ESRI.ArcGIS.Carto.ICadLayer)
'Get the CadDrawingDatsaset.
pCadLayer.CadDrawingDataset=pCadDwgDataset
'Get and print the property value for IS2D.
System.Console.WriteLine("Is2d={0}", pCadLayer.Is2d)
'Get and print the property value for IS3D.
System.Console.WriteLine("Is3d={0}", pCadLayer.Is3d)
'Get and print the property value for IsAutoCAD.
System.Console.WriteLine("IsAutoCAD={0}", pCadLayer.IsAutoCad)
'Get and print the property value for IsDgn.
System.Console.WriteLine("IsDgn={0}", pCadLayer.IsDgn)
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
- ESRI.ArcGIS.Version (ESRI.ArcGIS)
- ESRI.ArcGIS.Carto
- ESRI.ArcGIS.DataSourcesFile
- ESRI.ArcGIS.Display
- ESRI.ArcGIS.Geodatabase
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |