Hi
I amtrying to replace the reffernce of the unroslved file in the assembly
C:\Users\Marko\Desktop\3D\Workspace\Assembly3_6\Sklop\Assembly3_n1
When i run the rule in this file it won't replace the reference, but if i change the line higlithed in red
to any other file this code works.
I have attached the files in the attachment
This is driving me crazy please help
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oCompDef As ComponentDefinition oCompDef=oDoc.ComponentDefinition Dim occ As ComponentOccurrence For Each occ In oCompDef.Occurrences If occ.Name="" Then GoTo 1: If occ.IsSubstituteOccurrence = "True" Then GoTo 1 : Try If occ.Definition.Type =ObjectTypeEnum.kWeldsComponentDefinitionObject Then GoTo 1: Catch End Try If occ.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then occ.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference("C:\Users\Marko\Desktop\Reduktor1\Workspace\Assembly3_6\Assembly3_n1.iam") End If 1: Next End Sub
According to the help files: "The file being replaced and the replacement file must share ancestry (i.e. they must have the same InternalName). Documents have the same internal name if they are copied using 'Save Copy As' or a file explorer copy." I did not check your files but I guess that is the problem. As a test, you could check the internal names of the old and new files. Try the following rule:
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition
For Each occ As ComponentOccurrence In oCompDef.Occurrences
If occ.Name = "" Then Continue For
If occ.IsSubstituteOccurrence Then Continue For
Try
If occ.Definition.Type = ObjectTypeEnum.kWeldsComponentDefinitionObject Then Continue For
Catch
End Try
If occ.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim refDOc As Document = occ.ReferencedDocumentDescriptor.ReferencedDocument
Dim orgInternalName = refDOc.InternalName
Dim newFileName = "D:\forum\2022\exampleFile\AngleSupportPair.iam" ' "C:\Users\Marko\Desktop\Reduktor1\Workspace\Assembly3_6\Assembly3_n1.iam"
Dim newDoc As Document = ThisApplication.Documents.Open(newFileName)
Dim newInternalName = newDoc.InternalName
newDoc.Close(True)
If (orgInternalName <> newInternalName) Then
MsgBox("The file being replaced and the replacement file must share ancestry (i.e. they must have the same InternalName)")
Else
occ.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(newFileName)
End If
End If
Next
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
The files share an ancestry (Replace reference file is a copy of the unresolved file). I have tried to get the internal name of the unresolved file but it returns an error.
The problem is with the naming of the file. The files have the same name in the workspace
The main file Assembly3_n1.iam has the path:
C:\Users\Marko\Desktop\3D\Workspace\Assembly3_6\Sklop\Assembly3_n1.iam
And the resolve file has the path:
C:\Users\Marko\Desktop\3D\Workspace\Assembly3_6\Assembly3_n1.iam
If I change the resolve file name to Assembly3_n1-copy :
C:\Users\Marko\Desktop\3D\Workspace\Assembly3_6\Assembly3_n1-copy.iam
The code will work.
I don't know why can't change the reference to this path
C:\Users\Marko\Desktop\3D\Workspace\Assembly3_6\Assembly3_n1.iam
Can't find what you're looking for? Ask the community or share your knowledge.