Sorry about the error, I should have tested the customized code before posting it. Line 17 in that last code was designed to handle the situation where the Document being passed to the routine was a DrawingDocument. That one line could have been completely deleted, if you never intend to use it on a drawing. I sometimes use the parameters in drawings for various reasons, and sometimes one or more of them are just copied from 'the model'. The DrawingDocument object does not have a ComponentDefinition, and so its Parameters collection is located directly at DrawingDocument.Parameters, instead of under a ComponentDefinition.
However, when I condensed that code into fewer lines (with the ":" characters) and further customized the routines within the forum code window before posting, I apparently deleted the Exception portions, forgetting about an important detail of the Try...Catch statement with multiple Catch sections (which I don't use very often), which messed up their functionality a bit. When using more than one Catch section in a Try...Catch statement, the other Catch sections are for reacting differently to different reasons (different types of an Exception) that the Try portion may have failed. So, when using multiple Catch sections, each of them must be designated for dealing with different specified type of Exception, so that the Catch section will only be ran when that specific type of Exception caused the failure. This is generally not a problem when only using one Catch section. So, I fixed that routine back to the way it is supposed to be, and left the drawing handling Catch in there...then tested it this time. It is working as designed again now. I had not used that specific routine in a long time, because most of my 'working' codes that deal with exposing parameters have similar, but simpler functionality integrated into larger, more complex routines, and generally do not handle the possibility of dealing with a drawing. Apparently the snippet itself needed updating too. Sometimes I save out a custom snippet of code too soon, then further develop it later, and no not remember to update the saved snippet.
I know you already have a solution, but I decided to post the corrected version of the routine I posted above which uses the extra input variable. In this case, I moved the conditional statements of the 'custom' routine into the 'Main' routine, to leave the ExportParam Sub more dynamic. However, it still does not address the possibility of multiple ModelStates being involved, which would add another level of complexity.
Sub Main
Dim oDoc As Document = ThisDoc.Document
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheet metal
ExportParam(oDoc, "Thickness", True)
Else
ExportParam(oDoc, "Thickness", False)
End If
Dim oAllRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
If oAllRefDocs.Count = 0 Then Return
For Each oRefDoc As Document In oAllRefDocs
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheet metal
ExportParam(oRefDoc, "Thickness", True)
Else
ExportParam(oDoc, "Thickness", False)
End If
Next
If oDoc.RequiresUpdate Then oDoc.Update2(True)
If oDoc.Dirty Then oDoc.Save2(True)
End Sub
Sub ExportParam(oDoc As Document, sParamName As String, bExport As Boolean)
If oDoc Is Nothing OrElse oDoc.IsModifiable = False Then Return
Dim oParam As Inventor.Parameter = Nothing
Try : oParam = oDoc.ComponentDefinition.Parameters.Item(sParamName) 'Part or Assembly
Catch ae As ArgumentException
Return 'it was a model document, but the parameter was not found, so exit routine
Catch mme As MissingMemberException
'it was a DrawingDocument, which does not have a ComponentDefintion
Try 'try to find the parameter in the drawing
oParam = oDoc.Parameters.Item(sParamName)
Catch 'do not specify an Exception type here
Return 'the parameter was not found in the drawing either, so exit routine
End Try
End Try
If oParam Is Nothing Then Return 'could not be found, so exit routine
If oParam.ExposedAsProperty <> bExport Then oParam.ExposedAsProperty = bExport
End Sub
Wesley Crihfield

(Not an Autodesk Employee)