Replace References on mulit sheet drawing with ILogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I spent hours to find a solution for my "problem" but unfortunately without any luck.
I found the rule below in another post and customised it so far, the only thing I can't get working is the Replace References part in the "privat sub".
We are working with mulit sheet drawings and I want the rule to go through each sheet and replace the referenced models which has been created in the first part of the rule but I can only get the rule to change/replace the reference on the first sheet.
I tried already to change the referenceddocuemntdiscriptions.item(1), added a "for each ... in .." but only with the result in getting the ERROR message.
Can some one either point out to me what I need to change to get the rule working or change it for me?
Sub Main() Dim Path As String = ThisDoc.Path & "\" Dim tPath As String = ThisDoc.WorkspacePath + "\Test Ordner\Bauteile & -gruppen\" Dim FileChange As Boolean = False InvDoc = ThisDoc.Document Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments Dim refDoc As Document 'MessageBox.show(refDoc.DisplayName) Dim ext As String 'input box to enter new file name ext = InputBox("What is the ending for the files?", "New File Name", "-") 'NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", iProperties.Value(refDoc.DisplayName, "Project", "Part Number")) If ext = 0 Then Exit Sub End If 'if the new file name is blank then use the same name If ext = "" Then MessageBox.Show("Fehler darf nicht leer sein, bitte eine engabe machen", "Fehler") End If For Each refDoc in refDocs If refDoc.DisplayName.EndsWith(".ipt") = True Then refDoc.DisplayName = refDoc.DisplayName.substring(0,refDoc.DisplayName.length-4) 'MessageBox.show(NewFileName) End If NewFileName = refDoc.DisplayName + ext If refDoc.DisplayName <> NewFileName & ".ipt" Then If System.IO.File.Exists(tPath & NewFileName & ".ipt") Then Component.Replace(refDoc.DisplayName, tPath & NewFileName & ".ipt", True) Else Dim oldName As String = refDoc.DisplayName + ".ipt" 'if it does not exist then recreate the file refDoc.saveas(tPath & NewFileName & ".ipt",False) Call UpdateDrawing(Path, oldName, NewFileName) End If FileChange = True End If Next If FileChange = True Then NewAssemblyName = refDoc.DisplayName + ext If NewAssemblyName <> "" Then Dim oldName As String = ThisDoc.FileName(True) 'include extension ThisDoc.Document.SaveAs(tPath & NewAssemblyName & ".iam" , False) Call UpdateDrawing(Path, oldName, NewAssemblyName) End If End If iLogicVb.UpdateWhenDone = True End Sub Private Sub UpdateDrawing (ByVal Path As String, ByVal oldName As String, ByVal newName As String) Dim zPath As String = ThisDoc.WorkspacePath + "\Test Ordner\zeichnungen\" Dim tPath As String = ThisDoc.WorkspacePath + "\Test Ordner\Bauteile & -gruppen\" Dim oDestinationDoc As DrawingDocument Dim strFileExtension As String If oldName.EndsWith(".ipt") Or oldName.EndsWith("iam") Then strFileExtension = oldName.substring(oldName.Length-4,4) End If If oldName.EndsWith(".ipt") Or oldName.EndsWith("iam") Then oldName = oldName.substring(0,oldName.Length-4) End If Dim sFileName As String = Path & oldName & ".idw" Try If System.IO.File.Exists(sFileName) Then oDestinationDoc = ThisApplication.Documents.Open(sFileName) oDestinationDoc.saveas(zPath & newName & ".idw",False) Dim oDocDescriptor As DocumentDescriptor oDocDescriptor = oDestinationDoc.ReferencedDocumentDescriptors.Item(1) Dim oFileDescriptor As FileDescriptor oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor oFileDescriptor.ReplaceReference(tPath & newName & strFileExtension) oDestinationDoc.Update() oDestinationDoc.Close End If Catch oDestinationDoc.Close MessageBox.Show("error") End Try End Sub