Ok I solved it a little different then i intended but I now use the following code when saving the part
Sub Main
Dim oInvApp As Application
oInvApp = ThisApplication
' Get the active document object
Dim oDoc As Document
oDoc = oInvApp.ActiveDocument
If oDoc.DocumentType() = DocumentTypeEnum.kAssemblyDocumentObject Then
iProperties.Value("Custom","KFactor")= "Nvt"
Exit Sub
End If
'Check if part is purchased or not
Workpath= "I:\Engineering\"
If Left(ThisDoc.Path,15)=WorkPath Then
Exit Sub
End If
'Check for sheetmetal part
Dim oType As String
oType = oDoc.DocumentSubType.DocumentSubTypeID
If oType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
iProperties.Value("Custom", "X_Maat") = SheetMetal.FlatExtentsLength
iProperties.Value("Custom", "Y_Maat") = SheetMetal.FlatExtentsWidth
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit
iProperties.Value("Custom", "Part_Dimension")="Plaat " & Round(iProperties.Value("Custom", "X_Maat"),1) & "x" & Round(iProperties.Value("Custom", "Y_Maat"),1) & "x" & Parameter("Thickness")
iProperties.Value("Custom","KFactor")=SheetMetal.ActiveKFactor
Else
iProperties.Value("Custom","KFactor")= "Nvt"
End If
iLogicVb.UpdateWhenDone = True
End Sub
Which does what i need when saving the part. When I'm saving the drawing i have another rule which runs before saving the drawing.
Sub Main()
If iProperties.Value("Project", "Part Number") = "" Then
Exit Sub
Else
curDoc = ThisDrawing.Sheet("sheet:1").View("VIEW1").ModelDocument
If curDoc.DocumentType = kPartDocumentObject And curDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
oDoc = ThisApplication.Documents.Open(curDoc.FullFileName, True)
oCompDef = oDoc.ComponentDefinition
iLogicVb.RunExternalRule("Drawingnumber")
ThisApplication.ActiveDocument.Close
Else
Return
End If
End If
End Sub
This way the drawing always has the correct parameters. It takes a little more time to save, but thats ok by me.
Thanks for the help!