ArcObjects 9.3 transfer layers from ArcMap to ArcScene Automatically

767
6
01-12-2011 02:12 PM
New Contributor III
I am trying to create a macro in ArcMap that transfers layers in ArcMap to ArcScene.  I am able to launch ArcScene with the commanditem function, but still unsure how to run code in ArcScene from ArcMap without any user intervention.  Also, is it possible to launch ArcScene with a specific document from ArcMap?
Answers in VBA would be preferable, but I'll take anything.

Thanks,

Will McInnes
Reply
0 Kudos
6 Replies
MVP Frequent Contributor
Will,

I think you are heading off in the wrong direction... 😉

Below is some sample code that you would put in the on click event of a UIControl in an MXD. The code grabs the first layer in ArcMap, fires up ArcScene and then adds the layer. At this point you have a handle on the root object ISxDocument from which you can do all your stuff.

Make sure you are referencing the esriArcScene library and have the 3D Analyst extension turned on.

Duncan

Public Sub test()
    ' Grab first layer in ArcMap   
    Dim pMXDocument As IMxDocument
    Set pMXDocument = ThisDocument
    Dim pMap As IMap
    Set pMap = pMXDocument.FocusMap
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0)
   
    ' Create an instance of ArcScene   
    Dim pDocument As IDocument
    Set pDocument = New esriArcScene.SxDocument
    Dim pApplication As IApplication
    Set pApplication = pDocument.Parent
    pApplication.Visible = True
   
    ' Add a layer to ArcScene   
    Dim pSXDocument As ISxDocument
    Set pSXDocument = pDocument
    pSXDocument.AddLayer pLayer
End Sub
Reply
0 Kudos
New Contributor III
Thanks for pointing me in the right direction!

The code is opening arcScene just fine, but when it tries to add the layer it just crashes and says "preparing elevation for display". Any ideas?

The layer is selected, because I can use player.name, and it gives me the name of the DEM.

cheers,
Will
Reply
0 Kudos
MVP Frequent Contributor
Will,

May be it's something weird to do with your DEM? Try passing a simple vector layer to it first to see it that works?

Duncan
Reply
0 Kudos
Regular Contributor III
One thing you'll need to be aware of when you do something like this is that ArcMap and ArcScene are running in two separate processes.  Objects from one process should not be used in the other as they are COM objects that are single apartment threaded and will not marshall correctly between processes.  You shouldn't do something like take a layer from ArcMap and add it directly to ArcScene.  If you do so, the layer object is being used in two processes.  The recommended thing to do would be to deep clone the layer object and add the clone to ArcScene.  Most ArcObjects classes can be deep cloned using the IObjectCopy interface.  Do not use the IClone interface as this only performs a shallow clone.  The other thing to be aware of is you shouldn't call New to create new instances of objects that you intend to use in the other process.  You should use IObjectFactory to create these instances.  This will create the object in the correct process space for you.
Reply
0 Kudos
New Contributor III
Hey Neil,

The object factory was the key! You win 1000 bonus points. Thanks for the help.

Will McInnes
Reply
0 Kudos
New Contributor
Hello every body
could you solve this issue !?
I am tring to add a Raster Layer (RGB) with 3d properties (base heights) to my ArcScene which I open and get access to it trough C++.
But I get problems with the opened ArcScene through C++ and the layer does not apear properly. Here are my codes ! is that the right way of opening ArcScene and adding layer (raster or feature) to it !?? I use ArcGIS Desktop 10.

IAppROTPtr ipAppROT(CLSID_AppROT);

ISxDocumentPtr ipSxDoc(CLSID_SxDocument);
IDocumentPtr ipDoc(ipSxDoc);

CComPtr<IApplication> ipApl;
ipApl.CoCreateInstance(CLSID_AppRef);

ipDoc->get_Parent(&ipApl);
ipApl->put_Visible(VARIANT_TRUE);

then I try to add my Raster Layer which I have uploaded from my Raster Dataset and add it to my SxDocument like this :

direct way:
ipSxDoc->AddLayer(ipRstLyr);

through ILayer:
ILayerPtr ipLyr(ipRstLyr);
ipSxDoc->AddLayer(ipLyr);

unfortunately neither the direct way works nor the one through ILayer !!!

any idea ??? thank you very much. Nazereh
Reply
0 Kudos