An example of creating a custom script as a copy of a system script is given for the SaveArticleAs script. Let's assume you want to customize its behavior in some way, for example, to make it remember the last destination folder and not to default to the folder of the original article.
Firstly, in CustomTedOptions.vb add the line:
<XmlAttribute()> Public T_LastSaveAsFolderId As Integer = 0
as shown on the following screenshot:
In CustomArticle.vb, in the CustomTxtDesignerAddIn class, paste the below code (take care that text doesn’t wrap before selecting it and pasting. The differences with the standard ArticleSaveAs script are highlighted:
Public Overloads Sub ArticleSaveAs()
'v2 - recalls folderid of the original article; offers the name "Copy of "; uses ArticleSaveAs object UI
If ActiveArticle IsNot Nothing Then
Dim dlg As New NewObjDialog(TedApp.ClientApp().MainWindow, False)
If SystemUserOptions.T_NoOpenOnSaveAs = False Then
dlg.TitleFormat = My.Resources.IDS_SaveArticleAs
Else
dlg.TitleFormat = My.Resources.IDS_CopyArticle
End If
dlg.AddParameter("name", "Copy of " & Ted.GetActiveArticle.Name)
If CustomUserOptions.T_LastSaveAsFolderId = DBDesc.InvalidId Then
dlg.AddParameter("folderId", Ted.GetActiveArticle.FolderId)
Else
dlg.AddParameter("folderId", CustomUserOptions.T_LastSaveAsFolderId)
End If
' get categories from the source article
Dim firstSourceId = Ted.GetActiveArticle.Id
Dim firstSourceCats As IList(Of GenericAccessObj) = Editorial.EditorialLogin.GetLogin.GetAccessObjs(New Integer() {firstSourceId}, New ObjLoadDesc(New String() {"cats"}, Nothing))
Dim sourceCats As MultiCategoryValue = Nothing
' if there are categories in the source...
If Not firstSourceCats Is Nothing Then
sourceCats = CType(firstSourceCats(0).Obj.GetResolvedAttributeValue("cats"), MultiCategoryValue) '... get the sourceCats object...
If Not sourceCats Is Nothing Then
For i = 0 To sourceCats.NValues - 1 '... and then parse all it's members and add it as a new parameter to the dialog - later processed by NewArticle init
dlg.AddParameter("storyCats_" & CType(i, String), "obj" & sourceCats.Values(i).Id & "|" & sourceCats.Values(i).Weight)
Next
End If
End If
dlg.ObjectUI = DataConnection.Instance.ObjectUIConfig.GetObjectUI("ArticleSaveAs")
dlg.SetObjectType("article")
If dlg.ShowDialog() Then
Dim folderId As Integer = dlg.FolderId
CustomUserOptions.T_LastSaveAsFolderId = dlg.FolderId
Dim name As String = dlg.ObjectName
Dim objA As Article
objA = ActiveArticle
Dim newId As Integer = objA.SaveAs(name, folderId, dlg.Obj)
If (newId <> 0) Then
' clean all tags but para styles from copy CRASHES TED
' ShellWindow.ProgressBar(0, objA.NTxts - 1, "Cleaning tags...")
' For t = 0 To objA.NTxts - 1
' ShellWindow.ProgressBar(t, objA.NTxts - 1, "Cleaning tags...")
' objA.GotoTxt(t, True, False)
' DeleteTags(True, False)
' Next
' ShellWindow.ProgressBar(0, Nothing, Nothing)
If SystemUserOptions.T_NoOpenOnSaveAs = False Then
TxtDesigner.Close()
TxtDesigner.Group.OpenObjectType(newId, "article", OpenMode.ReadWrite)
End If
End If
End If
End If
End Sub
On the first load, the folder id will default to the same folder where the article is, but when you select another destination folder, it will be remembered in the CustomUserOptions.T_LastSaveAsFolderId and proposed in future.