Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replace Refference problem

4 REPLIES 4
Reply
Message 1 of 5
markohog
250 Views, 4 Replies

Replace Refference problem

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



 

4 REPLIES 4
Message 2 of 5
markohog
in reply to: markohog

The files i want to copy are attached in the post above.

Message 3 of 5
markohog
in reply to: markohog

Anyone?

Message 4 of 5
JelteDeJong
in reply to: markohog

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.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 5
markohog
in reply to: markohog

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.

markohog_0-1662204660130.png

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.

Post to forums  

Autodesk Design & Make Report