|
POST
|
Yes, I was afraid of that. Thanks for checking. A little background -- I have an add-in extension running in ArcMap 10.1 (.NET Framework 4.0). This project has been underway for a year or so. Along the way we developed a number of processes that run geoprocessing tools in a project toolbox. The project has been on the shelve for a month or so but was running fine last time I did work with it. Naturally, I had scheduled a demo to show folks the project on Monday this week. When I got into it I discovered that none of my gp Executes work. The toolbox is still valid and the tools execute normally from Catalog. Eventually I built the simple code block you see above in a separate add-in button to make sure that there wasn't something in the extension that was clobbering things. When that didn't work I ran a repair on Visual Studio and re-installed Arc. That did nothing. I've removed all of my extensions and add-ins except the test case and can not find the problem. The toolbox tool (sample code above in original post) is a very simple arcpy script that looks grabs the string parameter and gives it back: import arcpy
if __name__ == '__main__':
s = arcpy.GetParameter(0)
arcpy.AddMessage(s) Thanks Again.
... View more
11-06-2013
09:00 AM
|
0
|
0
|
1018
|
|
POST
|
Richard, Thanks for the speedy reply. The decimal code ErrorCode from the exception is -2147467259. I've not decoded this but did find a thread that suggest this code is a generic failure code but I'd be grateful for any thread that leads out of this ditch I've veered into! David
... View more
11-06-2013
08:23 AM
|
0
|
0
|
1018
|
|
POST
|
Hi Everyone, Recently, I started having problems with my C# projects running geoprocessing tools. My tools point to custom scripts in project toolboxes. The code in question has run without issue in the past. However, something in my environment has changed and even the simplest code throws errors. Please see sample below. The code fails on gp.Execute(); I've triple checked, labels, names, paths, parameters etc. I've tried every thing I can think of to track down this problem including re-installing Arc. I'm dead in the water if I can't solve this nasty problem. Thanks in Advance David
private void runTool()
{
try
{
Geoprocessor gp = new Geoprocessor();
gp.AddToolbox(@"C:\0_Test\Test.tbx");
IVariantArray parameters = new VarArrayClass();
parameters.Add(@"MyStringArg");
// Execute the tool.
gp.Execute("test", parameters, null);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "TestGP Error", System.Windows.Forms.MessageBoxButtons.OK);
return;
}
}
... View more
11-06-2013
07:47 AM
|
0
|
6
|
3818
|
|
POST
|
Hi Everyone, I've recently installed Server Enterprise 10.1 on my Windows 7 machine and have had a heck of a time keeping the services running. My installation went smoothly. Once started I checked my permissions for the arcgis user and was able to start the Server Manager fine. Things went downhill from there. As soon as I begin interacting with the server I began to get messages like: Failed to start the server machine...Required port 4000 already in use. I checked that port using netstat -ao and found the port was in use ... by a process owned by the arcgis server user. I tried starting and stopping the service but then found that subsequent tries at starting the server manager failed completely the site was not available. I did find that rebooting would re-expose the site but subsequent interactions with the site would crash the services. Finally I recalled having problems with our Cisco VPN crashing the my license manager a few months ago. Sure enough, I found that if I turned off my VPN the Server started to work -- well at least until this writing. I've not fully exercised it but was able to publish an arcmap service. I'm writing this partly for the record and to ask -- has anyone else out there had compatibility problems between your VPN (or similar) and server? Thanks in advance David
... View more
04-12-2013
01:32 PM
|
0
|
7
|
2834
|
|
POST
|
OK I've worked out what object(s) manage(s) single/multi part settings. This doesn't explain why the interface disables the basic command when posted on a toolbar but does give you a way to add this functionality to your own controls. You derive IMultiPartTextElement from IElement:
(Please forgive the ragged bits in the following development code)
Private Sub ToggleSingleMulti()
On Error GoTo lblError
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap
Dim pFeatSel As IEnumFeature
Set pFeatSel = pMap.FeatureSelection
Dim pFeat As IFeature
Set pFeat = pFeatSel.Next
Dim pAnnoFeat As IAnnotationFeature2
Dim pElem As IElement
Dim pTextEl As ITextElement
Dim pMultTextEl As IMultiPartTextElement
Dim pAnnoClassExt As IAnnotationClassExtension2
Set pAnnoClassExt = GetAnnoFeaClsExt(pMap, pDoc)
If pAnnoClassExt Is Nothing Then
Exit Sub
End If
Do While Not pFeat Is Nothing
If TypeOf pFeat Is IAnnotationFeature2 Then
Set pAnnoFeat = pFeat
Set pElem = pAnnoFeat.Annotation
If Not pElem Is Nothing Then
Set pMultTextEl = pElem
If pMultTextEl.IsMultipart Then
pMultTextEl.ConvertToSinglePart
Else
pMultTextEl.ConvertToMultiPart pAnnoClassExt.Display(pElem)
End If
pAnnoFeat.Annotation = pElem
Set pFeat = pAnnoFeat
pFeat.Store
End If
End If
Set pFeat = pFeatSel.Next
Loop
Exit Sub
lblError:
Debug.Print Err.Description
Exit Sub
End Sub
Public Function GetAnnoFeaClsExt(pMap As IMap, pMxdoc As IMxDocument) As IAnnotationClassExtension
On Error GoTo lblError
'Dim pMxDoc As IMxDocument
'Set pMxDoc = Nothing
Dim pID As UID 'Get a handle to the Editor extension
Set pID = New UID
Dim pAnnoExt As IAnnotationEditExtension
Dim pAnnoID As New UID
pAnnoID = "esriEditor.AnnotationEditExtension"
Dim pAnnoClass As IAnnotationClassExtension
pID = "esriEditor.Editor"
Dim pEditor As IEditor2
Set pEditor = Application.FindExtensionByCLSID(pID)
Dim pEditLayers As IEditLayers
If pEditor.EditState = esriStateNotEditing Then
MsgBox "Please start the Editor to select points."
Set GetAnnoFeaClsExt = Nothing
Exit Function
End If
Set pEditLayers = pEditor 'QI to grab CurrentLayer property
If pEditLayers Is Nothing Then
return nothing
End If
Dim iLayerCount As Integer
Dim pFeatureLayer As IFeatureLayer
For iLayerCount = 0 To pMap.LayerCount - 1
If TypeOf pMap.Layer(iLayerCount) Is IFeatureLayer Then
Set pFeatureLayer = pMap.Layer(iLayerCount)
s = pFeatureLayer.Name
pEditLayers.SetCurrentLayer pFeatureLayer, 0
Debug.Print pEditLayers.CurrentLayer.Name
End If
Next iLayerCount
Set pAnnoClass = pEditLayers.CurrentLayer.FeatureClass.Extension
Set GetAnnoFeaClsExt = pAnnoClass
Exit Function
lblError:
Debug.Print Err.Description
Exit Function
End Function
... View more
02-22-2011
12:22 PM
|
0
|
0
|
315
|
|
POST
|
Hi Everyone, I'd like to create some short cuts to point at the Convert to Multi/Single part commands on the Edit Annotation Tool. These commands are available in the Advanced Editing Commands list but become inactive when posted on toolbars. It would be very handy to associate some keys or similar short cuts to these commands while in an edit session. I thought that the code to get to these properties would be pretty "easy" to wire up in VBA or a .NET addin. I've not even been able to find the interface these properties sit on. Can anyone offer some insights into which objects manage Annotation Properties at this level? Thanks David
... View more
02-05-2011
11:35 AM
|
0
|
1
|
2373
|
|
POST
|
Hi Everyone, For the sake of completion in this thread, we solved our particular problem by simplifying all of the input features and by simplifying the resulting feature on each iteration of the while loop: Dim pNewFeature As ESRI.ArcGIS.Geodatabase.IFeature = Nothing
Dim pNewPolyline As ESRI.ArcGIS.Geometry.IPolyline = Nothing
Dim pOtherPolyline As ESRI.ArcGIS.Geometry.IPolyline = Nothing
Dim pTopoOp As ESRI.ArcGIS.Geometry.ITopologicalOperator5 = Nothing
Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature = Nothing
' Featureset contains two or more sector line
' features that have the same assignment and belong
' to the same perimeter polygon. Merge their shapes
' to create as single geometry from them.
' Get the feature metadata from the first feature.
' it will be used to populate metadata on the resulting
' feature. Since all the line features are associated
' with the same polygon, they should all have the
' same metadata.
Dim pMetadata As FIMTExtensionNET.clsFIMTMetadataNET
pMetadata = Nothing
FeatureSet.Reset()
pFeature = FeatureSet.Next
Do While Not pFeature Is Nothing
If pMetadata Is Nothing Then
pMetadata = New FIMTExtensionNET.clsFIMTMetadataNET
pMetadata.GetFeatureMetaData(pFeature)
End If
If pNewPolyline Is Nothing Then
pNewPolyline = pFeature.ShapeCopy
pTopoOp = CType(pNewPolyline, ESRI.ArcGIS.Geometry.ITopologicalOperator5)
pTopoOp.IsKnownSimple_2 = False '051710
pTopoOp.Simplify() '051710
Else
pOtherPolyline = pFeature.ShapeCopy
'Simplify the just obtained OtherPolyLine
pTopoOp = CType(pOtherPolyline, ESRI.ArcGIS.Geometry.ITopologicalOperator5) '051710
pTopoOp.IsKnownSimple_2 = False
pTopoOp.Simplify()
'Reset the pTopoOp to pNewPolyLine in prep for the union
pTopoOp = CType(pNewPolyline, ESRI.ArcGIS.Geometry.ITopologicalOperator5)
pNewPolyline = pTopoOp.Union(pOtherPolyline)
'Simplify the resulting New Line
pTopoOp = CType(pNewPolyline, ESRI.ArcGIS.Geometry.ITopologicalOperator5)
pTopoOp.IsKnownSimple_2 = False
pTopoOp.Simplify()
End If
pFeature = FeatureSet.Next
Loop I hope this is helpful. D
... View more
06-02-2010
07:54 AM
|
0
|
0
|
1658
|
|
POST
|
Thanks again Kirk, Yes, it seems like, unlike the old days working in MFC C++, the best policy is to leave your objects alone; trying to explicitly clean them up can cause more harm than good. This confirms the adage: no good deed goes unpunished! I found the following link that seems to confirm this and offers a bit of insight into how to think about COM objects and an approach to managing them: Please see: http://social.msdn.microsoft.com/Forums/en/vsto/thread/d11c67eb-3ad4-4e36-8707-37e671a37279 From that link: Hi Gary, Yes, managing Runtime Callable Wrappers (RCWs) can be tricky. However, depending on what you are doing, you may not need to manage them at all. As you know RCW's will hold a reference to their underlying COM object. When the RCW's finalizer is run, they will release their reference. So when do RCW's get finalized? At a minimum, they get finalized when the AppDomain is torn down. During teardown, all objects are collected regardless of whether they are rooted. Before AppDomain teardown, there are two other ways that RCWs could be finalized. The first would be when the objects are no longer rooted and therefore become eligable for collection. If the GC0 heap fills up, a garbage collection will occur, and those RCWs that are eligible will be finalized. The second way finalization can happen is if you explicitly force a garbage collection by calling GC.Collect. If you do that, any RCWs eligible for collection will be finalized. By calling WaitForPendingFinalizers, you ensure that the finalizer thread has finalized all of the objects in the queue before your thread continues. In addition, as you are aware, you can deterministically force the RCWs to release their reference by calling either Marshal.ReleaseComObject or Marshal.FinalReleaseComObject. The difference between the two calls is this. RCW's have a reference count of their own which gets bumped when the IUnknown is marshalled across AppDomain boundaries. Calling Marshal.ReleaseComObject will only actually release when the RCW reference count goes to zero--otherwise it has the effect of decrementing this internal count. Marshal.FinalReleaseComObject, however, will call the release regardless of what the RCW reference count is. So the real question is when do you need to be explicit about enforcing RCW finalization or calling Marshal.Final/ReleaseComObject? The answer is whenever you can't afford to wait for GC to happen (knowing that it might not occur until shutdown). The two most likely reasons would be if the object is holding onto a resource (such as a file handle) or if memory pressure caused by keeping the object(s) alive was hurting performance. If you know you are going to need to deterministically control the RCW cleanup, the best thing to do is to keep them isloated (and not pass them around) so that you can just call Marshal.FinalReleaseComObject when you are done with them. As long as you can guarantee that you won't try to call into the RCW again after you make that call, then this is a safe approach. This is better than trying to force a GC yourself since doing that will promote any existing objects in the heap to later generations which will mean they will potentially hang around in memory longer than they would have otherwise. That said, the ideal is to do nothing and just let the system take care of everything. Managing this stuff on your own is harder, so be sure you understand your reasons for doing so before you take that on. Sincerely, Geoff Darst Microsoft VSTO Team Regards David
... View more
05-20-2010
09:06 AM
|
0
|
0
|
1191
|
|
POST
|
For the sake of the thread, the following links provide a bit more insight into what is happening relative to releasing COM objects and the role of the Using block. Bottom line, my take is this: unlike VB6, setting COM objects = nothing doesn't really buy very much. When your functions and subs go out of scope your objects and their respective wrappers lurk around in object purgatory waiting for the garbage collector to clean them up. Generally speaking, this isn't a problem but for some resources it is best to explicitly force the release so one doesn't tie up limited resources such as tables. Hence, Marshal.ReleaseComObject(pMyCOMObject) --> I think of this sort of like pMyCOMObject = nothing in VB6 See also: http://www.getdotnetcode.com/gdncstore/free/Articles/ReleasingComObjectsWithVbNet.htm For those interested in the ComReleaser and the role of the Using statement see: http://msdn.microsoft.com/en-us/library/htd05whh.aspx In part from that article: Sometimes your code requires an unmanaged resource, such as a file handle, a COM wrapper, or a SQL connection. A Using block guarantees the disposal of one or more such resources when your code is finished with them. This makes them available for other code to use. Managed resources are disposed of by the .NET Framework garbage collector (GC) without any extra coding on your part. You do not need a Using block for managed resources. However, you can still use a Using block to force the disposal of a managed resource instead of waiting for the garbage collector. A Using block has three parts: acquisition, usage, and disposal. �?� Acquisition means creating a variable and initializing it to refer to the system resource. The Using statement can acquire one or more resources, or you can acquire exactly one resource before entering the block and supply it to the Using statement. If you supply resourceexpression, you must acquire the resource before passing control to the Using statement. �?� Usage means accessing the resources and performing actions with them. The statements between Using and End Using represent the usage of the resources. �?� Disposal means calling the Dispose method on the object in resourcename. This allows the object to cleanly terminate its resources. The End Using statement disposes of the resources under the Using block's control. Please feel free to comment with suggestions or corrections if I've missed something. Otherwise, I hope this helps others sort out this important topic and is helpful to others. D
... View more
05-14-2010
02:42 PM
|
0
|
0
|
1191
|
|
POST
|
Thanks again everyone, I'm finding the whole conversation very instructive and hope that others will also find it so in the future. Here, in our current project, It seems to me that our best strategy now will be to change our coding to the patterns as James suggested, still using ComReleaser. Furthermore we'll review our code to confine the use of the releaser to the basics that James also cited. Best Regards.
... View more
05-13-2010
09:07 AM
|
0
|
0
|
1191
|
|
POST
|
Neil, James and Kirk, Your replies have been very helpful, thank you -- A tip of my hat to the masters! For the sake of my own understanding and the thread then, regarding RCWs I am left wondering: see: http://edndoc.esri.com/arcobjects/9.2/NET/fe9f7423-2100-4c70-8bd6-f4f16d5ce8c0.htm, and http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.releasecomobject.aspx Reading at MSDN, I see that "Every time a COM interface pointer enters the common language runtime (CLR), it is wrapped in an RCW." I take this to mean, essentially, that all our our ArcObjects in .NET have a corresponding RCW. Furthermore MSDN says: Therefore, use the ReleaseComObject only if it is absolutely required. If you want to call this method to ensure that a COM component is released at a determined time, consider using the FinalReleaseComObject method instead. FinalReleaseComObject will release the underlying COM component regardless of how many times it has re-entered the CLR. The internal reference count of the RCW is incremented by one every time the COM component re-enters the CLR. Therefore, you could call the ReleaseComObject method in a loop until the value returned is zero. This achieves the same result as the FinalReleaseComObject method. So: it seems that a good rule of thumb would be -- if you explicitly know that you should release the object, such as a cursor, then do it otherwise leave things to the garbage collector. So consequently I'm wondering, is there a rule of thumb to help one detect which objects we should consider for explicit release, either by ReleaseComObject, FinalReleaseComObject or alternatively, ComReleaser? Best Regards David
... View more
05-12-2010
08:28 AM
|
0
|
0
|
1902
|
|
POST
|
Hi Everyone, We're using the ComReleaser object in .NET to free up cursors, feature cursors and a few other COM objects in various functions through out our project. The following code shows a typical implementation. We're finding that a number errors are being thrown in our code when it is running suggesting that the releaser is not working the way we think that i might be. I am under the impression that the ComReleaser object "knows" to clean up as it gets to the "End Using" statement. Apparently not? Errors that we're seeing are: COM object that has been separated from its underlying RCW cannot be used. Too many tables open. Attempted to read or write to protected memory. Bottom line, what is the best way to ensure that COM objects are cleaned up appropriately? Thanks D Here is a typical implementation: Using pComReleaser As ComReleaser = New ComReleaser Try Dim pBreakptFC As ESRI.ArcGIS.Geodatabase.IFeatureClass Dim pQF As ESRI.ArcGIS.Geodatabase.IQueryFilter Dim pTable As ESRI.ArcGIS.Geodatabase.ITable = Nothing pComReleaser.ManageLifetime(pTable) Dim pFeatCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor = Nothing pComReleaser.ManageLifetime(pFeatCursor) Dim pFeat As ESRI.ArcGIS.Geodatabase.IFeature pBreakptFC = GetBreakptClass(MXApp) pFeatCursor = Nothing If Not pBreakptFC Is Nothing Then pTable = pBreakptFC pQF = New ESRI.ArcGIS.Geodatabase.QueryFilter pQF.WhereClause = FIELD_PERIMETERID & " = " & CStr(PerimFeat.OID) If pTable.RowCount(pQF) > 0 Then pFeatCursor = pBreakptFC.Search(pQF, False) pFeat = pFeatCursor.NextFeature Do While Not pFeat Is Nothing pFeat.Delete() pFeat = pFeatCursor.NextFeature Loop End If End If pBreakptFC = Nothing pQF = Nothing pTable = Nothing pFeat = Nothing pFeatCursor = Nothing Catch ex As Exception LogError(LIBRARY_NAME, ex.ToString()) End Try End Using
... View more
05-11-2010
02:19 PM
|
0
|
20
|
11555
|
|
POST
|
Hi Rob Yes, I found all that behavior a bit challenging too. I set up document and ActiveView Events in an extension. I found that I had to setup the document events only once. I removed the events on extension shut down. On the other hand, each time the document.ActiveViewChanged event is fired I remove my old events then add the new ones, see below. Hope this helps. Private Sub OnActiveViewChanged() Try Dim pActiveView As IActiveView = m_pMxDocument.ActiveView Dim pMap As IMap Dim pPageLayout As IPageLayout If TypeOf pActiveView Is IMap Then pMap = pActiveView.FocusMap m_pActiveViewEvents = CType(pMap, IActiveViewEvents_Event) Debug.Print("Active View is IMAP, FocusMap is: " & pActiveView.FocusMap.Name) ElseIf TypeOf pActiveView Is IPageLayout Then pPageLayout = m_pMxDocument.PageLayout m_pActiveViewEvents = CType(pPageLayout, IActiveViewEvents_Event) Debug.Print("Active View is IPageLayout, FocusMap is: " & pActiveView.FocusMap.Name) Else Return End If Me.RemoveActiveViewEvents() Me.AddActiveViewEvents() Catch ex As Exception DebugMsgBox("OnActiveviewChanged() Error: " & ex.ToString) End Try End Sub Public Sub AddActiveViewEvents() Try If m_pActiveViewEvents IsNot Nothing Then AddHandler m_pActiveViewEvents.FocusMapChanged, AddressOf OnActiveViewEventsFocusMapChanged AddHandler m_pActiveViewEvents.ItemAdded, AddressOf OnActiveViewEventsItemAdded AddHandler m_pActiveViewEvents.ItemDeleted, AddressOf OnActiveViewEventsItemDeleted DebugMsgBox("AddActiveViewEvents") Else DebugMsgBox("AddActiveViewEvents m_pActiveViewEvents = NOTHING") End If Catch ex As Exception End Try End Sub Public Sub RemoveActiveViewEvents() Try If m_pActiveViewEvents IsNot Nothing Then RemoveHandler m_pActiveViewEvents.FocusMapChanged, AddressOf OnActiveViewEventsFocusMapChanged RemoveHandler m_pActiveViewEvents.ItemAdded, AddressOf OnActiveViewEventsItemAdded RemoveHandler m_pActiveViewEvents.ItemDeleted, AddressOf OnActiveViewEventsItemDeleted DebugMsgBox("RemoveActiveViewEvents") Else DebugMsgBox("RemoveActiveViewEvents - m_pActiveViewEvents = NOTHING") End If Catch ex As Exception End Try End Sub
... View more
04-07-2010
03:52 PM
|
0
|
0
|
490
|
|
POST
|
For those who are interested, a bit more information: If one cannot ensure that the polyline created is not simple then we need to call the simplify method. A geometry is not simple when it does not meet the all the constraints associated with them. The following documentation explains how the simplify method simplifies the geometry. http://resources.esri.com/help/9.3/ArcGISDesktop/com/samples/Geometry/e7840a7a-f228-46d2-9c45-81dd5527faa3.htm http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esriGeometry/Geometry_overview.htm http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esriGeometry/ITopologicalOperator_Simplify.htm
... View more
04-07-2010
03:37 PM
|
0
|
0
|
1658
|
|
POST
|
Thanks again Kirk, I've added your recommended code with good success. I've run through the problem scenario about 10-15 times with no COM Exception thrown. We might be there!
... View more
04-07-2010
09:38 AM
|
0
|
0
|
1658
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-09-2015 12:25 PM | |
| 2 | 05-19-2015 04:27 PM | |
| 1 | 04-06-2010 09:51 AM | |
| 1 | 05-22-2015 11:02 AM | |
| 1 | 05-08-2015 04:58 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|