- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I see. Tough situation. Here is a more robust and complete version of my earlier code, with several checks in there to help eliminate some possible errors that may be preventing it from working.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
For Each oUParam As UserParameter In oPDoc.ComponentDefinition.Parameters.UserParameters
Dim oExists As Boolean
If oUParam.Name = "SEAL_CUSTOM_EXTENTS" Then
oExists = True
If oUParam.Value = "REQUIRED" Then
oPDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "N/A"
oPDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = "RTSM"
Try
'Check if it is a 'Regular Part', if not change it to one.
If oPDoc.SubType <> "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
oPDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
End If
Catch
MsgBox("The attempt to change the SubType of " & oPDoc.FullFileName & vbCrLf & _
"to a 'Regular Part' failed.",,"")
End Try
Else 'if that parameter didn't have that value...
oPDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = "N/A"
Try
'Check if it is a 'Sheet Metal Part', if not change it to one.
If oPDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
oPDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
End If
Catch
MsgBox("The attempt to change the SubType of " & oPDoc.FullFileName & vbCrLf & _
"to a 'Sheet Metal Part' failed.",,"")
End Try
End If
End If
If oExists = False Then
MsgBox("The User Parameter 'SEAL_CUSTOM_EXTENTS' was not found within" & vbCrLf & _
oPDoc.FullFileName & vbCrLf & _
"so this part was not processed.", , "Parameter Not Found")
End If
Next
oPDoc.Save
oPDoc.Close(True)
End If
NextAlso, just in case you weren't aware, there is another option for checking the document's SubType, that is actually readable/understandable. There are iProperties named "Document SubType" and "Document SubType Name" within the "Design Tracking Properties" set. I have found these to be very reliable, and found that they instantly update when changing a part back and forth between regular part and sheet metal part in my testing. In English, if a part is a regular part, the value of "Document SubType Name" is "Modeling", and if is a sheet metal part, the value is "Sheet Metal". Although, I am not sure if those values may change to different words for different language Inventor installations. I have also created an 'Idea' within the Inventor Idea Station to create a 'DocumentSubTypeEnum' to better handle these types of inquiries in a readable, stable way.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE'
.
Wesley Crihfield
(Not an Autodesk Employee)