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.
Mike,
I found a couple of errors in my code but have now fixed it. However, the rule is unstable. If I start Inventor fresh, open the assembly, and run the rule, it will work most times. Occasionally it won't though, which is really weird. Also, once it has been ran you can't run it again until you close the assembly, reopen it, and run the rule. It is something inside the pipe (If IsPipe....) and/or flange (If IsFlange....) swap "If" that is causing it but I can't figure out what. I've tried resetting all variables to nil once the rule has finished but that doesn't work either. It acts like it is hung up somehow inside the "If" statement because it immediately tries to set the "Parameter(pNewRename, "PL") = OldpLength" and won't even open the dialog before erroring. Below is a picture of what the dialog currently looks like and the updated code is below that.
Any help is appreciated.
Rule Code :
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 icompDef as Inventor.ComponentDefinition = oCompOcc.Definition
Dim icompDoc as Inventor.Document = icompDef.Document
Dim iPartName As String = System.IO.Path.GetFileNameWithoutExtension(icompDoc.FullFileName)
iIsPipe = Left(iPartName, 4)
If iIsPipe = "Pipe" Then
CurrentSize = Mid(iPartName, 6, 2)
SizeChk = Mid(CurrentSize, 2, 1)
pNewNameLength = iPartName.Length
pNewNameRemainL = pNewNameLength - 7
pNewNameRemain = Mid(iPartName, 8, pNewNameRemainL)
pPartName = iPartName & ":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(iPartName, 6, 1)
pNewNameRemainL = pNewNameLength - 6
pNewNameRemain = Mid(iPartName, 7, pNewNameRemainL)
pNewName = iIsPipe & 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"
pNewReName = IsPipe & " " & NozzleSize & " - XS - " & OldPlength & ":1"
ThisDoc.Document.ComponentDefinition.Occurrences.Item(1).Name = pNewReName
Parameter(pNewReName, "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})
End Sub
Does it always give the same error message? What is the error message that it gives?
Did you originally add the pipe as a Custom or Standard component? See the attached picture.
I thought I could create a test assembly, but it would be better if you could post your assembly. Also, can you zip up the full VB project for the dialog code and send that? Or just the .dll file would be enough.
Yes, it's the same error. See below.
So, what is happening is that the pipe that's shown in the error is the original pipe (from the first run) before I adjust the length and rename it. But, for some reason it tries to go set that parameter again using the wrong name and even before it opens th dialog.
And, the pipe was inserted as "Custom" originally.
Would it be better to just send it to you by email? What's your email?
I think I have to change the content center replacer rule to handle Custom components. That might be required to get your rule working.
It looks like it is important to you to have the component name reflect the part type and size? That should be possible, but it makes the rule more complicated. Would you consider using a component occurrence name that remains constant, such as Pipe:1 or Flange:1? I know this is not very user-friendly, but it does make the rule simpler.
My email is mike dot deck at <the company name at the top of this page> dot com
No, it isn't possible for us to use constant naming. We must have the naming as I have it.
I agree that it would make the rule simpler but we can't at this point.
The files and a more detailed explanation of what I'm trying to achieve, will be on their way shortly.
Regarding Passing Variables.
Are you saying the variable CurrentSize is not being passed all the way down to the deepest sub or not being passed back up to the top?
Arguments in Sub Routines and Functions in VB are passed in one of two ways. ByRef (By Reference) or ByVal (By Value).
In effect
If Passed ByVal they are one way only. The value is passed into the Sub but not back out.
If Passed ByRef they are passed two way into and back out of the Sub.
In iLogic it appears that if you do not specify ByRef or ByVal then ByVal is the Default.
(This is the opposite from how VBA treats Sub arguments.)
The following test works fine for me
Format:HTML Format
Version:1.0
StartHTML: 165
EndHTML: 5252
StartFragment: 314
EndFragment: 5220
StartSelection: 314
EndSelection: 314
Sub Main
Dim CurrentSize As String = "24.375"
FirstPass(CurrentSize)
MessageBox.Show("Final Value " & CurrentSize) 'Displays: Final Value 48.625
End Sub
Sub FirstPass(ByRef CurrentSize As String)
SecondPass(CurrentSize)
End Sub
Sub SecondPass(ByRef CurrentSize As String)
MessageBox.show("Deepest Nest " & CurrentSize) 'Displays: Deepest Nest 24.375
CurrentSize = "48.625"
End Sub
That sounds reasonable. However, I have since done away with the subs and just combined all into the main. Is working fine now.
For anybody that might be following this thread, below is an image of the latest version of the dialog. It's getting really complicated but if I can get everything to work it will be awesome. We are going to convert all of our thousands of 2D AutoCad standard drawings to Inventor 3D models. With this one interface I figure we can eliminate somewhere around 5-6000 2D drawings with one dialog, one internal rule, one external rule (Mike's Content Center Replacer), one assembly, three part files, and one drawing file. That's pretty awesome!! See latest dialog below :
I do have a question though. In some cases, with smaller nozzles, the repad is not required and it needs to be suppressed. The code snippet in iLogic rules for "IsActive" (true or false) doesn't seem to want to work. I can turn the repad visibility on and off but it needs to be suppressed so that it doesn't show up in the drawing and bill of material.
Any ideas?
Can't find what you're looking for? Ask the community or share your knowledge.