Replacing References to an assembly model (VB.NET)

Replacing References to an assembly model (VB.NET)

shrey9GP3F
Enthusiast Enthusiast
442 Views
2 Replies
Message 1 of 3

Replacing References to an assembly model (VB.NET)

shrey9GP3F
Enthusiast
Enthusiast

Hello,

 

I am trying to replace all the references in my newly copied assembly model. But when I run the code, it gives me the error below. I cannot figure out what's wrong with the code.

shrey9GP3F_0-1629129186398.png

 

 

 

Public Function assemblyDescriptor(assmFileName As String, oSuff As String)
	' assmFileName is the full loction of the new assembly, and oSuff is the suffix
	Dim assDoc As AssemblyDocument = ThisApplication.Documents.Open(assmFileName, False)
	Dim ostr As String =""
	
	For Each occ As DocumentDescriptor In assDoc.ReferencedDocumentDescriptors
		
		Dim oSubDir As String = System.IO.Path.GetDirectoryName(occ.FullDocumentName)
		Dim oSubFileName As String = System.IO.Path.GetFileNameWithoutExtension(occ.FullDocumentName)
		Dim oSubFileExt As String = System.IO.Path.GetExtension(occ.FullDocumentName)
		Dim oSubNewFileName As String = oSubDir & oSuff & "\" & oSubFileName & oSuff & oSubFileExt
		
		
		If System.IO.File.Exists(oSubNewFileName) Then
						
				Try
					occ.ReferencedFileDescriptor.ReplaceReference(oSubNewFileName)
					assDoc.Update
				Catch ex As Exception
					MessageBox.Show(ex.Message)
				End Try
				
				
				ostr += oSubNewFileName & vbCrLf
			End If
		
	Next
	MessageBox.Show(ostr)
	
	assDoc.Update
		
End Function

 

 

0 Likes
Accepted solutions (1)
443 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Using INV 2020 I tested this in a one part model and could not get an error. Perhaps it was erroring out for another reason somewhere else in you rule. Post the remainder of the rule if you still have an error or a simple assembly in a zipped folder  where the error is occurring.

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3

shrey9GP3F
Enthusiast
Enthusiast

Hi @A.Acheson ,

 

Thanks for replying. I actually found out the issue. My drawing file was open while I was trying to change the references in the assembly file. For some reason, that was conflicting. I have already fixed the issue but I could not remove this post. 

 

Thank you again.

0 Likes