How to get subtypes from tables in arcobjects

615
5
09-10-2019 08:38 AM
Ruben_DarioCalero_Clavijo
New Contributor

Hello

Everyone

I have a problem to get the subtypes from tables in arcmap with the arcobjects library in C# (sharp) lenguage.

So i need that someone could help me with some code example.

Appreciating the attention

0 Kudos
5 Replies
DuncanHornby
MVP Frequent Contributor

Have a look at this page on the API help file, whilst it's about creating subtypes you should be able to figure out how to access existing subtypes.

0 Kudos
WeifengHe
Occasional Contributor II
public void GetSubtypes(IFeatureClass featureClass) {     // Cast the feature class to the ISubtypes interface.    ISubtypes subtypes = (ISubtypes)featureClass;      // then you can enumeraate subtypes.    IEnumSubtype enumSubtype = subtypes.Subtypes
}
0 Kudos
Ruben_DarioCalero_Clavijo
New Contributor

Hi Duncan and Weifeng and thanks for the answer

I have been working in the next code to get all Subtypes from a table in a single string that concatenate. But I can not put it to works it correctly.

I attached it in the form of an image and text but its the same code.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

IDocument docRDC = m_application.Document;
IMxDocument mxdocRDC = docRDC as IMxDocument;

string esFeature = "";
string esTable = "";

if (mxdocRDC.SelectedItem is IFeatureLayer2)
{
esFeature = "Si";
MessageBox.Show("Es IFeaturelayer2");
}

if (mxdocRDC.SelectedItem is ITable)
{
esTable = "Si";
MessageBox.Show("Es Itable");
}

ITable table = mxdocRDC.SelectedItem as ITable;

System.Text.StringBuilder listadosubtipos = new System.Text.StringBuilder();

if (esFeature != "Si" && esTable=="Si")
{
IObjectClass MiObjeClassTabla = table as IObjectClass;
ISubtypes MisSubtypesTabla = (ISubtypes)MiObjeClassTabla;
IEnumSubtype enumSubtypeTabla;
int subtypeCodeTabla;
string subtypeNameTabla;


if (MisSubtypesTabla.HasSubtype)
{
enumSubtypeTabla = MisSubtypesTabla.Subtypes;
subtypeNameTabla = enumSubtypeTabla.Next(out subtypeCodeTabla);

while (subtypeNameTabla != null)
{
listadosubtipos.Append(subtypeNameTabla);
listadosubtipos.Append(", ");
subtypeNameTabla = enumSubtypeTabla.Next(out subtypeCodeTabla);
}
}

textBox3.Text = Convert.ToString(listadosubtipos);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thanking any help

0 Kudos
Ruben_DarioCalero_Clavijo
New Contributor
IDocument docRDC = m_application.Document;
IMxDocument mxdocRDC = docRDC as IMxDocument;

string esFeature = "";
string esTable = "";

if (mxdocRDC.SelectedItem is IFeatureLayer2)
{
esFeature = "Si";
MessageBox.Show("Es IFeaturelayer2");
}

if (mxdocRDC.SelectedItem is ITable)
{
esTable = "Si";
MessageBox.Show("Es Itable");
}

ITable table = mxdocRDC.SelectedItem as ITable;

System.Text.StringBuilder listadosubtipos = new System.Text.StringBuilder();

if (esFeature != "Si" && esTable=="Si")
{
IObjectClass MiObjeClassTabla = table as IObjectClass;
ISubtypes MisSubtypesTabla = (ISubtypes)MiObjeClassTabla;
IEnumSubtype enumSubtypeTabla;
int subtypeCodeTabla;
string subtypeNameTabla;


if (MisSubtypesTabla.HasSubtype)
{
enumSubtypeTabla = MisSubtypesTabla.Subtypes;
subtypeNameTabla = enumSubtypeTabla.Next(out subtypeCodeTabla);

while (subtypeNameTabla != null)
{
listadosubtipos.Append(subtypeNameTabla);
listadosubtipos.Append(", ");
subtypeNameTabla = enumSubtypeTabla.Next(out subtypeCodeTabla);
}
}

textBox3.Text = Convert.ToString(listadosubtipos);
}
0 Kudos
Ruben_DarioCalero_Clavijo
New Contributor

what I am looking for is to get all the subtypes of a stand-alone table. The code "IFeatureClass" it is no working with stand-alone table.

0 Kudos