Access Parent to set reference

Access Parent to set reference

Leonardo_Czuy
Advocate Advocate
180 Views
2 Replies
Message 1 of 3

Access Parent to set reference

Leonardo_Czuy
Advocate
Advocate

I am trying to change the filenames without losing references, and when I have one assembly within another assembly, the file references get lost.

On line 22, if its parent is different from 'asmDoc,' take its parent to set the reference, but I am not able to access the parent from oDoc.

Leonardo_Czuy_0-1701949536722.png

 

	'set a reference to the assembly component definintion
	Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDoc As Inventor.Document
	
	'Store referenced documents properties
	For Each oDoc In asmDoc.AllReferencedDocuments
		Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
		Dim fileType As String = System.IO.Path.GetExtension(oDoc.FullFileName)
		
		Dim DrawCode As String
		DrawCode = FindObject(fileName, fileType)
		
		If DrawCode Is Nothing Then Continue For
		
		'iProperties.Value(oDoc.DisplayName, "Custom", "Codigo Antigo") = fileName
		
		Dim directoryPath As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
		Dim newFilePath As String = System.IO.Path.Combine(directoryPath, DrawCode)
		Dim oldFilePath As String = oDoc.FullFileName


		If oDoc.Parent.Name <> asmDoc.DisplayName 

		' Renomeia o arquivo
		Try
			oDoc.SaveAs(newFilePath, False)
			asmDoc.File.ReferencedFileDescriptors.Item(oldFilePath).ReplaceReference(newFilePath)
        Catch ex As Exception
			errorRename.add(fileName)
        End Try
		
		' Exclui o arquivo antigo
		Try
			System.IO.File.Delete(oldFilePath)
		Catch ex As Exception
			errorRemove.add(fileName)
		End Try
	Next

 

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

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Leonardo_Czuy.  I am not sure, but it sounds like you changed the name of one or more of the files that the components you have a red box around are referencing.  And now you want to replace those components or file references within the parent level assemblies.  Does that sound correct?  If so, then you will need to use a different primary path than using AssemblyDocument.AllReferencedDocuments.  I would recommend one of two routes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

Leonardo_Czuy
Advocate
Advocate
Hello @WCrihfield, yes you are correct. I will try this. Thanks for help.
0 Likes