Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am writing a stand-alone application in c# (using vs2010). I have ArcGis Desktop license.
I only need to insert a new data frame in an mxd file and save this mxd.

So: I create MxDocument coclass. Then get IMxDocument interface from that. Then i use its "Maps" property which return me IMaps interface. From that I call its method Add() to add a new dataframe.

Code:

Dim pDocClassOut As MxDocumentClas = New MxDocumentClass()
Dim appl As IApplication = TryCast(pDocClassOut.Parent, IApplication)
Dim mxDoc As IMxDocument = TryCast(appl.Document, IMxDocument)
Dim maps As IMaps = CType(mxDoc.Maps, IMaps)
Dim pMap1 As IMap = New MapClass
pMap1.Name = "XYZ"
maps.Add(pMap1)

mxDoc.UpdateContents()
appl.SaveDocument()
appl.SaveAsDocument("E:\DEV EnGIS\Untitled.mxd")
appl.Shutdown()

Why this simple code doesn't work? Thank you so much!

share|improve this question
add comment

2 Answers

What part isn't working? Have you tried calling mxDoc.Open(pathToMXD) first? I found a sample on the ArcGIS forums in Java, but the concept should be exactly the same in .Net.

share|improve this answer
    
Hi. Sorry for my late answer. Yes, i tried also mxDoc.Open(pathToMxd). Problem is that i get an error when i save the document (Generic error from COM). –  diolo75 Jul 24 '13 at 13:31
    
Sample you linked is for Add-in but I have a standalone application. –  diolo75 Jul 24 '13 at 13:44
add comment

Are you using engine? According to the help file this interface will not work, it's for desktop only

Have a look at this link: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IMaps_Interface/00120000097v000000/

If you are developing for desk top then try the create method.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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