Select to view content in your preferred language

create attachments with scripts

6118
22
12-03-2010 08:33 AM
LauraTellechea
New Contributor
Hi,

I was wondering if it is possible to attach several pictures to a set of points using scripts.

I have different point locations (structures) and many jpgs for each structure. I would like to have an automated attachment process in which by clicking the point, the point will already know which pictures to show.

I already tried using the attachment manager in ArcMap10. However, my supervisor wants to make it an automated process. Does anybody know how to do this?
0 Kudos
22 Replies
BrennaSterling
Deactivated User
Instead of attaching the actual document to each feature and storing it in the geodatabase, is it possible to only store the LINK or PATH to the file in the geodatabase? 

I have a street feature class that i am attaching hundreds of as built .pdf documents to.  Because the geodatabase stores the actual file..it is getting very large very quickly.  And it's redundant because the files are already stored on the server.  The attachment feature is key because many of our users have arcgisexplorer and can view the documents as html pop ups from there.  However, I am running out of space!

Each street segment has a unique segment number but the as built documents are randomly numbered.  I have an access table that stores the segment number and it associated "asbuilt ID's" but they are not the same number. 

It would be VERY useful if we could just attach several "hyperlinks" to a feature and have those links stored in the geodatabase. 

Is this currently possbile or will it be in future releases? 

And I hope this makes sense to all of you 🙂
0 Kudos
RebeccaRidley
Occasional Contributor
Hi Russel,
I'm not the original poster, but I will state that the functionality that you have described would be very useful.  I'd like to be able to attach documents to a file geodatabase feature class using ArcToolbox tools or python scripts.  My ultimate goal is to expose the attach file functionality through a geoprocessing service in ArcGIS Server.  That way, users could add attachments to features by way of a web mapping application.  This can currently be done very easily if your data is in SDE.  I'd like to use a file geodatabase for my applications...



Yes, I am trying to accomplish the very same task. This would be very useful for my operation, as well.
0 Kudos
EdDempsey
Occasional Contributor
I was challenged with the same issue, so here's some psuedo code that may help.   Using the active layer, in an Edit session, this code will loop through a featureclass reading a value from a Filepath field.   Most people already have a column like this in their data, particularly if they use Hyperlinks.  If the filepath value is not null, the associated file is loaded as an attachment for that feature.

       
Dim pApplication As IApplication
        Dim pMxDocument As IMxDocument
        Dim pFeatLayer As IFeatureLayer
        Dim pFeatureclass As IFeatureClass
        Dim pTable As ITable
        Dim pContentsView As IContentsView3
        Dim pfeature As IFeature
        Dim pFeatCursor As IFeatureCursor
        Dim OID As Integer
        Dim filepath As String

        pApplication = m_application
        pMxDocument = pApplication.Document
        pContentsView = pMxDocument.CurrentContentsView

        Dim selectedItem As System.Object = pContentsView.SelectedItem
        If Not (TypeOf selectedItem Is ESRI.ArcGIS.Carto.ILayer) Then
            Return
        End If

        Dim layer As ESRI.ArcGIS.Carto.ILayer = TryCast(selectedItem, ESRI.ArcGIS.Carto.ILayer)
        pFeatLayer = TryCast(layer, ESRI.ArcGIS.Carto.FeatureLayer)
        pFeatureclass = pFeatLayer.FeatureClass

        Dim tableAttachments As ITableAttachments = CType(pFeatureclass, ITableAttachments)
        Dim attachmentManager As IAttachmentManager = tableAttachments.AttachmentManager


        pTable = pFeatLayer
        pFeatCursor = pFeatureclass.Search(Nothing, False)
        pfeature = pFeatCursor.NextFeature()

        Do While Not pfeature Is Nothing

            OID = pfeature.OID
            filepath = pfeature.Value(pfeature.Fields.FindField("FilePath"))  'the field where you store the filename

            If Not filepath.Equals("999") Then 

                ' Open a file as a memory blob stream.
                Dim memoryBlobStream As IMemoryBlobStream = New MemoryBlobStreamClass()
                memoryBlobStream.LoadFromFile(filepath)

                ' Create an attachment.
                Dim attachment As IAttachment = New AttachmentClass With _
                                                { _
                                                .ContentType = "image/jpeg", _
                                                .Data = memoryBlobStream, _
                                                .Name = filepath _
                                                }

                ' Assign the attachment to the feature with ObjectID (OID) = 1.
                attachmentManager.AddAttachment(OID, attachment)

                pfeature.Store()
                pfeature = pFeatCursor.NextFeature

            Else
                pfeature = pFeatCursor.NextFeature()
            End If

        Loop

        pFeatCursor = Nothing
0 Kudos
AdamCottrell
Frequent Contributor
I was challenged with the same issue, so here's some psuedo code that may help.   Using the active layer, in an Edit session, this code will loop through a featureclass reading a value from a Filepath field.   Most people already have a column like this in their data, particularly if they use Hyperlinks.  If the filepath value is not null, the associated file is loaded as an attachment for that feature.

       
Dim pApplication As IApplication
        Dim pMxDocument As IMxDocument
        Dim pFeatLayer As IFeatureLayer
        Dim pFeatureclass As IFeatureClass
        Dim pTable As ITable
        Dim pContentsView As IContentsView3
        Dim pfeature As IFeature
        Dim pFeatCursor As IFeatureCursor
        Dim OID As Integer
        Dim filepath As String

        pApplication = m_application
        pMxDocument = pApplication.Document
        pContentsView = pMxDocument.CurrentContentsView

        Dim selectedItem As System.Object = pContentsView.SelectedItem
        If Not (TypeOf selectedItem Is ESRI.ArcGIS.Carto.ILayer) Then
            Return
        End If

        Dim layer As ESRI.ArcGIS.Carto.ILayer = TryCast(selectedItem, ESRI.ArcGIS.Carto.ILayer)
        pFeatLayer = TryCast(layer, ESRI.ArcGIS.Carto.FeatureLayer)
        pFeatureclass = pFeatLayer.FeatureClass

        Dim tableAttachments As ITableAttachments = CType(pFeatureclass, ITableAttachments)
        Dim attachmentManager As IAttachmentManager = tableAttachments.AttachmentManager


        pTable = pFeatLayer
        pFeatCursor = pFeatureclass.Search(Nothing, False)
        pfeature = pFeatCursor.NextFeature()

        Do While Not pfeature Is Nothing

            OID = pfeature.OID
            filepath = pfeature.Value(pfeature.Fields.FindField("FilePath"))  'the field where you store the filename

            If Not filepath.Equals("999") Then 

                ' Open a file as a memory blob stream.
                Dim memoryBlobStream As IMemoryBlobStream = New MemoryBlobStreamClass()
                memoryBlobStream.LoadFromFile(filepath)

                ' Create an attachment.
                Dim attachment As IAttachment = New AttachmentClass With _
                                                { _
                                                .ContentType = "image/jpeg", _
                                                .Data = memoryBlobStream, _
                                                .Name = filepath _
                                                }

                ' Assign the attachment to the feature with ObjectID (OID) = 1.
                attachmentManager.AddAttachment(OID, attachment)

                pfeature.Store()
                pfeature = pFeatCursor.NextFeature

            Else
                pfeature = pFeatCursor.NextFeature()
            End If

        Loop

        pFeatCursor = Nothing


This is going to sound stupid but did you use VBA to run this code? I'm trying to avoid VBA now since it will be no longer supported in future releases.
0 Kudos
richardBurdett
Deactivated User
Richard,

In the next release of ArcGIS we are looking at adding a geoprocessing tool that would give you the ability to use a key field to match a record in your table/feature class with a file stored on disk.

For example if you had a feature class containing sign posts with a photoID of 'sign1234' and you had a photo on disk named 'sign1234.jpg' you could attach photos based on this type of relationship.

Would these tools be useful with the way your data is currently stored?


Yes thats it! that would be perfect! Please hurry as this would be Indispensable to me!.   Many thanks!
0 Kudos
RussellBrennan
Esri Contributor
Yes thats it! that would be perfect! Please hurry as this would be Indispensable to me!.   Many thanks!


This is in ArcGIS 10.1, it will be shipping soon.

http://resources.arcgis.com/en/help/main/10.1/index.html#/Working_with_the_Attachments_geoprocessing...


0 Kudos
RachelOser
Emerging Contributor
ArcMap 10.1 Standard
Windows 7 Professional
12.0 GB Ram
64 Bit

I am trying to use the following Data Management Tools:  Attachments: "Generate Attachment Match Table" and "Add Attachments".  The "Generate Attachment Match Table" tool works perfectly, but my computer cannot seem to execute the "add attachments" command.  I tried reducing the size of the Match Table all the way down to three rows, but it still gets stuck.  Does anyone know what I am doing wrong?
0 Kudos
RachelOser
Emerging Contributor
In answer to my own question, I was creating an INFO table.  When I put the output match table inside the geodatabase instead, everything worked great.
0 Kudos
AuraRamos_Lora
Deactivated User
Instead of attaching the actual document to each feature and storing it in the geodatabase, is it possible to only store the LINK or PATH to the file in the geodatabase? 

I have a street feature class that i am attaching hundreds of as built .pdf documents to.  Because the geodatabase stores the actual file..it is getting very large very quickly.  And it's redundant because the files are already stored on the server.  The attachment feature is key because many of our users have arcgisexplorer and can view the documents as html pop ups from there.  However, I am running out of space!

Each street segment has a unique segment number but the as built documents are randomly numbered.  I have an access table that stores the segment number and it associated "asbuilt ID's" but they are not the same number. 

It would be VERY useful if we could just attach several "hyperlinks" to a feature and have those links stored in the geodatabase. 

Is this currently possbile or will it be in future releases? 

And I hope this makes sense to all of you 🙂


Someone found how to do this, I have the same problem, help please.
0 Kudos
RhettZufelt
MVP Notable Contributor
Richard,

In the next release of ArcGIS we are looking at adding a geoprocessing tool that would give you the ability to use a key field to match a record in your table/feature class with a file stored on disk.

For example if you had a feature class containing sign posts with a photoID of 'sign1234' and you had a photo on disk named 'sign1234.jpg' you could attach photos based on this type of relationship.

Would these tools be useful with the way your data is currently stored?


This would be a great option, if designed correctly.  As is, if I have a 20 square signs called s_sign with photos s1.jpg, s2.jpg, s3.jpg, etc.  Would be nice if it used the key/value pair in the lookup table to do the relate.  Instead, it takes the OID from the FIRST occurance of the feature (squaresign) and will attach every photo to the first occurance of s_sign, and all other s_sign features have none.  Seems like it completely defeats the anything to many relationship.  Seems that if, instead of converting the key value to the first OID that matches and using the actual key value column for the relate would actually give us what it claims.

R_

Professional ESRI beta tester
0 Kudos