iLogic - Keep old occurrence name with Component.Replace

iLogic - Keep old occurrence name with Component.Replace

Binary12
Contributor Contributor
901 Views
2 Replies
Message 1 of 3

iLogic - Keep old occurrence name with Component.Replace

Binary12
Contributor
Contributor

 

Hi,

 

I'm working on a ilogic driven assembly where I want to be able to replace all components with a given placeholder, copy out files from a directory and put them back in the assembly again replacing the placeholder.

 

So far I've got it to work up until reinserting the new components as the component occurrence name changes when I insert the placeholder.

 

 

Here's an example of what I'm trying to do:

 

If ReplaceToPlaceholder = True Then

'Walls
Component.Replace("Wall_Front", "PLACEHOLDER.ipt", False)
End If





AssemblyDir = Component.InventorComponent("MASTER")
Dim Workpath As String = System.IO.Path.GetDirectoryName(AssemblyDir.Definition.Document.FullDocumentName) & "\"

'Defines the search path for BaseComponents
Dim LibraryPath As String = Workpath & "\BaseComponents\"

'Define files for copying
Dim WallPart As String = "Wall.ipt"


		If ReInsertParts = True Then
		
		'Walls
		System.IO.File.Copy(LibraryPath & WallPart, Workpath & "Wall_Front" & ".ipt", True)
		
		
		Component.Replace("Wall_Front", "Wall_Front.ipt", False)
		
		End If

I have given both the placeholder and the part Wall_Front.ipt a "stabilized" name (I think... I changed the component Wall_Front:1 to Wall_Front) but whenever I replace it the placeholder part is called "PLACEHOLDER:1". I need the occurrence name to stay as Wall_Front to reinsert the part.

 

Any ideas how this can be done?

 

 

Thanks for any advice!

 

/Fredrik

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

Jef_E
Collaborator
Collaborator

Best option is to work via the API.

 

If I use this code in iLogic it works just fine and keeps the name. Up to you to set the correct path.

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oOccurrence As ComponentOccurrence
oOccurrence = oDoc.ComponentDefinition.Occurrences.ItemByName("Wall_Front")

oOccurrence.Replace("C:\VaultWorkspace\cadcampc\test derived compo\Part6.ipt", False)


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 3 of 3

MjDeck
Autodesk
Autodesk
Accepted solution

Hi Fredrik,

 In Inventor 2016 and later, it's harder to stabilize the component name. You have to change the name to something that does not match any filename. Instead of "Wall_Front" you could use "Wall_Front (replaceable)".


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes