POST
|
Ken Your Extension tag really helped me here. The following instructions were not inside my tag: showInExtensionDialog="true" autoLoad="true" So, copying it to my code, it's all working fine. I was guessing it could be started with the add in wizard, but now it's ok. I really appreciate your help. Thanks a lot. Rodrigo Salvador
... View more
05-23-2012
08:59 AM
|
0
|
0
|
518
|
POST
|
Hi Ken Thanks for your attention. I didn't make any changes in Config.esriaddinx, I've let it just the way the wizard created it. The "Extension1" class differs from de default onde only by some message boxes inside the constructos, startup and event handle methods. Here they are: Extension1 class
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace GEOTE_Addin
{
public class Extension1 : ESRI.ArcGIS.Desktop.AddIns.Extension
{
public Extension1()
{
MessageBox.Show("Constructor method Extension1 reached...");
}
protected override void OnStartup()
{
MessageBox.Show("OnStartup method reached!");
WireDocumentEvents();
}
private void WireDocumentEvents()
{
//
// TODO: Sample document event wiring code. Change as needed
//
// Named event handler
ArcMap.Events.NewDocument += delegate() { ArcMap_NewDocument(); };
ArcMap.Events.OpenDocument += delegate() { ArcMap_OpenDocument(); };
// Anonymous event handler
ArcMap.Events.BeforeCloseDocument += delegate()
{
// Return true to stop document from closing
ESRI.ArcGIS.Framework.IMessageDialog msgBox = new ESRI.ArcGIS.Framework.MessageDialogClass();
return msgBox.DoModal("BeforeCloseDocument Event", "Abort closing?", "Yes", "No", ArcMap.Application.hWnd);
};
}
void ArcMap_NewDocument()
{
// TODO: Handle new document event
}
void ArcMap_OpenDocument()
{
MessageBox.Show("You opened a doc");
}
}
}
Config.esriaddinx (2 buttons, 2 menus, 2 toolbars, 1 extension) <ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Name>GEOTE_Addin</Name> <AddInID>{135b6f77-cc81-4a52-9b13-644d6427dbc1}</AddInID> <Description>Extensão do GEO-TE</Description> <Version>1.0</Version> <Image>Images\GEOTE_Addin.png</Image> <Author>Salvador</Author> <Company>COPEL</Company> <Date>21/05/2012</Date> <Targets> <Target name="Desktop" version="10.0" /> </Targets> <AddIn language="CLR" library="GEOTE_Addin.dll" namespace="GEOTE_Addin"> <ArcMap> <Extensions> <Extension id="GEOTE_Addin_Extension1" class="Extension1" /> </Extensions> <Commands> <Button id="GEOTE_Addin_ArcGISAddin1" class="ArcGISAddin1" message="Add-in command generated by Visual Studio project wizard." caption="My Button" tip="Add-in command tooltip." category="Add-In Controls" image="Images\ArcGISAddin1.png" /> <Button id="GEOTE_Addin_ArcGISAddin2" class="ArcGISAddin2" message="Add-in command generated by Visual Studio project wizard." caption="My Button" tip="Add-in command tooltip." category="Add-In Controls" image="Images\ArcGISAddin2.png" /> </Commands> <Menus> <Menu id="GEOTE_Addin_Menu_A" caption="Menu A" isRootMenu="false"> <Items /> </Menu> <Menu id="CGEOTE_Addin_Menu_B" caption="Menu B" isRootMenu="false"> <Items /> </Menu> </Menus> <Toolbars> <Toolbar id="GEOTE_Addin_Toolbar_Z" caption="Toolbar Z" showInitially="false"> <Items /> </Toolbar> <Toolbar id="GEOTE_Addin_Toolbar_Y" caption="Toolbar Y" showInitially="true"> <Items /> </Toolbar> </Toolbars> </ArcMap> </AddIn> </ESRI.Configuration>
... View more
05-22-2012
12:37 PM
|
0
|
0
|
518
|
POST
|
Hi all I have just built a simple add-in, in order to migrate my application to this new architecture. This add-in has two toolbars, and I can see both of then when I run ArcMap. There's also an extension, but the Startup method is never called. Does anyone faced some issue like that? Before it, I've tried do work registering dlls. I've faced the same difficult, but it worked - unfortunately, I have no idea why it wasn't working, neither why it suddenly acess the class that inherited IExtension. Thanks in advance Rodrigo Salvador
... View more
05-22-2012
10:55 AM
|
0
|
4
|
3015
|
POST
|
Hi again Please, ignore this thread. The problem was internal (I was reading the wrong password). It's working fine. Sorry about that. Rodrigo Salvador
... View more
08-25-2011
08:41 AM
|
0
|
0
|
173
|
POST
|
Hi everyone I reached my goal in changing layer properties, it's greatly working. My code opens a .mxd, look for layer properties, load all of them for each layer, change the convenient ones and save these changes. Here's the trouble: Before running the code, the layers are correctly loaded when opening ArcMap, and the DataSource contains all connection properties and spatial references. After it, the red exclamation appears. Taking a look at the DataSource, the connection properties are there (with some differences, like the password field, which was hidden before and now is shown), but the spatial references are gone. So, my questions are: Am I loading it wrong? Is a DataSource connecting nedded in the code? What's the reason to that? PS: I tried to use IDataLayer2.Connect() and Disconnect() methods, but they're giving me COM exceptions.
this.pMapDocument = new MapDocumentClass();
if (!this.pMapDocument.get_IsPresent(sPath))
{
MessageBox.Show("The file " + sPath + " doesn't exists");
return;
}
this.pMapDocument.Open(sPath, "");
for (i = 0; i < this.pMapDocument.MapCount; i++)
{
this.pMap = new MapClass();
this.pMap = this.pMapDocument.get_Map(i);
this.pMapDocument.ActiveView.Activate(i);
Application.DoEvents();
this.pUID = new UIDClass();
this.pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
this.pEnumLayer = this.pMap.get_Layers((UID)pUID, true);
this.pEnumLayer.Reset();
this.pFeatureLayer = (IFeatureLayer)this.pEnumLayer.Next();
while (this.pFeatureLayer != null)
{
string dst = this.pFeatureLayer.DataSourceType;
if (dst.Contains("SDE"))
{
this.pDataLayer = (IDataLayer2)this.pFeatureLayer;
this.pDatasetName = (IDatasetName)this.pDataLayer.DataSourceName;
this.pWorkspaceName = this.pDatasetName.WorkspaceName;
this.pConnectionProperties = this.pWorkspaceName.ConnectionProperties;
if (!starting)
{
Application.DoEvents();
this.pConnectionProperties.SetProperty("SERVER", this.txtServidor.Text);
this.pConnectionProperties.SetProperty("INSTANCE", this.txtPorta.Text);
this.pConnectionProperties.SetProperty("DATABASE", this.txtDatabase.Text);
this.pConnectionProperties.SetProperty("USER", this.txtUsuario.Text);
this.pConnectionProperties.SetProperty("PASSWORD", this.txtSenha.Text);
this.pWorkspaceName = new WorkspaceNameClass();
this.pWorkspaceName.ConnectionProperties = this.pConnectionProperties;
this.pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory";
this.pNome = (IName)this.pWorkspaceName;
this.pNome.NameString = "SDE Connection";
this.pDatasetName = (IDatasetName)this.pDataLayer.DataSourceName;
this.pDatasetName.WorkspaceName = this.pWorkspaceName;
}
else
{
Application.DoEvents();
this.txtServidor.Text = this.pConnectionProperties.GetProperty("SERVER").ToString();
this.txtPorta.Text = this.pConnectionProperties.GetProperty("INSTANCE").ToString();
this.txtDatabase.Text = this.pConnectionProperties.GetProperty("DATABASE").ToString();
this.txtUsuario.Text = this.pConnectionProperties.GetProperty("USER").ToString();
}
this.pFeatureLayer = (IFeatureLayer)this.pEnumLayer.Next();
}
}
}
if (!starting)
{
this.pMapDocument.ReplaceContents((IMxdContents)this.pMap);
this.pMapDocument.Save(true, false);
}
this.pMapDocument.Close();
}
Thanks for your attention Rodrigo Salvador
... View more
08-25-2011
05:52 AM
|
0
|
1
|
1369
|
POST
|
Alexander, I had some troubles with IWorkspaceName.PathName too. It was loading a path that doesn't exist on my machine, but on the developer's. I solved that using IWorkspaceName. Did you try it? Rodrigo Salvador
... View more
08-25-2011
05:21 AM
|
0
|
0
|
355
|
POST
|
Hello Alexander Based on my application, I can only ask if you really need do use the IFeatureLayer.FeatureClass property. At this point, everything is going ok for me (reading the layer properties, changing and then saving), except for a DataSource connection (I am not able to open correctly the .mxd after saving, though the properties are correct. The spatial references are missing after saving). This means the null value in FeatureClass makes no difference for me at all. I presume that's nothing wrong with your code. Sincerely Rodrigo Salvador
... View more
08-24-2011
12:13 PM
|
0
|
0
|
355
|
POST
|
Hi My issue is resolved, and I must post the answer to that. I've pasted here the relevant part of the code, but I did not say that pMapDocument.Save() was inside an if clause. So, the first call of a map (which occurs while the form is loading) was never close. So, if you want to save some information, you must do it and then close de document. And also be sure that all other documents are close at this point. That's how I make it work. Good job for all Rodrigo Salvador
... View more
08-24-2011
12:00 PM
|
0
|
0
|
383
|
POST
|
Hi everyone I would open a new topic, but it might be interesting for all to see that this issue happens a lot of times. My code looks like this:
this.pMapDocument.Open(sPath, "");
for (i = 0; i < this.pMapDocument.MapCount; i++)
{
this.pMap = this.pMapDocument.get_Map(i);
this.pMapDocument.ActiveView.Activate(i);
//several commands to change layer properties here
}
this.pMapDocument.ReplaceContents((IMxdContents)pMap);
//IObjectCopy lip_ObjCopy = new ObjectCopyClass();
//pMap = (IMap)lip_ObjCopy.Copy(pMapDocument.get_Map(0));
//lip_ObjCopy = null;
this.pMapDocument.Save(pMapDocument.UsesRelativePaths, false);
this.pMapDocument.Close();
(The lines commented at ending I found in research, bur they made no difference) So, when I attempt to save, the code generates a STR_E_LOCKVIOLATION exception, even the .mxd is not ReadOnly. The very annoing thing is that I've saved the changes once, yesterday (it worked after I added .Close() in the ending of the code), and this error starts happening besides I did not changed the code. I made tests for many .mxd files. I'm using ArcInfo license for 9.3 version. Does anyone know what's going on? Edit: The method SaveAs also don't work using the same string (referenced by sPath in my code) as reference. But works fine on creating another file. I still waiting for some light. Many thanks Rodrigo Salvador
... View more
08-23-2011
03:24 AM
|
0
|
0
|
383
|
POST
|
Jo I can't run your code right now, I'll do it since I can. About the points, one may be the point you are interested, and the other two may be the edges of your line. You must calculate de distance from one tho another (you have one, the length of the segment, so it's just two calculations). After that, you use the 3 sides in Heron's formula, to get the distance of each point to the line. I assure you, it's not difficult to do. Good luck Rodrigo Salvador
... View more
08-19-2011
03:02 PM
|
0
|
0
|
974
|
POST
|
Alexander To change the layer's properties, I think I don't need to open the ArcMap (at least, I'm not dealing with this option). So, the ActiveView is not necessary. Even way, I called Activate() for testing, and it makes no difference. I've found a code that updates the information without connecting. I don't have it here right now, sorry, but it's something like "pWorkspaceName.ConnectionPropperties = pPropSet" after setting the pPropSet properly. It runs fine, but the information inside the layer did not change. Aldo, that .Save(true,false) is crashing the application. I couldn't understand how to set the parameters here. Thanks for your time Rodrigo Salvador
... View more
08-19-2011
02:56 PM
|
0
|
0
|
355
|
POST
|
Ok, tests are done. The code I've paste here failed while saving. So I changed it to Alexander's. And I'm getting a COM Exception on connecting or disconneting. Does anyone know why? I remember there's something to do with Project Properties -> Build -> check Register for COM interop, but this CheckBox is disabled here. Thanks Rodrigo Salvador
... View more
08-19-2011
11:33 AM
|
0
|
0
|
601
|
POST
|
Hi there I've build myself a code to find the nearest street of a point, and it is quite simple. I did not use any namespace, only math functions. So, if you want to give it a try, look for Heron's formula, which I think is the cheapest for computing. The formula gives you a height of a triangule using the sides. Maybe IProximityOperator give you best results, but I've never worked with it. Good luck Rodrigo Salvador
... View more
08-19-2011
11:17 AM
|
0
|
0
|
974
|
POST
|
Sorry, Alexander, I forgot this information to you: the links are not broken (the red exclamation is not there), and that's why I can't figure out why the information is not loaded in IFeatureLayer. On the other side, you said another important thing: the FeatureClass property is a direct link. Maybe that's why this error is happening, I'm not making an explicit connection to the database inside the code. As I told, the information is avaiable in the map properties window, and it makes me think the .mxd connects to the database itself someway, and I need to do it programatically too to be able to get that information. Does it make sense? About the connections, my first shot to edit the properties follows:
pMapDocument.ReplaceContents((IMxdContents)pMap);
pMapDocument.Save(true, false); //are these arguments ok?
pMapDocument.Close();
I found it in some research, and I'm guessing it will be sufficient. If I can't see it working, I'll try your suggestion. In both cases, I'll post again in order to finish the topic. Rodrigo Salvador
... View more
08-19-2011
08:00 AM
|
0
|
0
|
601
|
POST
|
Drubravko, thanks for the link. I'd change the GUID from IGeoFeatureLayer to IFeatureLayer, but it didn't make much difference. I asked the following test for all layers, whether GroupLayer or not, and all of them failed:
if (pFeatureLayer.FeatureClass != null)
{
MessageBox.Show(pFeatureLayer.Name + " ok");
}
else MessageBox.Show(pFeatureLayer.Name + " fail");
Alexander, you gave a great hint. My first goal here is to get the connection properties of the layer and write them down on a window (in which the user must change the properties as he/she wants). So, I do can open IDatalayer.DataSourceName (the property .NameString returns empty (""), but when I set it to an IDatasetName the .Name field is exactly the FeatureClass I want). Thus, the following code works:
pDataLayer = (IDataLayer2)pFeatureLayer;
if (pDataLayer.DataSourceName is IDatasetName)
{
pDatasetName = (IDatasetName)pDataLayer.DataSourceName;
pWorkspaceName = pDatasetName.WorkspaceName;
pConnectionProperties = pWorkspaceName.ConnectionProperties;
}
So, with your help, I'm able to do what I want right now (hope I can change the properties successfully later). Therefore, the IFeatureLayer.FeatureClass still returning null, and I think it's interesting if we keep trying to find a solution for this. Once again, thank you so much.
... View more
08-19-2011
05:24 AM
|
0
|
0
|
601
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|