I'm using the rule below at the assembly level to go through all parts in the assembly and change the schedule to whatever is set at the assembly level. I used a Try/Catch statement since not all parts will have the "Sch" parameter - only piping and fittings will have that parameter. Maybe I am not using this statement correctly though? I have message boxes for debugging purposes on both the Try and Catch. When I run the rule, I get the Catch message box for all parts as if it couldn't find that Parameter, but then the parts update as expected anyway! Note, the "Sch" parameter at both the assembly and part levels are multivalue text. Could that have something to do with it?
See code below and I've also attached a sample part, so feel free to try it out for yourself. As always, any help is much appreciated!
' Set a reference to the assembly component definintion Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Iterate through all occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences Try Parameter(oOcc.Name,"Sch") = PipeSch Parameter(oOcc.Name,"PipeSch") = PipeSch ' For debugging: MessageBox.Show(oOcc.Name & " was updated." & vbLf & "Schedule set to: " & iProperties.Value(oOcc.Name,"Project","Description"), "Debug Message - Pipe_Sch") Catch MsgBox(oOcc.Name & vbLf & "Parameter 'Sch' not found. Proceeding to next part...") End Try Next
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
See if switching they syntax of your params helps;
oOcc.Definition.Parameters.Item("Sch").Value()
Or
oOcc.Definition.Parameters.Item("Sch").Expression
Also,
The less sloppy way of accessing iProperties would be:
oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Description").Value
Thanks for the tips, Mech. I tried both of your parameter access methods. The .Expression modifier doesn't seem to work - I don't get any error messages, but the models don't update. The .Value() modifier does the exact same thing as was happening before where I get the Catch debug message, but then everything still updates as expected anyway.
Hmm.. This seemed like a fairly straight-forward bit of code. I guess it's never as simple as you first think it is!
P.S. that makes sense about the iProperties - To access the document before telling it to look for a parameter. I'm guessing that's the idea anyway. Although it is a little more lengthy.
Hey there,
Looking at your sample part, you're missing the PipeSch parameter.
Your code ran fine in my testing.
Yes, you are correct, rsmabery. The elbow doesn't contain the parameter "PipeSch", but for my flange parts, I used "PipeSch" rather than "Sch". So I just wrote my code to look for both those parameter names. I may go back and update my flanges later though so all are sharing the same parameter names.
So the code is working fine for you? That is weird. I wonder why mine is acting funny. Maybe I just need to restart the app? I'll give that a try.
Try separating the two parameter lines into two separate Try/Catch Blocks. I didn't realize you didn't have the same parameter in all parts.
APatterson_1 wrote:
I'm using the rule below at the assembly level to go through all parts in the assembly and change the schedule to whatever is set at the assembly level. I used a Try/Catch statement since not all parts will have the "Sch" parameter - only piping and fittings will have that parameter. Maybe I am not using this statement correctly though? I have message boxes for debugging purposes on both the Try and Catch. When I run the rule, I get the Catch message box for all parts as if it couldn't find that Parameter, but then the parts update as expected anyway! Note, the "Sch" parameter at both the assembly and part levels are multivalue text. Could that have something to do with it?
See code below and I've also attached a sample part, so feel free to try it out for yourself. As always, any help is much appreciated!
' Set a reference to the assembly component definintion Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Iterate through all occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences Try Parameter(oOcc.Name,"Sch") = PipeSch Parameter(oOcc.Name,"PipeSch") = PipeSch ' For debugging: MessageBox.Show(oOcc.Name & " was updated." & vbLf & "Schedule set to: " & iProperties.Value(oOcc.Name,"Project","Description"), "Debug Message - Pipe_Sch") Catch MsgBox(oOcc.Name & vbLf & "Parameter 'Sch' not found. Proceeding to next part...") End Try Next
Also, looking through your code again, I think the issue is that when you use a try loop, it still PERFORMS all of the actions up until the point where it throws the error in the loop.
ie; if it has sch but no pipesch it will still change the sch parameter.
I would try a simpler check before you run the changing; ie;
oCheck = oParam.Item("Sch").Name 'will throw an error if it does not exist. (This is referring to the syntax i talked about in my other post)
Also, double check your message box syntax as it seems your are using 2 different versions... not sure if that will actually cause any issues, but it doesn't hurt to keep it consistent.
Aaaahhhh.... I just had a face-palm moment. That makes perfect sense now that if even though the "Sch" parameter is there, it will still give me the Catch error handling if the "PipeSch" is not there. Yep, now it works fine! The importance of consistancy is becoming all to real lol. I will definitely go back and update my other parts' parameter names.
This is what happens when I take vacation days and immediately jump into coding when I return....
Thanks for the help, guys!
Can't find what you're looking for? Ask the community or share your knowledge.