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: 

Component Replace with Target Path

1 REPLY 1
SOLVED
Reply
Message 1 of 2
W_Barnett
191 Views, 1 Reply

Component Replace with Target Path

***Solved***

1. Manually named components that are replaced will keep their overwritten names.  You can check if "Component.Replace" worked correctly by checking iProperties.

 

2. If a command isn't working as intended, and you know it should, then try restarting Inventor.  Would have saved me about 2 hours this morning if I had just restarted and tried running the rule again.

 

***Original Post***

I've been trying to replace a part file in an assembly using iLogic, however the component is not actually being replaced with anything.  I've tried four different methods:

  • Target object occurrence (oOcc) and replace (oOcc.Replace...)
  • Component Replace using string variables (I want to replace "Comp_A:1" with "P:\...\temp_Comp_A.ipt")
  • Component Replace using manually typed strings.
  • Component Replace using oOcc.Name and file path.

Nothing is working.  I understand that Component.Replace will replace components within the same folder, but I've read several places (including the code snippet) that I can use a target path.  Is there a work around?  Here's the code in question:

 

Sub Main()
	Dim oldPart = "Comp_A:1"
	Dim newPart = "P:\...\temp_Comp_A.ipt".       '*** Demo String for Forum Post.
	
	'*** Method 1
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	oADef = oADoc.ComponentDefinition
	oOccs = oADef.Occurrences
	Dim oOcc As Object
	
	For Each oComp As ComponentOccurrence In oOccs
		If oComp.Name = oldPart Then
			Logger.Debug("oComp is: " & oComp.Name & ".  It should be the same as " & oldPart)
			oOcc = oComp
		End If
	Next
	
	Logger.Debug("Attempting to replace component now...")
	oOcc.Replace(newPart, False)
	
	'*** Method 2
	Component.Replace(oldPart, newPart, False)
	
	
	'*** Method 3
	Component.Replace("Comp_A:1", "temp_Comp_A.ipt", False)
	
	'*** Method 4
	Component.Replace(oOcc.Name, newPart, False)

	InventorVb.DocumentUpdate()
	
End Sub

 

Labels (1)
1 REPLY 1
Message 2 of 2
W_Barnett
in reply to: W_Barnett

Method 1 works as intended.  Turns out I needed to restart Inventor.

 

I did however learn that manually named components in the model browser do not have their names updated when you "Component.Replace" them.  Makes things extremely confusing.  I couldn't figure out why 4 out of 5 components got replaced correctly, but that one just wouldn't change.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report