Select to view content in your preferred language

Layer 3D to feature class

983
1
01-31-2012 06:12 AM
AnthonyTimpson2
Regular Contributor
Hello there,
I am quite new to python and I am just trying to do a simple iteration.

I have Six Feature classes which need to be converted to Multipatch as part of an automated process

I tried getting it done with modelbuilder but it seems that Iterate features does not work with Layer 3d to FC since it needs to look in the TOC for the 3d Polygons rather than the MDB

Would anyone be willing to shed a little light on the python setup needed to run this conversion?
Tags (2)
0 Kudos
1 Reply
AhjungKim
Deactivated User
I batch process Layer 3D to Feature Class, so I authored a Python script that convert all .lyr files in a target folder to feature class.  If you build a script tool, you can click through the process. Hope this helps.
# Import system modules
import arcpy
from arcpy import env
import exceptions, sys, traceback

try:
    # Obtain a license for the ArcGIS 3D Analyst extension
    arcpy.CheckOutExtension("3D")

    # Get input parameter
    inLyr = arcpy.GetParameterAsText (0)
    outFolder = arcpy.GetParameterAsText (1) 
    
    # Set environment settings
    env.workspace = inLyr
    
    # Use the ListFiles method to identify all layer files in workspace
    if arcpy.ListFiles("*.lyr"):
        for lyrFile in arcpy.ListFiles("*.lyr"):
            # Set Local Variables
            #outFC = "Test.gdb/{0}".format(lyrFile[:-4]) #Strips '.lyr' from name
            outFC = outFolder + "/" + lyrFile[:-4]+ "_3D"
            #Execute Layer3DToFeatureClass
            arcpy.Layer3DToFeatureClass_3d(lyrFile, outFC)
    else:
        "There are no layer files in {0}.".format(env.workspace)

except arcpy.ExecuteError:
    print arcpy.GetMessages()
except:
    # Get the traceback object
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    # Concatenate error information into message string
    pymsg = 'PYTHON ERRORS:\nTraceback info:\n{0}\nError Info:\n{1}'\
          .format(tbinfo, str(sys.exc_info()[1]))
    msgs = 'ArcPy ERRORS:\n {0}\n'.format(arcpy.GetMessages(2))
    # Return python error messages for script tool or Python Window
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)
            
        
0 Kudos