The following VB code, taken almost verbatim from the Map 3D Object ARX .Net Developer's Guide, doesn't compile for Map 3D 2014 (didn't test it for other versions).
Here's the compiler error:
Error 10 'SetDefaultValue' is not a member of 'Autodesk.Gis.Map.ObjectData.FieldDefinition'. C:\Users\jdutz\Documents\Visual Studio Projects\C3D_2014\MH_ParcelTools\ClassLibrary2\Class1.vb 17 9 ClassLibrary2
The error appears to be because the SetDefaultValue method isn't defined. Is there a workaround?
Imports Autodesk.Gis.Map
Imports Autodesk.Gis.Map.Project
Imports Autodesk.Gis.Map.ObjectData
Public Class Class1
Private Sub Sub1()
Dim mapApp As MapApplication
mapApp = HostMapApplicationServices.Application
Dim fieldDefs As ObjectData.FieldDefinitions
fieldDefs = _
mapApp.ActiveProject.MapUtility.NewODFieldDefinitions()
Dim def1 As ObjectData.FieldDefinition
def1 = fieldDefs.Add("FIRST_FIELD", "Owner name", _
Autodesk.Gis.Map.Constants.DataType.Character, 0)
def1.SetDefaultValue("A")
Dim def2 As ObjectData.FieldDefinition
def2 = fieldDefs.Add("SECOND_FIELD", "Assessment year", _
Autodesk.Gis.Map.Constants.DataType.Integer, 1)
def2.SetDefaultValue(0)
End Sub
End Class
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
I think the sample code from AutoCAD Map ObjectARX SDK's document/dev. guide is out-dated. The documentation on AutoCAD Map development has been particularly known for its not being updated.
The oldest AutoCAD Map version I currently has access is AutoCAD Map 2012, and indeed the ObjectData.FieldDefinition class does not have the method SetDefaultValue(). This method must have been there when first AutoCAD Map .NET API avialble in Map 2006 and was removed in later version.
Anyway, to create a FieldDefinition with default value, you can use FieldDefinition's static method Create() and then add the FieldDefinition into the FieldDefinitions collection:
Dim field As FieldDefinition= _
FieldDefinition.Create("MyField1","This is the field for...", "This is default text value") ''The last parameter could be String, Integer, Doule...
MyOdTable.FieldDefinitions.AddColumn(field,0)
Norman Yuan