Select to view content in your preferred language

Adding a feature class to a 3D Layer in Map_3D

1444
4
09-23-2016 03:16 AM
MatthiasBuehler
Deactivated User

Hi,

[ ArcGIS PRO 1.3.1 ]

I'm a bit stuck with arcpy when adding a feature class in the Map_3D viewer as a layer. Basically I'm trying to emulate the same thing that happens when drag-n-dropping a FC into the Contents pane, resp. the Map_3D viewer.

Code so far ..

import arcpy
aprx = arcpy.mp.ArcGISProject(pPath + pName)

fc = gdbPath + gdbName + '/myFeatureClass'
lyr = arcpy.MakeFeatureLayer_management(fc, 'myLayer')

for map in aprx.listMaps():
   if map.mapType == 'SCENE':
      map.addLayer(lyr, add_position = 'AUTO_ARRANGE')

But this produces an error .. What am I missing?

Thanks for any input!

Matt

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

are your variables defined somewhere else? ppath, pname, gdbpath, gdbname etc

this seems like a question rather than a discussion

0 Kudos
MatthiasBuehler
Deactivated User

Hi,

Yes, they are defined as:

pPath            = project Path on disk (e.g. 'D:/..')

pName          = project file name ('.aprx')

gdbName      = path to GDB (usually sitting in the project path)

gdbName      = GDB name

It indeed may be more a question, sorry about that..

matt

0 Kudos
DanPatterson_Retired
MVP Emeritus

Well the reason I asked is because the error isn't specified and there is no way to check what it might be since the error may be due to the values of the parameters.

0 Kudos
MatthiasBuehler
Deactivated User

Ok, true. This is the error:

Traceback (most recent call last):
File "Y:\..\pyScripts\createCables.py", line 25, in <module>
cc.createCables(pPath, pName, gdbPath, gdbName, pfc, mfc, rpk, lfc, a)
File "Y:\..\cableCode.py", line 456, in createCables
map.addLayer(lyr, add_position = 'AUTO_ARRANGE')
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1041, in addLayer
return convertArcObjectToPythonObject(self._arc_object.addLayer(*gp_fixargs((add_layer_or_layerfile, add_position), True)))
ValueError: myLayer
Failed to execute (createCables).

0 Kudos