Help with Code!!!!!

669
2
01-03-2013 11:50 AM
MichelleCouden1
Occasional Contributor III
I have a dialog box written in ArcObjects because Python does not have one. The beginning of the code is in ArcObjects and in the middle of the code I need to switch to Python to complete the program. What would be the code to use to move from ArcObjects to Python????
0 Kudos
2 Replies
SteveFang
New Contributor III
If you are using ArcObjects then why not use ESRI.ArcGIS.Geoprocessing library?  Many of the tools available in ArcToolbox are also available via ArcObjects using this library.  Check the sample code below for reference.  On a side note, I thought Python has a very robust GUI library and I would hope combobox is one of the UI controls available.  So you could possibly do what you want in Python also but I don't have much experience in that.

Dim pGP As Geoprocessor = New Geoprocessor
        Dim pFC2FC As FeatureClassToFeatureClass = New FeatureClassToFeatureClass
        Dim pWS As IWorkspace = m_pGbWSF.Open(m_Conn.pgdbProperty, 0)
        Dim pEnumDataset As IEnumDataset
        Dim pDataset As IDataset
        Dim pFC As IFeatureClass
        Dim pQfilter As IQueryFilter = New QueryFilter

        Try
            pEnumDataset = pWS.Datasets(esriDatasetType.esriDTFeatureClass)
            pQfilter.WhereClause = Svc_CatchBasin.c_Fld_Appstatus & " in (1,2,3)"
            pEnumDataset.Reset()
            pDataset = pEnumDataset.Next()

            'Convert any point not 0 to the local archive PGB
            Do Until pDataset Is Nothing
                If pDataset.Name = "CATCH_BASIN_PT" Then
                    pFC = pDataset
                    If pFC.FeatureCount(pQfilter) > 0 Then
                        pFC2FC.in_features = pFC
                        pFC2FC.out_path = m_Conn.archiveProperty.GetProperty("DATABASE")
                        pFC2FC.out_name = "CB_" & Format(Microsoft.VisualBasic.Now, "MMddyy_hhmmss").ToString
                        pFC2FC.where_clause = "[" & Svc_CatchBasin.c_Fld_Appstatus & "]" & " in (1,2,3)"
                        pGP.Execute(pFC2FC, Nothing)
                        Me.m_ArchiveDone = True
                    End If
                    Exit Do
                End If
                pDataset = pEnumDataset.Next()
            Loop
        Catch ex As Exception
            Me.m_ArchiveDone = False
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error - Synchronize (ArchiveComplete)")
        Finally

        End Try
0 Kudos
JasonPike
Occasional Contributor
I wouldn't recommend it, but you could run python scripts from within C# code using IronPython.

This blog entry explains how you can do it. Rather than getting the python code from a text box, you could read it in from your .py file: http://www.secretgeek.net/host_ironpython.asp

I think you'd be much better off to write all of your code in one language or the other, though.
0 Kudos