detect Content Center Part
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have written an add-in which loads a form for new parts and assemblies (to set naming, iProperties etc). The program is trigged by the app-event .OnNewDocument.
The problem I currently have is that I want to avoid loading my form at Content Center parts. For past loaded parts I could detect it easily by searching "Content Center" inside the FullFileName, but this is not valid for newly generated content center parts.
I´m able to detect the Content Center part by the assembly-event .OnNewOccurence (source: https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/content-center-file/m-p/9066906#M101877), but that is sadly trigged AFTER the OnNewDocument event.
Is there a way to detect the Content Center part during or before event OnNewDocument ?
Below excerpt of code:
'module
Dim oClass As TestEvenClass
Sub startEvent()
oClass = New TestEvenClass
oClass.ini
Do While True
DoEvents
Loop
End Sub
'event class
Public WithEvents E_AssEvents As AssemblyEvents
Public WithEvents E_AppEvents As AssemblyEvents
Public Sub ini()
E_AssEvents = ThisApplication.AssemblyEvents
E_AppEvents = ThisApplication.ApplicationEvents
End Sub
Private Sub E_AssEvents_OnNewOccurence(DocumentObject As _AssemblyDocument, Occurrence As ComponentOccurrence, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles c.OnNewOccurrence
If BeforeOrAfter = EventTimingEnum.kAfter Then
For Index = 1 To Context.Count
Dim oContextName As String
oContextName = Context.Name(Index)
If oContextName = "ComponentDefinition" Then
Dim oDef As ComponentDefinition
oDef = Context.Value(Context.Name(Index))
If TypeOf oDef Is PartComponentDefinition Then
Dim oPartDef As PartComponentDefinition
oPartDef = oDef
If oPartDef.IsContentMember Then
'this is a part from content center in standard way
MsgBox("This is a part from Content Center ")
Else
' check if it is common part of custom part of Content Center
Dim isCustomPart As Boolean
isCustomPart = False
Dim oPropertySets As PropertySets
oPropertySets = oPartDef.Document.PropertySets
Dim oEachProSet As PropertySet
Dim oEachP As [Property]
For i = 1 To oPropertySets.Count
' use the 6th propertyset of [ContentCenter].
' If it is a Custom part, there is only one property within this property set.
' The name is “IsCustomPart”. While if it is a Standard CC part, there are some properties
' to indicate the information of the CC such as family, member etc..
'the internal name of this propertyset is not same across different content center part
'so, it looks we have to use display name, which assumes no user defined property set with the same name.
oEachProSet = oPropertySets(i)
'If oEachProSet.InternalName = "{5E21919D-4082-492A-8A30-039424CD07B5}" Then
If oEachProSet.DisplayName = "ContentCenter" Then
For k = 1 To oEachProSet.Count
oEachP = oEachProSet(k)
If oEachP.Name = "IsCustomPart" Then
Dim oValue As String
oValue = oEachP.Value
If oValue = "1" Then
isCustomPart = True
Exit For
End If
End If
Next
End If
If isCustomPart Then
Exit For
End If
Next
If isCustomPart Then
MsgBox("This is a custom part from content center")
Else
MsgBox("This is a common part")
End If
End If
End If
End If
Next
End If
End Sub
Private Sub E_AppEvents_OnNewDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles E_AppEvents.OnNewDocument
If DocumentObject IsNot Nothing Then
If DocumentObject.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or DocumentObject.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
If InStr(DocumentObject.FullFileName, "Content Center") = 0 Then
'Init and call of program
'olib = New Init(oInvApp)
'olib.Main()
End If
End If
End If
End Sub