Component Rename after Replace

Component Rename after Replace

jfenter
Enthusiast Enthusiast
658 Views
2 Replies
Message 1 of 3

Component Rename after Replace

jfenter
Enthusiast
Enthusiast

I am creating a configurable assembly using a component replace command.  After the replacement completes, the model tree name updates as well and essentially breaks the iLogic code, preventing further configurations from happening (or reverting back to the previous configuration).

 

I'm hoping to add code that can keep the existing model tree name as the assembly is configured.  

 

'
ExcelFile = "X:\Acad\PRD\JMF\Drawers\DRAWERS.xlsx"

MultiValue.List("DrawerBox") = GoExcel.CellValues(ExcelFile, "T-Lock", "A2", "")
SharedVariable("DrawerSearch") = GoExcel.FindRow(ExcelFile, "T-Lock", "Description", "=", DrawerBox)

Dim leftSide As String
leftSide = GoExcel.CurrentRowValue("LH Side")
Dim drawerLH As String
drawerLH = "C:\Work\Library\30_Drawers\Parts\" & leftSide & "_IPT_111.ipt"

Dim rightSide As String
rightSide = GoExcel.CurrentRowValue("RH Side")
Dim drawerRH As String
drawerRH = "C:\Work\Library\30_Drawers\Parts\" & rightSide & "_IPT_111.ipt"

Dim dBack As String
dBack = GoExcel.CurrentRowValue("Back")
Dim drawerBack As String
drawerBack = "C:\Work\Library\30_Drawers\Parts\" & dBack & "_IPT_111.ipt"

Dim dBottom As String
dBottom = GoExcel.CurrentRowValue("Bottom")
Dim drawerBottom As String
drawerBottom = "C:\Work\Library\30_Drawers\Parts\" & dBottom & "_IPT_111.ipt"

'Dim dBrace As String
'dBrace = GoExcel.CurrentRowValue("Brace")
'Dim drawerBrace As String
'drawerBrace = "C:\Work\Library\30_Drawers\Parts" & dBrace & "_IPT_111.ipt"

Component.Replace("RH DWR SIDE:1", drawerRH, True)
Component.Replace("LH DWR SIDE:1", drawerLH, True)
Component.Replace("DRAWER BACK:1", drawerBack, True)
Component.Replace("DWR BTM:1", drawerBottom, True)
0 Likes
Accepted solutions (1)
659 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

A simple fix that actually requires less code than you think.

 

Existing snippet:

Component.Replace("RH DWR SIDE:1", drawerRH, True)

 

What is happening is that the rule is targeting the occurrence name of the current part which is “RH DWR SIDE:1“

This name is automatically linked from your file name. 

So to keep the target name you need to break this link and rename the browser node with a constant name call it “RH DWR SIDE” or any name that is unique. This has the effect that bringing in the next part using replace will inherit this constant name. 


Target occurrence name that has been stabilized. 

Component.Replace("RH DWR SIDE", drawerRH, True)

 
 To stabilize automatically, you will need to use the API to loop through the occurrences of the assembly using the occurrence.name =“……..”

One method would be to split the string of the the existing display name removing the “:1”

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

jfenter
Enthusiast
Enthusiast

Beautifully simple!  So simple I missed what you changed at first!  Thanks!

0 Likes