I'm working on converting some of my ArcMap addins to work in Pro. Rather steep learning curve given that is no ESRI guidance at all on doing this.
I have found that you can't do anything with geodatabases without wrapping it into an asynchronous function. I managed to find some sample code and wrote a test addin that lists all the featureclasses in a geodatabase.
The code below actually works, but is really messy with the inline defined "lambda" function. I should be able to clean it up with a separate function as in the commented out lines in the code, but am having trouble properly constructing the code.
The IDE tells me QueuedTask.run wants an "action" and not the function I passed it, so I don't know where to go from there.
I also found that I needed to add "async" to the addin button's onclick override to make it work, but that was a shot in the dark as none of the documentation or samples showed this, so I don't know if this is the proper way to do it.
Friend Class Sample
Inherits Button
Dim m_gdbPath As String = "F:\HIES\CnmiImagery\CnmiImagery.gdb"
Protected Overrides Async Sub OnClick()
Dim strMsgs As String = ""
Try
'strMsgs += Await QueuedTask.Run(getDefs())
strMsgs += Await QueuedTask.Run(Function()
Dim msg As String = ""
Using gdb As New Geodatabase(New FileGeodatabaseConnectionPath(New Uri(m_gdbPath, UriKind.Absolute)))
Dim defs As IReadOnlyList(Of TableDefinition) = gdb.GetDefinitions(Of FeatureClassDefinition)()
For Each fdsDef As FeatureClassDefinition In defs
msg += fdsDef.GetName & vbCrLf
Next
End Using
Return msg
End Function)
Catch ex As Exception
MsgBox(ex.Message)
End Try
MsgBox(strMsgs)
End Sub
'Function getDefs() As String
' Dim msg As String = ""
' Using gdb As New Geodatabase(New FileGeodatabaseConnectionPath(New Uri(m_gdbPath, UriKind.Absolute)))
' Dim defs As IReadOnlyList(Of TableDefinition) = gdb.GetDefinitions(Of FeatureClassDefinition)()
' For Each fdsDef As FeatureClassDefinition In defs
' msg += fdsDef.GetName & vbCrLf
' 'Console.WriteLine(TableString(fdsDef As TableDefinition))
' Next
' End Using
' Return msg
'End Function
End Class
Solved! Go to Solution.
Hi Berndt.
Have you tried like this:
strMsgs += Await QueuedTask.Run(Return getDefs())
I don't know VB Net syntax, but you must return value from your QueedTask.Run.
Another way:
strMsgs += Await QueuedTask.Run(Function()
Return getDefs()
End Function)
In c# we use {} instead of Function() End Function.
About await and async. You can use Result from QueedTask.Run. Then you do not need add async.
Like this:
strMsgs += QueuedTask.Run(Function()
....
End Function).Result
I found info for c# but I think it could be suitable and for VB Net:
https://www.exprodat.com/blogs/33195/
(Enabling Edit and Continue section)
Hi Berndt.
Have you tried like this:
strMsgs += Await QueuedTask.Run(Return getDefs())
I don't know VB Net syntax, but you must return value from your QueedTask.Run.
Another way:
strMsgs += Await QueuedTask.Run(Function()
Return getDefs()
End Function)
In c# we use {} instead of Function() End Function.
About await and async. You can use Result from QueedTask.Run. Then you do not need add async.
Like this:
strMsgs += QueuedTask.Run(Function()
....
End Function).Result
I found info for c# but I think it could be suitable and for VB Net:
https://www.exprodat.com/blogs/33195/
(Enabling Edit and Continue section)
Thank you very much, Gintautas!
The first suggestion didn't work, but the second one did. It could be further cleaned up as
strMsgs += Await QueuedTask.Run(Function() getDefs())
And your suggestion for getting rid of the Async modifier worked a treat. Awesome!
Hello Berndt Nording
Great to hear that you are beginning your work migrating your add-ins to Pro, and found your way here to the group. I saw that you mentioned that you had not found many resources yet, and wanted to make sure you are aware of these as you get started:
Christopher,
Thanks for responding. Yes, I have already studied the "Migrating to ArcGIS Pro" document, In fact I was quite thrilled to find it, and then very disappointed when I looked at the content. "Migration" is not addressed at all, this is truly a "Getting Started" (from scratch) document. For those of us that have spent years learning, developing, and refining our knowledge of customizing ArcGIS UnPro (ArcMap), there is little if anything that helps us apply those hard-won skills to migrating. Clearly, while Pro is a completely different animal and many things are different, there are still many concepts and approaches that are still the exactly the same even if they are just sporting new names and terminology.
And yes, what I have been able to do so far has been because of the community samples. Indeed, samples are the lifeblood of a GIS Engineer that needs to have many GIS skills that are not programming related, yet still needs to use programming as just another tool to accomplish a larger task by cobbling together bits and pieces borrowed from samples.
I am looking forward to the resumption of real (not online) instructor-led training.
I have looked at several of the DevSummit videos, and even paused them to painstakingly copy some code to a file. It would be great if any code from these videos were made available digitally. Please don't mention PDF, the bane of all GIS datahounds.
Thanks for your feedback, Berndt, and glad you found that document. We've tried to include the high-level topics which are normally helpful to new Pro developers as they look to migrate or get started from scratch, and these mainly are getting started concepts. Sounds like you're very familiar with many of the resources and great news that you found the samples.
On your question on the DevSummit videos -- yes, the team has recently been making these available, and you can find the individual SDK session materials at this page: