AddReference "NozzleAdjuster1"
Sub Main
AddVbFile ("ContentCenterReplace.iLogicVb")
Dim app As Inventor.Application = ThisApplication
Dim oDoc As Inventor.AssemblyDocument = app.ActiveDocument
Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc In oCompDef.Occurrences
Dim compDef as Inventor.ComponentDefinition = oCompOcc.Definition
Dim compDoc as Inventor.Document = compDef.Document
Dim PartName As String = System.IO.Path.GetFileNameWithoutExtension(compDoc.FullFileName)
IsPipe = Left(PartName, 4)
If IsPipe = "Pipe" Then
CurrentSize = Mid(PartName, 6, 2)
SizeChk = Mid(CurrentSize, 2, 1)
pNewNameLength = PartName.Length
pNewNameRemainL = pNewNameLength - 7
pNewNameRemain = Mid(PartName, 8, pNewNameRemainL)
pPartName = PartName & ":1"
OldPlength = Parameter(pPartName, "PL")
PipeWall = Parameter(pPartName, "t")
PipeFlangeOffset = Parameter(oDoc, "d0")
CurrentNozzleProjection = Parameter(oDoc, "d4")
If SizeChk = "" Or SizeChk = " " Or SizeChk = nil Then
CurrentSize = Mid(PartName, 6, 1)
pNewNameRemainL = pNewNameLength - 6
pNewNameRemain = Mid(PartName, 7, pNewNameRemainL)
pNewName = IsPipe & CurrentSize & pNewNameRemain
End If
End If
Next
Dim dlg as New ClassLibrary1.Dialog1
dlg.NozzleSize = NozzleSize
dlg.CurrentSize = CurrentSize
dlg.PipeWall = PipeWall
dlg.PipeFlangeOffset = PipeFlangeOffset
dlg.CurrentNozzleProjection = CurrentNozzleProjection
dlg.NewNozzleProjection = NewNozzleProjection
i = dlg.ShowDialog()
For Each oCompOcc In oCompDef.Occurrences
Dim compDef as Inventor.ComponentDefinition = oCompOcc.Definition
Dim compDoc as Inventor.Document = compDef.Document
Dim PartName As String = System.IO.Path.GetFileNameWithoutExtension(compDoc.FullFileName)
Dim replacer As New ContentCenterReplace(ThisDoc.Document, ThisApplication, "en-US")
Dim PfamilyName As String = "Tube & Pipe:Conduits:Pipes:ASTM A 53/A 53M Pipe"
pCCFam = "ASTM A 53/A 53M "
Dim FfamilyName As String = "Tube & Pipe:Fittings:Flanges:ASME B16.5 Flange Slip-On Welding - Class 150"
If IsFlange <> "ASME B16.5 Flange Slip-On Welding - Class 150" Then
IsPipe = Left(PartName, 4)
End If
If IsPipe <> "Pipe" Then
IsFlange = Left(PartName, 45)
End If
If(i = vbOK)Then
NozzleSize = dlg.NozzleSize
PipeFlangeOffset = dlg.PipeFlangeOffset
NewNozzleProjection = dlg.NewNozzleProjection
If NozzleSize <> "" And NozzleSize <> " " And NozzleSize <> nil Then
If IsPipe = "Pipe" Then
pNewName = IsPipe & " " & NozzleSize & " - XS - .001"
replacer.Replace(pPartName, PfamilyName, pNewName)
pNewPipeName = pNewName & ":1"
ThisDoc.Document.ComponentDefinition.Occurrences.Item(1).Name = pNewPipeName
Parameter(pNewPipeName, "PL") = OldPlength
End If
If IsFlange = "ASME B16.5 Flange Slip-On Welding - Class 150" Then
fPartName = PartName & ":1"
NewFlange = IsFlange & " " & NozzleSize
replacer.Replace(fPartName, FfamilyName, NewFlange)
End If
End If
If PipeFlangeOffset <> "" And PipeFlangeOffset <> " " And PipeFlangeOffset <> nil Then
Parameter(oDoc, "d0") = PipeFlangeOffset
End If
If NewNozzleProjection <> "" And NewNozzleProjection <> " " And NewNozzleProjection <> nil Then
Parameter(oDoc, "d4") = NewNozzleProjection
End If
End If
Next
UpdateNozzle
End Sub
Sub UpdateNozzle
InventorVb.DocumentUpdate
InventorVb.SetViewCamera(ViewCameraOption.FitExtents, New Double() {-121.30039731877672, 145.50927339213723, 145.44114957469338}, New Double() {24.208876073360443, 0, -0.068123817443847656}, New Double() {0.40824829046386318, 0.81649658092772592, -0.40824829046386313}, New Double() {76.824887490943567, 87.260303212016993})
IsFlange = nil
IsPipe = nil
PartName = nil
CurrentNozzleProjection = nil
NewNozzleProjection = nil
PipeFlangeOffset = nil
End Sub
I figured out if I use
ThisDoc.Document.ComponentDefinition.Occurrences.Item(1).Name = pNewPipeName
I can rename the pipe and continue on.
You will need a pipe and a 150# raised face slip on flange parts put together in an assembly.
You will also need to create a dialog in Dot Net and build as a DLL. The Dot Net code is as follows :
Public Class Dialog1
Public NozzleSize As String
Public CurrentSize As String
Public PipeFlangeOffset As String
Public PipeWall As String
Public CurrentNozzleProjection As String
Public NewNozzleProjection As String
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
NozzleSize = TextBox1.Text
PipeFlangeOffset = TextBox2.Text
NewNozzleProjection = TextBox3.Text
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub Dialog1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Label2.Text = "Current Nozzle Size = " & CurrentSize
Label5.Text = "Current Pipe/Flange Offset = " & PipeFlangeOffset
Label6.Text = "Current Pipe Wall Thickness = " & PipeWall
Label8.Text = "Current Nozzle Projection = " & CurrentNozzleProjection
TextBox1.Focus()
TextBox1.SelectAll()
End Sub
Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = "Current Nozzle Size = " & CurrentSize
Label5.Text = "Current Pipe/Flange Offset = " & PipeFlangeOffset
Label6.Text = "Current Pipe Wall Thickness = " & PipeWall
Label8.Text = "Current Nozzle Projection = " & CurrentNozzleProjection
TextBox1.Focus()
TextBox1.SelectAll()
End Sub
End Class