I have a rule which contains the Main and three Subs. I need to transfer variables between Subs. Normal VB doesn't seem to work. It doesn't error out. It just doesn't do it.
For example, I call a Sub from Main :
SwapPipe (oCompOcc, CurrentSize, NozzleSize)
The Sub beginning looks like :
Sub SwapPipe(compOcc as Inventor.ComponentOccurrence, CurrentSize As String, NozzleSize As String)
Then that Sub calls another Sub as:
InitialSize(compOcc, CurrentSize)
And that Sub beginning looks like:
Sub InitialSize(ScompOcc as Inventor.ComponentOccurrence, CurrentSize As String)
So, as an example, I would think that the variable CurrentSize would transfer between all these. But it isn't.
Any help is greatly appreciated.
That should work. What version of Inventor are you using?
You can try adding the line:
Option Explicit On
and maybe
Option Strict On
to the top of your rule. That might give you some compiler error messages about undeclared variables.
Inventor 2011 64bit.
OS = Windows 7.
I agree it should work but there are lots of things I've found in iLogic that you can do in Dot Net but not in iLogic.
But variable transfer is simple and I just can't understand why it won't do it.
Can you post the complete rule? That would help me to figure out what's going on.
I can but I think I may have found a way around it. I'm now trying to eliminate the subs, condense down the code, and just put it all in the main.
I do have another question. Are you the one that wrote the external rule for the Content Center replacer for iLogic?
Ok, good. I'm using it in my current program.
Basically I have a 150# nozzle which consists of a 150# flange and a pipe. Both are Content Center parts. I can swap the flange out without issue but I'm having difficulty with the pipe. How do I put that in the replacer command so that Content Center knows to ONLY replace the size and leave the schedule and length alone?
Then, secondary to that, how do I put that in the replacer command so that I can change any of those?
You're placing the pipes as Custom parts, right? That way you can specify any length you want. The content center replacement function code will only work on Standard parts. I'll see if if can be modified to work on Custom parts as well.
Note that you can replace Custom parts using the iLogic Component.Replace function. But to use that, you must first generate the exact part you need from the content center. The part must be available in your workspace or local library so that Component.Replace can find it.
So, if I'm understanding you, the part has to be placed first then the length parameter adjusted to what it needs to be....correct?
If you are placing the pipe as a Custom part, then the ContentCenterReplace code will not work. I am looking at changing it.
But as a workaround, you can use Component.Replace. To make that work, first place the pipe in one size and length that you require. Then (maybe in a temporary assembly in the same folder), place other sizes and lengths that you need. Now that you've placed them, the part files are available to be used by Component.Replace. I don't know if you will find this workaround to be useful. How many different sizes and lengths of a particular pipe component do you require in your design?
The pipe sizes can be ANY normal pipe size.
However, I found another workaround. You CAN use your Replacer to swap out the pipes by calling it in as the Content Center built in length. Then change the length parameter of the pipe to make it the correct length. After that you can use MakePath to rename it to the correct name with the new length.
In this case, it will take only four lines of code.
replacer.Replace(pPartName, PfamilyName, pNewName)
pNewPartName = pNewName & ":1"
Parameter(pNewPartName, "PL") = OldPlength
I only show three here because I haven't done the MakePath yet.
Hey Mike, here is another question. Our Content Center is custom and has a custom name. Today I put our custom Content Center on my machine and turned all others off. Now Replacer can't find things.
Is Replacer specific to out-of-the-box Content Center and not able to see our custom one?
I think I may have found the problem with the custom Content Center so disregard that last question. The problem was with my code........imagine that
Ok, I fixed my code. But, yesterday when it swapped out the pipes I could still go in and adjust the length using the "Parameter" command on the newly inserted pipe and make it the correct length. Today I can't. Yesterday it changed the diameter in the name but not the length. Today, with the custom Content Center, it isn't changing either one, even though the parameter name is still the same from yesterday to today.
I'm fairly baffled at the moment.
Any insight would be greatly appreciated.
Using a rule to change the length after replacing the part probably isn't equivalent to selecting a different part and custom length in the Content Center UI. I'm going to see if I can improve the rule function to accept a custom length or other parameter.
But I can also look at the method you're using. Can you post the rule you're using? I should be able to create a test assembky to try it out.
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
Can't find what you're looking for? Ask the community or share your knowledge.