Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

detect Content Center Part

6 REPLIES 6
Reply
Message 1 of 7
bernd.schreck
1319 Views, 6 Replies

detect Content Center Part

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

 

6 REPLIES 6
Message 2 of 7
JelteDeJong
in reply to: bernd.schreck

you can have a go like this:

    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.kPartDocumentObject) Then
                Dim def As PartComponentDefinition = DocumentObject.ComponentDefinition
                ' This will not detect Custom CC parts.
                ' If you want to detect those you also need to check the iProperty sets
                ' see:
                ' https://adndevblog.typepad.com/manufacturing/2018/01/inventor-api-detect-a-content-center-part-is-inserted-as-standard-or-custom.html
                If (def.IsContentMember) Then
                    Return 'Stop doing any thing
                End If
            End If
            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

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 7
bernd.schreck
in reply to: JelteDeJong

Thanks for the reply @JelteDeJong .

Because the preview in Visual Studio does not show the ComponentDefinition object, I wasn´t aware I can access this, so thanks for this.

Sadly your solution does not work because (for whatever reason), the property IsContentMember is false for unsafed Content Center parts. After save it is true and even on the OnNewOccurence Event (trigged after this event), it is set to true when accessing the document object by Context. 

Also looking into the PropertySets does not help.

Any ideas to solve this?

Message 4 of 7
JelteDeJong
in reply to: bernd.schreck

In your opening post, you have a rule that searches for 1 specific iProperty. With the following rule, I found more iProperties that hint at CC parts.

JelteDeJong_0-1640880693559.png

Maybe you are lucky and are those present other wise i would not know how to detect them.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 7

For a CC part there is a additional propertyset available like content center. If that is available you have a cc part

 

Dim a As Inventor.PartDocument = ThisDoc.Document
For Each p As Inventor.PropertySet In a.PropertySets
	
	Logger.Info(" {0}", p.Name)

	Next

 

  • Inventor Summary Information
  • Inventor Document Summary Information
  • Design Tracking Properties
  • Inventor User Defined Properties
  • Content Library Component Properties
  • ContentCenter

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 6 of 7

Hi @bradeneuropeArthur,

 

thanks for your reply. Sadly this is again only valid for already saved CC parts. New ones does only have the "normal" ones

  • Inventor Summary Information
  • Inventor Document Summary Information
  • Design Tracking Properties
  • Inventor User Defined Properties
Message 7 of 7

Hi @bernd.schreck,

 

Maybe this code can help you?

 

ThisApplication.ActiveDocument.PropertySets.PropertySetExists("ContentCenter")

  • True when it is a content center part
  • False when it is not a content center part

ThisApplication.ActiveDocument.PropertySets.Item("ContentCenter").Item("IsCustomPart").Value

  • = 1 When it is a custom content center part
  • = 0 When it is not a custom content center part

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report