2

I am working on a script (to publish as a geoprocessing service) that will take multiple feature layers and use them as inputs to the ExportCAD_Conversion tool.

What I ultimately want is a set of checkboxes that allow the user to check which layers they want converted into CAD (from a list of about 10 features).

I saw somebody mention using something like this:

import arcpy

Feature = "C:\FeatureLocation"

    FeatureCheck = arcpy.GetParameterAsText(0)

    if str(FeatureCheck) == "C:\FeatureLocation":
            arcpy.AddMessage("Feature")
            result = arcpy.Exists(Feature)

    Feature2 = "C:\Feature2Location"

    Feature2Check = arcpy.GetParameterAsText(1)

    if str(Feature2Check) == "C:\Feature2Location":
            arcpy.AddMessage("Feature2")
            result = arcpy.Exists(Feature2)


    arcpy.ExportCAD_conversion([FeatureCheck,Feature2Check], "DWG_R2010", r"C:\dwg\test.dwg", "Ignore_Filenames_in_Tables", "Append_To_Existing_Files", "")

This only got me an error that said "Dataset true does not exist or is not supported"

Am I going down the right path?

0
1

Try this:

import arcpy

features_to_export = []
features = ["C:\FeatureLocation", "C:\Feature2Location"]

for n, filepath in enumerate(features):
    if bool(arcpy.GetParameterAsText(n)) and arcpy.Exists(filepath):
        features_to_export.append(filepath)

if len(features_to_export) > 0:
    arcpy.conpversion.ExportCAD(
        in_features=features_to_export, 
        Output_type="DWG_R2010", 
        Output_file=r"C:\dwg\test.dwg", 
        Ignore_FileNames="Ignore_Filenames_in_Tables", 
        Append_To_Existing="Append_To_Existing_Files"
    )

Here's a break down:

features_to_export = []
features = ["C:\FeatureLocation", "C:\Feature2Location"]

We don't know how many things we'll export, so make that an empty list that we'll append to. The features variable is a list off all possible features that might get exported.

for n, filepath in enumerate(features):
    if bool(arcpy.GetParameterAsText(n)) and arcpy.Exists(filepath):
        features_to_export.append(filepath)

Loop through all possible features, keeping track of their index in the variable n, which we use to get the state of the checkbox. if the box is checked and the file exists, append that feature of to our list of thinks to be exported.

if len(features_to_export) > 0:
    arcpy.conpversion.ExportCAD(
        in_features=features_to_export, 
        Output_type="DWG_R2010", 
        Output_file=r"C:\dwg\test.dwg", 
        Ignore_FileNames="Ignore_Filenames_in_Tables", 
        Append_To_Existing="Append_To_Existing_Files"
    )

If we actually have something to export, do it, using named arguments instead of Esri's absurd style of empty positional arguments.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.