2012-03-26 48 views

回答

3

如果您实际上只是试图执行“Copy Parallel ...”命令...您可以这样做这

 IDocument d = ArcMap.Document as IDocument; 
     IUID ud = new UIDClass(); 
     ud.Value = "esriEditor.CopyParallelCommand"; 
     ICommandItem c = d.CommandBars.Find(ud); 
     c.Execute(); 

如果你想以编程方式复制平行副本,只有我发现是使用IConstructCurve3来模拟天生的操作。这种方法似乎几乎有相同的参数。

 //Get the selection 
     UID uid = new UIDClass(); 
     uid.Value = "esriEditor.Editor"; 

     IEditor editor; 
     editor = (IEditor)ArcMap.Application.FindExtensionByCLSID(uid); 

     //Get Selection 
     IEnumFeature enumfeature = editor.EditSelection; 
     IFeature f = enumfeature.Next(); 

     //For adding new features 
     IFeatureClass fc = f.Class as IFeatureClass; 

     //Start an operation for undo/redo 
     editor.StartOperation(); 
     while (f != null) 
     { 

      //Interface to do a "copy parallel" 
      IConstructCurve3 construct = new PolylineClass(); 

      //Rounded, Mitered, etc 
      object offset = esriConstructOffsetEnum.esriConstructOffsetRounded; 

      IPolyline source = f.Shape as IPolyline; 

      //Method call (0.001 or -0.001 determines left/right) 
      construct.ConstructOffset(source, 0.001, ref offset); 

      //Storing output shape 
      IFeature newFeature = fc.CreateFeature(); 
      newFeature.Shape = (IGeometry)construct; 

      newFeature.Store(); 


      f = enumfeature.Next(); 
     } 

     editor.StopOperation("Copy Parallel"); 

     //refresh 
     ArcMap.Document.ActiveView.Refresh(); 

我只砍死了IConstructCurve3相关的部分,确保你做你的支票,如果欲望,复制源要素属性了。

如果你有VS2010,如果你只是通过使用ESRI ArcMap Addin项目模板和一个按钮创建一个Button Addin,这段代码就会运行。然后将代码复制并粘贴到OnClick()事件中。 (当然,不要忘记设置必要的esri参考)

+0

我必须先说“谢谢”,然后再进入它。我稍后可能会有更多的问题。非常感谢。 – user1293655 2012-03-27 14:14:46

+0

你的代码工作得很好。我非常感谢你的帮助。我一直在阅读ArcObjects SDK 10 Microsoft .NET Framework三周。仍然不确定如何开始编写代码。你能指点我从哪里开始的正确方向吗?比如我可以在任何书籍或任何指令中找到像“esriEditor.CopyParallelCommand”这样的命令?我一直在使用ArcGIS桌面,可以编写python代码。但我对使用c#的ArcObjects相当陌生。再次感谢。等待你的回复。 – user1293655 2012-03-27 14:59:59

+0

如果您对ArcObjects完全陌生......我仍然相信ESRI有一些相当不错的开发文档。这个网站。 http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html可能是最好的开始。在“演练:”这个词的内容列表中查找任何内容,并且它几乎可以逐步扩展。因此,只需打开VS2010,并随时随地进行演练,您就会明白。祝你好运。 – JTran 2012-03-28 05:54:45