Message 1 of 4
Editing iProperties from Drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Curious if anyone can help debug this script I wrote which is intended to be ran from a part or drawing where the script determines if it is being ran in a part or drawing and if in a part it deletes certain parameters from the User Parameters list, the adds sheet metal values to the custom iProperties list. It runs correctly on parts however when run from the drawing it deletes the parameters but doesn't add the iProperties to the part
I'd like to keep the single function although I think if it was written to have 2 functions then it would probably work
Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim smLen, smWid As String
Dim refParams As UserParameter
If oDoc.DocumentType = kassemblydocumentobject Then
MsgBox("Only run on parts or drawings")
Exit Sub
End If
If oDoc.DocumentType = kPartDocumentObject Then
Dim param As Parameter
Try :
param = oDoc.ComponentDefinition.Parameters.Item("Length")
param.Delete
Catch :
End Try
Try :
param = oDoc.ComponentDefinition.Parameters.Item("Width")
param.Delete
Catch :
End Try
Call AddParams
End If
If oDoc.DocumentType = kdrawingdocumentobject Then
Dim oRef As Document
Dim refDocs As Integer
For Each oRef In oDoc.ReferencedDocuments
refDocs = oDoc.ReferencedDocuments.Count
Try:
If refDocs < 2 Then
If oRef.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value <> "Sheet Metal" Then
MsgBox("Part must be sheet metal to apply sheet metal functions")
Exit Sub
Else
Parameter.Quiet = True
Try :
Dim lenParam As UserParameter = oRef.ComponentDefinition.Parameters.UserParameters.item("Length")
Dim widParam As UserParameter = oRef.ComponentDefinition.Parameters.UserParameters.item("Width")
widParam.Delete
lenParam.Delete
oRef.Activate
Call AddParams
oDoc.Activate
Catch :
oRef.Activate
Call AddParams
oDoc.Activate
'MsgBox("error deleting parameters?")
End Try
End If
End If
Catch :
oRef.Activate
Call AddParams
oDoc.Activate
End Try
Next
oDoc.Update2
End If
End Sub
Function AddParams
Dim oPart As Document = ThisApplication.ActiveDocument
'MsgBox(oPart.FullFileName) ' Part is active part?!
iProperties.Value("Custom", "Length") = "=<Sheet Metal Length>"
iProperties.Value("Custom", "Width") = "=<Sheet Metal Width>"
iProperties.Value("Custom", "Visual Description") = "=<Sheet Metal Rule>"
End Function