Unable to programmatically add (and activate Elevation and Extrusion) 3d layer to local Scene Using ArcPy

149
1
3 weeks ago
Alex_Devoid
New Contributor

I have been unable to programmatically add (and activate Elevation and Extrusion properties) a layer to the 3d section of a local Scene Using ArcPy.

I am able to programmatically set elevation and extrusion properties for layers in a scene, but I have not been able to programmatically add these layers to a 3d scene. Despite setting the elevation and extrusion properties, the layers do not display in 3D until I manually move them from the "2d" section to the "3d" section. Then to activate the elevation properties so they display appropriately I must open the layer properties dialog, go to the Elevation tab, open the expression dialog where I see my programmatically set expression and click OK. (without making any changes to the expression).

 

 

 

 

 


Again, when I inspect the properties of the layer, the elevation and extrusion properties are set correctly, but it's like they are not activated (especially in the case of elevation, as I have to click OK through the elevation dialogs without changing anything for it to take effect. )

aprx = arcpy.mp.ArcGISProject("CURRENT")
local_scene = next((scene for scene in aprx.listMaps() if scene.name == "The3DSceneName" and scene.mapType == "SCENE"), None)
group_layer = local_scene.createGroupLayer("TheGroupName")

group_layer_cim = group_layer.getDefinition('V3')
    
group_layer_cim.layer3DProperties = arcpy.cim.CIM3DLayerProperties()

# Setting the layer3DProperties properties
group_layer_cim.layer3DProperties.castShadows = True
#... ect set layer3DProperties
# Push the updated CIM definition back to the group layer
group_layer.setDefinition(group_layer_cim)

#'partition_layer' is previously defined and configured
cim_definition = partition_layer.getDefinition('V3')
cim_definition.layer3DProperties = arcpy.cim.CIM3DLayerProperties()
cim_definition.layer3DProperties.applyAsElevationLayer = True


# Additional code for setting extrusion and elevation...
elevation_definition = arcpy.cim.CIMSymbolizers.CIMExpressionInfo()
elevation_definition.title = "Custom"
elevation_definition.expression = f"$feature.{field2_name} / {user_defined_number}" 
elevation_definition.name = ""
elevation_definition.returnType = "Default"

cim_definition.featureElevationExpressionInfo = elevation_definition


partition_layer.setDefinition(cim_definition)

extrusion_expression = f"([{field1_name}] - [{field2_name}]) / {user_defined_number_meters}"
partition_layer.extrusion('BASE_HEIGHT', extrusion_expression)

local_scene.addLayerToGroup(group_layer, partition_layer, "BOTTOM")

- How can I ensure that the elevation and extrusion settings take effect programmatically without needing to open and close the properties dialog?
- Is there a specific property or method call I am missing that activates or refreshes these settings within a 3D scene?
- By setting the group layer's 3d properties `group_layer_cim.layer3DProperties` in the CIM I am able to programmatically add all layers to the 3d section of the Scene, but the layers within the group are only rendered as 2d, despite having their extrusion properties set. *How can I render all in the 3d Scene as 3d programmatically*?
Any insights or suggestions on how to resolve these issues would be greatly appreciated!

0 Kudos
1 Reply
Tomasz_Tarchalski
New Contributor III

Hi,

your extrusion expression- does it return number ?, can you check first based on one field height value ?

Personally, i have not completely managed to do it in python script, but in notebook opened in arcgis pro --> Yes.

sth lik that:

 

 

p = arcpy.mp.ArcGISProject("CURRENT")
my_scene = p.listMaps("Scene")[0]
print(my_scene.name)
# when it adds THE file but it SHOWS ERROR. what does it mean ? i dont know
try:
    my_scene.addDataFromPath(FC_IN_2D)
except:
    print('skipp error, just continue')
    pass

# get the right layer
lyr = my_scene.listLayers(FC_IN_2D)[0]

# extrue data where H_EXTRUSION is the field name , containing float number
# notice the single quotes also....
lyr.extrusion('MIN_HEIGHT','[H_EXTRUSION]')
# convert to 3D layer MultiPatch, notice that I am applying both
# projeciton horizontal and projection vertical
with arcpy.EnvManager(outputCoordinateSystem='GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],VERTCS["NGF_IGN69",VDATUM["Nivellement_General_de_la_France_IGN69"],PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Meter",1.0]]'):
        arcpy.ddd.Layer3DToFeatureClass(
            in_feature_layer=fc_in,
            out_feature_class=fc_out,
            group_field=None,
            disable_materials="DISABLE_COLORS_AND_TEXTURES"
        )

 

 
0 Kudos