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 :
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(icompDo
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
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
Dim replacer As New ContentCenterReplace(ThisDoc.Document, ThisApplication, "en-US")
Dim PfamilyName As String = "Tube & Pipe:Conduitsipes: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)
If IsPipe <> "Pipe" Then
IsFlange = Left(PartName, 45)
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"
Parameter(pNewReName, "PL") = OldPlength
If IsFlange = "ASME B16.5 Flange Slip-On Welding - Class 150" Then
fPartName = PartName & ":1"
NewFlange = IsFlange & " " & NozzleSize
replacer.Replace(fPartName, FfamilyName, NewFlange)
If PipeFlangeOffset <> "" And PipeFlangeOffset <> " " And PipeFlangeOffset <> nil Then
Parameter(oDoc, "d0") = PipeFlangeOffset
If NewNozzleProjection <> "" And NewNozzleProjection <> " " And NewNozzleProjection <> nil Then
Parameter(oDoc, "d4") = NewNozzleProjection
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).
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
Dim CurrentSize As String = "24.375"
MessageBox.Show("Final Value " & CurrentSize) 'Displays: Final Value 48.625
Sub FirstPass(ByRef CurrentSize As String)
Sub SecondPass(ByRef CurrentSize As String)
MessageBox.show("Deepest Nest " & CurrentSize) 'Displays: Deepest Nest 24.375
CurrentSize = "48.625"
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.
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!