I'm running an external rule within both parts and assemblies. It's been working just fine for days now. But all of a sudden today it will no longer run within parts and it gives me an error saying it can only be run within assemblies. I've put a message box as the very first line of code and it wont even open the message. So I believe the issues not with the code itself. Please see image below.
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @ndillner343SKL. Can you post the code, so we can review it, if it does not contain any proprietary data? The error makes it sound like you are using the iLogic shortcut snippet that starts with the keyword "Component", but that really is just for working with an assembly, not a part, so that may be where the problem lies.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @WCrihfield,
I can't share the code entirely. But here is the first chunk. The External rules its calling are simply "Select Case" that are using the parameter value to determine the returned variable.
@WCrihfield, I found the issue. You were right it was because of a "Component." callout. But the code was only suppose to run if it was an assembly. Which is why I didn't think it would be an issue. Thanks for the response!
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
If oComName = oComponentName Then Try If GoExcel.CellValue(param.Name) = "NA" Then Component.IsActive(oComponentName) = False End If Catch Component.IsActive(oComponentName) = True End Try End If
I don't really see anything that I suspect might cause an error like that in what you posted. I see that you are using 'ActiveDocument' to access parameters, but are then using 'ActiveEditDocument' for defining your 'oDef' variable. You are likely aware of this, but those could be pointing to completely different documents in some situations. If an assembly was 'active' when you started the code, but you were also currently in 'edit mode' of a component within that assembly, the 'ActiveDocument' would remain the main assembly, but the 'ActiveEditDocument' would be the document the component you were editing represents. But if you already had that in mind, or planned it that way, there is probably no problem there.
Another tip is that you can check if a SharedVariable exists, before trying to access its value, which can help avoid some potential errors.
I am now curious about the other two rules, and how they are identifying the document that they are to work on. But, if there was a problem with one of them, I would assume that it would have the name of one of them in the error message, instead of this rule's name. At this point, I'm still not sure what might be causing an odd sounding error like that.
Oops... OK, I just read your later posts after posting this one. 😂
Wesley Crihfield
(Not an Autodesk Employee)
If you need to replace that little bit of code, there are API ways of doing the same thing too, but it would obviously take more code to do the API way. IsActive = Not Suppressed, and the ComponentOccurrence object has a ReadOnly property called Suppressed, for checking its current status, and two methods (Suppress & Unsuppress) for handling changes to that status.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.