Hello Philippe,
I didn´t posted all the details of my little project. What I´m trying to do is basically a customized copy function for design templates. What I´m doing is using the DocumentsEnumerator of the assembly with AllReferencedDocuments to catch all document references.
When there are derived parts in the assembly with suppressed links they are not in the Enumeration. So I wasn´t able to catch the document references of these suppressed base parts.
I´m cycling through all Referenced Documents in one rule. When I put in the code for activating suppressed links somewhere in that loop it will do that but they will not be added to the enumeration (obviously).
So I created another rule which is called before I start the loop and instantiation of the enumerator and that did the trick.
Actually I wanted to have all the code in one rule but I guess I´m running into limitations here either on my skills or iLogic.
Here is the whole code (without the ActivateSuppressedReference Rule):
Sub Main()
iLogicVb.RunExternalRule("ActivateSupressedReference")
Dim Path As String = ThisDoc.WorkspacePath & "\"
Dim oldPath As String = ThisDoc.Path & "\"
'MessageBox.Show(Path, "Workspace-Pfad")
'MessageBox.Show(oldPath, "alter Workspace-Pfad")
oInvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = oInvDoc.AllReferencedDocuments
Dim refDoc As Document
For Each refDoc In refDocs
Dim oldDisplayName As String = refDoc.DisplayName
'read filename with file extension
Dim Filename_Ext As String = refDoc.FullFileName.Substring(oldpath.length)
'get the extension of the file
Dim strFileExtension As String = Filename_Ext.substring(Filename_Ext.Length-4,4)
'get the filename without extension from the filename with extension
Dim Filename As String = Filename_Ext.substring(0,Filename_Ext.Length-4)
'detect If document Is Assembly And save As Assembly
If refDoc.DocumentType = 12291 Then
'define new Name for copy of the referenced document
NewFileName = InputBox("Geben Sie den neuen Namen für die Baugruppe " & Filename_Ext &" ein!","Neuer Dateiname", Filename)
'check For blank filename And Set To DisplayName
If NewFileName = "" Then
NewFileName = Filename
End If
'check For extension In name And remove If there
If NewFileName.EndsWith(".iam") = True Then
NewFileName = NewFileName.Substring(0,NewFileName.length-4)
'MessageBox.Show(NewFileName)
End If
refDoc.SaveAs(Path & NewFileName & ".iam",False)
refDoc.DisplayName = oldDisplayName
Call CopyDrawing(Path, oldPath, Filename_Ext, NewFileName)
Else
'initialize object for PartComponentDefinition to access property if part is member of content center
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = refDoc.ComponentDefinition
If Not oPartCompDef.IsContentMember Then
NewFileName = InputBox("Geben Sie den neuen Namen für das Bauteil " & Filename &" ein!","Neuer Dateiname", Filename)
'check For blank filename
If NewFileName = "" Then
NewFileName = Filename
End If
'check For extension In name And remove If there
If NewFileName.EndsWith(".ipt") = True Then
NewFileName = NewFileName.substring(0,NewFileName.length-4)
'MessageBox.Show(NewFileName)
End If
refDoc.SaveAs(Path & NewFileName & ".ipt",False)
refDoc.DisplayName = oldDisplayName
Call CopyDrawing(Path, oldPath, Filename_Ext, NewFileName)
Else
'MessageBox.Show("Die Komponente " & refDoc.DisplayName & "ist ein Content Center Part und wird nicht kopiert !")
End If
End If
Next
NewAssemblyName = InputBox("Wie lautet der neue Name für die Haupt-Baugruppe?", "Neuer Baugruppenname", ThisDoc.FileName(False))
If NewAssemblyName = "" Then
NewAssemblyName = ThisDoc.FileName(False)
Dim oldAssemblyName = ThisDoc.FileName(True)
ThisDoc.Document.SaveAs(Path & NewAssemblyName & ".iam",False)
'ThisDoc.Document.DisplayName = oldAssDisplayName
Call CopyDrawing(Path, oldPath, oldAssemblyName, NewAssemblyName)
Else
If NewAssemblyName.EndsWith(".iam") = True Then
NewAssemblyName = NewAssemblyName.Substring(0,NewAssemblyName.length-4)
End If
Dim oldAssemblyName = ThisDoc.FileName(True)
ThisDoc.Document.SaveAs(Path & NewAssemblyName & ".iam",False)
'ThisDoc.Document.DisplayName = oldAssDisplayName
Call CopyDrawing(Path, oldPath, oldAssemblyName, NewAssemblyName)
MessageBox.Show("Main Assembly kopiert")
End If
'Dim ctrl As ControlDefinition
'ctrl = ThisApplication.CommandManager.ControlDefinitions("AppSaveAllCmd")
'ctrl.Execute()
End Sub
Private Sub CopyDrawing (ByVal NewPath As String, ByVal oldPath As String, ByVal oldName As String, ByVal NewName As String)
Dim oDestinationDoc As DrawingDocument
Dim strFileExtension As String = oldName.substring(oldName.Length-4,4)
oldName = oldName.substring(0,oldName.Length-4)
Dim sFileName As String = oldPath & oldname & ".idw"
Try
If System.IO.File.Exists(sFileName) Then
oDestinationDoc = ThisApplication.Documents.Open(sFileName)
oDestinationDoc.SaveAs(NewPath & NewName & ".idw",False)
Dim oDocDescriptor As DocumentDescriptor
oDocDescriptor = oDestinationDoc.ReferencedDocumentDescriptors.Item(1)
Dim oFileDescriptor As FileDescriptor
oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor
oFileDescriptor.ReplaceReference(NewPath & NewName & strFileExtension)
oDestinationDoc.Update()
oDestinationDoc.Close
End If
Catch
oDestinationDoc.Close
MessageBox.Show("error")
End Try
End Sub
Private Sub ActivateSupRef(ByVal oDoc As Document)
Dim oDerivDoc As Document
Try
If oDoc.ReferencedDocumentDescriptors.Item(1).ReferenceSuppressed Then
oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1).SuppressLinkToFile = False
oDerivDoc = oDoc.ReferencedDocuments.Item(1)
End If
Catch
End Try
'If oDoc.ReferencedDocuments.Count > 0 Then
'oDerivDoc = oDoc.ReferencedDocuments.Item(1)
'MessageBox.Show(oDerivDoc.DisplayName & " is Basepart for derived Part "& oDoc.DisplayName &" !")
'End If
End Sub
The code is a bit garbled up due to testing and trying different approaches but I hope it´s still readable.
I thought it might be possible after activating the suppressed references to add them to the enumeration so the base parts for the derived parts going through the same loop as all the other components.
Cheers Falk