Summary
Converts one or more multipatch features into a collection of COLLADA (.dae) files and referenced texture image files in an output folder. The inputs can be a layer or a feature class.
Usage
COLLADA files are an XML representation of a 3D object that can reference additional image files that act as textures draped onto the 3D geometry. This means that exporting a multipatch feature to COLLADA can result in the creation of several files—a .dae file containing the XML representation of the 3D object and one or more image files (for example, a .jpg or .png file) that contain the textures.
This tool creates one COLLADA representation for each multipatch feature that it exports. The tool uses a field value from each feature—by default, this is the Object ID—to define the output file names. This allows easier identification of which feature was exported to which COLLADA file and also provides the methodology for defining unique names when exporting multiple features to the same directory. Texture files are stored in the same directory as the COLLADA file. To minimize the total export file size, textures that are used in multiple COLLADA files—such as a repeated brick or window texture—are only exported once and then referenced by the applicable DAE files.
This tool automatically overwrites any existing COLLADA files with the same file name. When this happens, a warning message is given stating which files were overwritten with a new file during the export process. A GP message is also generated for any features that fail to export—for example, if the output location is read-only, or the disk is full.
To ensure a new COLLADA file is created for all the exported multipatch features, set the destination directory to an empty or new folder and choose a file name field that is unique for each feature. Exporting two features with the same attribute value will result in the second exported feature overwriting the COLLADA file of the first.
When iteratively updating a multipatch feature by exporting it to COLLADA and making changes outside of ArcGIS, export the feature to the same location each time. This will keep a single file on disk for that feature, representing the most up-to-date state of the 3D object.
If the exported multipatch is in a projected coordinate system, such as a building stored in a UTM zone, then a KML file containing the coordinates as WGS84 will also be created in the output folder. Note that this process will not use a datum transformation, which may result in positional discrepancies when viewing the KML.
Syntax
MultipatchToCollada(in_features, output_folder, {prepend_source}, {field_name})
Parameter | Explanation | Data Type |
in_features | The multipatch features to be exported. | Feature Layer |
output_folder | The destination folder where the output COLLADA files and texture image files will be placed. | Folder |
prepend_source (Optional) | Prepend the file names of the output COLLADA files with the name of the source feature layer.
| Boolean |
field_name (Optional) | The feature attribute to use as the output COLLADA file name for each exported feature. If no field is specified, the feature's Object ID is used. | Field |
Code sample
MultipatchToCollada example 1 (Python window)
The following sample demonstrates the use of this tool in the Python window.
import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.MultipatchToCollada_conversion("Sample.gdb/Buildings", "C:/COLLADA",
"PREPEND_SOURCE_NAME", "BldName")
MultipatchToCollada example 2 (stand-alone script)
The following sample demonstrates the use of this tool in a stand-alone Python script.
'''*********************************************************************
Name: Convert Multipatch To Collada
Description: Converts multipatch features in an input workspace
to a Collada model.
*********************************************************************'''
# Import system modules
import arcpy
import exceptions, sys, traceback
from arcpy import env
# Script variables
inWorkspace = arcpy.GetParameterAsText(0)
try:
# Set environment settings
env.workspace = inWorkspace
# Create list of feature classes in workspace
fcList = arcpy.ListFeatureClasses()
# Determine if the list contained any feature classes
if fcList:
# Iterate through each feature class
for fc in fcList:
# Describe the feature class
desc = arcpy.Describe(fc)
# Determine if feature class is a multipatch
if desc.shapeType is 'MultiPatch':
# Ensure unique name for output folder
outDir = arcpy.CreateUniqueName('collada_dir')
# Specify that collada file is prefixed by source name
prepend = 'PREPEND_SOURCE_NAME'
# Specify the feature attribute used to name Collada files
fldName = 'OID'
#Execute MultipatchToCollada
arcpy.MultipatchToCollada(fc, outDir, prepend, fldName)
else:
print 'There are no feature classes in {0}.'.format(inWorkspace)
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)
Environments
This tool does not use any geoprocessing environments.
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes