'TITLE: ATTACHMENT EXAMPLE.BAS 'DESCRIPTION: This macro exports attachment data for each bound ' attachment for every selected table in the active model. ' The file name and path is "C:\Attachment Data.txt" ' ' Dim ER/Studio variables Dim diag As Diagram Dim ent As Entity Dim attmnt As Attachment Dim battmnt As BoundAttachment Dim mdl As Model Dim submdl As SubModel Dim so As SelectedObject Dim notepad As Object ' output string Dim outstring As String Sub Main Set diag = DiagramManager.ActiveDiagram Set mdl = diag.ActiveModel Set submdl = mdl.ActiveSubModel 'loop through the selected objects For Each so In submdl.SelectedObjects 'only get the entities. If so.Type = 1 Then 'grab entity using the ID from the selected object Set ent = mdl.Entities.Item(so.ID) 'outstring will be used to write to the text file 'write the entity name and table name outstring = outstring & "Entity Name: " & ent.EntityName & vbCrLf & "Table Name: " & ent.TableName & vbCrLf 'determine if there are any bound attachments If ent.BoundAttachments.Count = 0 Then outstring = outstring & vbTab & "No attachments on entity/table." & vbCrLf Else 'loop through bound attachments For Each battmnt In ent.BoundAttachments 'set attachment object to the base attachment from the data dictionary. Set attmnt = battmnt.Attachment 'output the name (from the attachment in dictionary) outstring = outstring & vbTab & "Attachment Name: " & attmnt.Name & vbCrLf 'output the type the attachment belongs to (again from the dictionary) outstring = outstring & vbTab & vbTab & "Parent Type: " & attmnt.AttachmentType.Name & vbCrLf 'output the override value, this comes from the bound attachment since the value 'is overridden on the table outstring = outstring & vbTab & vbTab & "Override value: " & battmnt.ValueOverride & vbCrLf 'output the default value, this is from the attachment in the data dictionary. outstring = outstring & vbTab & vbTab & "Default Value: " & attmnt.ValueDefault & vbCrLf outstring = outstring & vbCrLf Next End If outstring = outstring & vbCrLf End If Next 'write outstring to file Open "C:\Attachment Data.txt" For Output As #1 Print #1, outstring Close #1 MsgBox("Done! See ""c:\Attachment Data.txt""",vbOkOnly) End Sub
'TITLE: ATTACHMENT EXAMPLE.BAS 'DESCRIPTION: This macro exports attachment data for each bound ' attachment for every selected table in the active model. ' The file name and path is "C:\Attachment Data.txt" ' ' Dim ER/Studio variables Dim diag As Diagram Dim ent As Entity Dim attmnt As Attachment Dim battmnt As BoundAttachment Dim mdl As Model Dim submdl As SubModel Dim so As SelectedObject Dim notepad As Object ' output string Dim outstring As String Sub Main Set diag = DiagramManager.ActiveDiagram Set mdl = diag.ActiveModel Set submdl = mdl.ActiveSubModel 'loop through the selected objects For Each so In submdl.SelectedObjects 'only get the entities. If so.Type = 1 Then 'grab entity using the ID from the selected object Set ent = mdl.Entities.Item(so.ID) 'outstring will be used to write to the text file 'write the entity name and table name outstring = outstring & "Entity Name: " & ent.EntityName & vbCrLf & "Table Name: " & ent.TableName & vbCrLf 'determine if there are any bound attachments If ent.BoundAttachments.Count = 0 Then outstring = outstring & vbTab & "No attachments on entity/table." & vbCrLf Else 'loop through bound attachments For Each battmnt In ent.BoundAttachments 'set attachment object to the base attachment from the data dictionary. Set attmnt = battmnt.Attachment 'output the name (from the attachment in dictionary) outstring = outstring & vbTab & "Attachment Name: " & attmnt.Name & vbCrLf 'output the type the attachment belongs to (again from the dictionary) outstring = outstring & vbTab & vbTab & "Parent Type: " & attmnt.AttachmentType.Name & vbCrLf 'output the override value, this comes from the bound attachment since the value 'is overridden on the table outstring = outstring & vbTab & vbTab & "Override value: " & battmnt.ValueOverride & vbCrLf 'output the default value, this is from the attachment in the data dictionary. outstring = outstring & vbTab & vbTab & "Default Value: " & attmnt.ValueDefault & vbCrLf outstring = outstring & vbCrLf Next End If outstring = outstring & vbCrLf End If Next 'write outstring to file Open "C:\Attachment Data.txt" For Output As #1 Print #1, outstring Close #1 MsgBox("Done! See ""c:\Attachment Data.txt""",vbOkOnly) End Sub