Link Parameters After Component/Part Name Change in Assembly

Link Parameters After Component/Part Name Change in Assembly

swatkins3YWDA
Contributor Contributor
306 Views
2 Replies
Message 1 of 3

Link Parameters After Component/Part Name Change in Assembly

swatkins3YWDA
Contributor
Contributor

I have an assembly drawing where I will place a wheel and axle shaft.  After placing the parts, I have a name change for the wheel and axle, then save as a new file in a specified folder.  This all works great, many thanks to the ones who contributed in the code.  My issue is after the component name change my link parameters do not work.  How can I use a wild card or change the code to reflect the new component names?  

 

This is the code to insert the wheel and axle.  Axle not coded yet.  This code runs perfect.

'Insert Wheel
Dim componentA = Components.Add("R10S WHEEL:1", "Z:\ENGINEERING\CAD\MFG. DRAWINGS\ROCKENG\2 - 3D WHEEL MODELS\10in FORGINGS\R10S WHEEL.ipt", position := Nothing, grounded := True, visible := True, appearance := Nothing)




' Get current location of where you want the search area to be.
Dim ExportPath As String = (”Z:\ENGINEERING\CAD\MFG. DRAWINGS\ROCKENG”)


' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
	' User clicked 'ok' on dialog box - capture the export path
	ExportPath = Dialog.SelectedPath & "\"
	
Else
	' User clicked 'cancel' on dialog box - exit
	Return
End If


Dim Path As String = ExportPath
MessageBox.Show(Path, "Directory path")

InvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document

Dim PartN As String = "FileName"
PartN = InputBox("Prompt", "Title", PartN)
For Each refDoc In refDocs
    'MessageBox.Show(refDoc.DisplayName)
    If refDoc.DisplayName.EndsWith("R10S WHEEL.ipt") = True Then
        NewFileName = PartN & " WHEEL.ipt"
        refDoc.SaveAs(Path & NewFileName, False)
    ElseIf refDoc.DisplayName.EndsWith("STUB AXLE.ipt")= True Then
        NewFileName = PartN & " AXLE.ipt"
        refDoc.SaveAs(Path & NewFileName, False)
    End If
Next


ThisDoc.Document.SaveAs(Path & PartN & ".iam", False)

iLogicVb.UpdateWhenDone = True

 

This is my parameter link code.  How do I get the R10S WHEEL changed to the new file name?

Parameter("R10S WHEEL", "WheelGage") = WheelGage
Parameter("R10S WHEEL", "WheelWidth") = WheelWidth
Parameter("R10S WHEEL", "WheelBore") = WheelBore
Parameter("R10S WHEEL", "WheelFlangeWidth") = WheelFlangeWidth
Parameter("R10S WHEEL", "WheelFlangeOffset") = WheelFlangeOffset
Parameter("R10S WHEEL", "WheelFlangeDia") = WheelFlangeDia
Parameter("R10S WHEEL", "HubCapOffset01") = HubCapOffset01
Parameter("R10S WHEEL", "HubCapDiaBore") = HubCapDiaBore
Parameter("R10S WHEEL", "RetainerRingWidth") = RetainerRingWidth
Parameter("R10S WHEEL", "RetianerRingOffset") = RetianerRingOffset
Parameter("R10S WHEEL", "RetainerRingDia") = RetainerRingDia
Parameter("R10S WHEEL", "AlemiteOffset01") = AlemiteOffset01
Parameter("R10S WHEEL", "AlemiteOffset02") = AlemiteOffset02
Parameter("R10S WHEEL", "AlemiteOffset03") = AlemiteOffset03
Parameter("R10S WHEEL", "AlemiteCBoreDia") = AlemiteCBoreDia
Parameter("R10S WHEEL", "AlemiteCBoreDepth") = AlemiteCBoreDepth
Parameter("R10S WHEEL", "AlemiteAngle") = AlemiteAngle
Parameter("R10S WHEEL", "WheelWidth") = WheelWidth
Parameter("R10S WHEEL", "BoreType") = BoreType

 My original wheel name is R10S WHEEL.

 

This is the new file name and changed component name change.

swatkins3YWDA_0-1651256966165.png

This is before running the rules.

swatkins3YWDA_1-1651257015173.png

 

Thank you,

Samantha

 

Inventor 2022.2

 

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

dalton98
Collaborator
Collaborator

You need to replace the first wheel with the newly created one

I highlighted the code I changed:

Dim InvDoc As AssemblyDocument = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document

Dim PartN As String = "FileName"
PartN = InputBox("Prompt", "Title", PartN)
For Each refDoc In refDocs
    'MessageBox.Show(refDoc.DisplayName)
    If refDoc.DisplayName.EndsWith("R10S WHEEL.ipt") = True Then
        NewFileName = PartN & " WHEEL.ipt"
        refDoc.SaveAs(Path & NewFileName, True)
	InvDoc.ComponentDefinition.Occurrences.ItemByName("R10S WHEEL:1").Replace(NewFileName, True)
    ElseIf refDoc.DisplayName.EndsWith("STUB AXLE.ipt")= True Then
        NewFileName = PartN & " AXLE.ipt"
        refDoc.SaveAs(Path & NewFileName, False)
    End If
Next

 Also add ":1" to change the parameters

Parameter("R10S WHEEL:1", "WheelGage") = WheelGage

 

0 Likes
Message 3 of 3

swatkins3YWDA
Contributor
Contributor

I figured out to get what I wanted.  See code and screen shots below.  I placed the part into the assembly and using that as a template.  I normalized the browser node name and changed the linked parameters to reflect name change.  Removed the insert code for the part.

 

swatkins3YWDA_0-1651671450995.png

 

 

' Get current location of where you want the search area to be.
Dim ExportPath As String = (”Z:\ENGINEERING\CAD\MFG. DRAWINGS\ROCKENG\2 - 3D WHEEL MODELS\Test Folder Delete”)


' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
	' User clicked 'ok' on dialog box - capture the export path
	ExportPath = Dialog.SelectedPath & "\"
	
Else
	' User clicked 'cancel' on dialog box - exit
	Return
End If


Dim Path As String = ExportPath
MessageBox.Show(Path, "Directory path")

Dim InvDoc As AssemblyDocument = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document

Dim PartN As String = "FileName"

PartN = InputBox("Prompt", "Title", PartN)
For Each refDoc In refDocs
'    MessageBox.Show(refDoc.DisplayName)
    If refDoc.DisplayName.EndsWith("R10S WHEEL.ipt") = True Then
        NewFileName = PartN & " WHEEL.ipt"
		        refDoc.SaveAs(Path & NewFileName, False)
'    MessageBox.Show(refDoc.DisplayName)
    ElseIf refDoc.DisplayName.EndsWith("STUB AXLE.ipt")= True Then
        NewFileName = PartN & " AXLE.ipt"
        refDoc.SaveAs(Path & NewFileName, False)
    End If
Next


ThisDoc.Document.SaveAs(Path & PartN & ".iam", False)

iLogicVb.UpdateWhenDone = True
Parameter("R10S WHEEL", "WheelGage") = WheelGage
Parameter("R10S WHEEL", "WheelWidth") = WheelWidth
Parameter("R10S WHEEL", "WheelBore") = WheelBore
Parameter("R10S WHEEL", "WheelFlangeWidth") = WheelFlangeWidth
Parameter("R10S WHEEL", "WheelFlangeOffset") = WheelFlangeOffset
Parameter("R10S WHEEL", "WheelFlangeDia") = WheelFlangeDia
Parameter("R10S WHEEL", "HubCapOffset01") = HubCapOffset01
Parameter("R10S WHEEL", "HubCapDiaBore") = HubCapDiaBore
Parameter("R10S WHEEL", "RetainerRingWidth") = RetainerRingWidth
Parameter("R10S WHEEL", "RetianerRingOffset") = RetianerRingOffset
Parameter("R10S WHEEL", "RetainerRingDia") = RetainerRingDia
Parameter("R10S WHEEL", "AlemiteOffset01") = AlemiteOffset01
Parameter("R10S WHEEL", "AlemiteOffset02") = AlemiteOffset02
Parameter("R10S WHEEL", "AlemiteOffset03") = AlemiteOffset03
Parameter("R10S WHEEL", "AlemiteCBoreDia") = AlemiteCBoreDia
Parameter("R10S WHEEL", "AlemiteCBoreDepth") = AlemiteCBoreDepth
Parameter("R10S WHEEL", "AlemiteAngle") = AlemiteAngle
Parameter("R10S WHEEL", "WheelWidth") = WheelWidth
Parameter("R10S WHEEL", "BoreType") = BoreType



 

0 Likes