Replace Imported Component

Replace Imported Component

ForrestJudd
Advocate Advocate
332 Views
2 Replies
Message 1 of 3

Replace Imported Component

ForrestJudd
Advocate
Advocate

I have an existing Inventor Assembly references a STEP file as a Reference Model. I would like to rename the step file to something else and replace the reference via the API.

 

If this was an Inventor document reference it would be straightforward - I can use the Replace method on the ComponentOccurrence(s) that reference the document and be done. However, if it is a referenced STEP file, it appears that ComponentOccurrence.Replace, when provided the name of a STEP file, will convert the STEP file - it doesn't continue to reference the STEP file.

 

I know I can add a new STEP file reference using the AssemblyDocument.ComponentDefinition.ImportedComponents.Add method, but I don't want to add a new one - I want to replace an existing one. Am I missing something or is what I need to do not possible?

0 Likes
333 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

Here is a route that might be viable. I haven't tested it to see. 

1.Syntax ImportedComponent.ReferencedDocumentDescriptor() As DocumentDescriptor

 

2.Syntax

DocumentDescriptor.ReferencedFileDescriptor() As FileDescriptor

 

3.Syntax

FileDescriptor.ReplaceReferenceFullFileName As String )

 

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

A.Acheson
Mentor
Mentor

It appears that the replace reference mentioned above is not functioning and there is no documented sample to do this, so here is another approach.  The  manual replace all correctly keeps the reference to an imported component and the import type referenced model. So the below codes simply automates this procedure. Here is the article that references running commands.

 

AAcheson_1-1656713107293.png

AAcheson_0-1656712994563.png

 

 

 

	' Get the command manager.
    Dim oCommandMgr As CommandManager = ThisApplication.CommandManager
	
	'Pick occurrence
	Dim oAssyoOcc As ComponentOccurrence = oCommandMgr.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Occurence")
	
	'Select the chosen occurrence for processing
	oCommandMgr.DoSelect(oAssyoOcc)
    
	'Clear the clipboard
	oCommandMgr.ClearPrivateEvents
	
	' Post the filename.
    Call oCommandMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,"C:\Users\Assembly5.stp")

    ' Get control definition for the place component command.
    Dim oControlDef As ControlDefinition= oCommandMgr.ControlDefinitions.Item("AssemblyReplaceAllCmd")

    ' Execute the command synchronously. 
    Call oControlDef.Execute2(True)

 

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