recognizing occurrence as a Content Center

recognizing occurrence as a Content Center

shastu
Advisor Advisor
2,199 Views
13 Replies
Message 1 of 14

recognizing occurrence as a Content Center

shastu
Advisor
Advisor

If I have an occurrence selected how can I tell if it is a normal part or a content center part?

 

For example: Make sure you select a part before running this.  I stripped out the logic to ensure this happens for clarity.

 

Sub IsContent()
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    Dim NewFile As String
    
    Dim oSS As SelectSet
    Set oSS = oDoc.SelectSet
   
    Select Case True
        Case oSS.Count = 1
            If oSS.Item(1).Type = ObjectTypeEnum.kComponentOccurrenceObject Then
                'If oSS.Item(1) is a content center part then exit sub
                OccurrenceName = oSS.Item(1).Name
            End If
    End Select

End Sub

 

The commented line is where I need the logic.

0 Likes
Accepted solutions (1)
2,200 Views
13 Replies
Replies (13)
Message 2 of 14

MechMachineMan
Advisor
Advisor

Again, API help.

 

Looking at component definition object, you see there is a property "IsContentMember".

 

At the same time, looking just a the document object, there is a property "IsModifiable"

 

If you don't like either of these methods, you could always make your own function to check the file name against the paths within the project file, or paths in a predefined list


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 14

shastu
Advisor
Advisor

I had looked at the API help before I posted.  I found the IsContentMember but I don't know how to use it.  I tried the following:

 

If oSS.Item(1).ComponentDefinitiion.IsContentMember = False Then

If oSS.ComponentDefinitiion.IsContentMember = False Then

If oDoc.ComponentDefinitiion.IsContentMember = False Then

 

None of them worked.

0 Likes
Message 4 of 14

MechMachineMan
Advisor
Advisor

"None of them worked" as in it threw an error because ComponentDefinition is spelled wrong?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 14

shastu
Advisor
Advisor

Yes, I had caught that after I posted it, but even with it spelled correctly I get a "Run-time error '438':  Object doesn't support this property or method."

0 Likes
Message 6 of 14

Anonymous
Not applicable

First of all, without you indicating what oSS is for sure, it's hard to offer much useful help but I'll try anyway.

 

"If oSS.Item(1).ComponentDefinitiion.IsContentMember = False Then"

Under the assumption oSS is your SelectSet, this fails because oSS.Item(1) will return an object type value and not a component occurrence as you would need. So you will need to do something of this nature: Dim oOccurrence as ComponentOccurrence = oSS.Item(1). Additionally, there is not a ComponentDefinition property available to ComponentOccurrence objects, there is only Definition. So it would be oOccurrence.Definition.IsContentMember.

 

If oSS is actually what you are using for your ComponentOccurrence collection then the result is very similar and you could use the above example or you could use one less step and the final code line would be oSS.Item(1).Definition.IsContentMember.

 

 

"If oSS.ComponentDefinitiion.IsContentMember = False Then"

This one fails for the same reason as above: there is no ComponentDefinition property available to ComponentOccurrences or SelectSet objects.

 

 

"If oDoc.ComponentDefinitiion.IsContentMember = False Then"

I am assuming you are looking for parts in an assembly which may or may not be content center parts rather than executing this code on a PartDocument where you, the user, already know whether it's a content center part or not. In that case, I would expect this to fail given that your oDoc variable most likely refers to the parent assembly document and the AssemblyComponentDefinition does not have the IsContentMember property.

Message 7 of 14

shastu
Advisor
Advisor

Thanks for your response.  If you look at my original post, oSS is the SelectSet and set to oDoc.SelectSet.  When I Set the OccurrenceName = oSS.Item(1).Name it gives me the name of the occurrence that  I have selected so that part is working correctly.  Now I just need to know if the part that is selected is a Content Center part or not because different code will run for that.  Based on what you mentioned below I have this:

 

Sub IsContent()
    Dim Occrencename As String
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    Dim oSS As SelectSet
    Set oSS = oDoc.SelectSet
    Dim oOcc As ComponentOccurrence
    Set oOcc = oSS.Item(1)
    Select Case True
        Case oSS.Count = 1
            If oSS.Item(1).Type = ObjectTypeEnum.kComponentOccurrenceObject Then
                OccurrenceName = oSS.Item(1).Name
                If oSS.Item(1).Definition.IsContentMember = False Then
                End If
               
            End If
    End Select

End Sub

 

 

The above is what makes sense to me but unfortunately I still get the 438 error.

0 Likes
Message 8 of 14

shastu
Advisor
Advisor

I just realized that it is redundant to set oOCC = oSS.Item(1).  I don't really need that as oOcc.Name and oSS.Item(1).Name gives me the same result so I am getting to the right occurrence, I just can't figure out how to determine if it is a content member or not.

0 Likes
Message 9 of 14

MechMachineMan
Advisor
Advisor

This skimmed down version of your code 100% works.

 

The only thing I can see giving you errors now is if you actually have an ASSEMBLY selected that it is trying to run IsContentMember on, because the property isn't available to AssemblyComponentDefinition.

 

Sub IsContent()

    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSS As SelectSet
    Set oSS = oDoc.SelectSet
    
    Select Case True
        Case oSS.Count = 1
            If oSS.Item(1).Type = ObjectTypeEnum.kComponentOccurrenceObject Then
                If oSS.Item(1).Definition.IsContentMember = True Then
                    MsgBox ("Is Content!")
                End If
               
            End If
    End Select
End Sub

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 14

shastu
Advisor
Advisor

I guess the real question is, can I determine the IsContentCenter from a selection set or do I have to open the file.  I am able to get it to work if I open up the file, but I rather not have to open every file in order to be able to tell if it is a content center part or not.

0 Likes
Message 11 of 14

MechMachineMan
Advisor
Advisor
No, you just have to have the file open in memory, ie as part of an
assembly/sub-assembly, and access the component definition to use the
isContentMemver property.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 12 of 14

shastu
Advisor
Advisor

So why does this MsgBox not show true or false but rather gives an error 438?  The oSS.Item(1).Name works.

 

Sub IsContent()
    Dim OccurrenceName As String
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    Dim oSS As SelectSet
    Set oSS = oDoc.SelectSet
    Select Case True
        Case oSS.Count = 1
            If oSS.Item(1).Type = ObjectTypeEnum.kComponentOccurrenceObject Then
                OccurrenceName = oSS.Item(1).Name
                MsgBox (oSS.Item(1).PartComponentDefinition.IsContentMember)
            End If
    End Select

End Sub

0 Likes
Message 13 of 14

MechMachineMan
Advisor
Advisor
Accepted solution
Because the object you have selected in your select set is a Component
occurrence object.

As explained above, neither PartComponentDefinition nor Componentdefinition
are valid methods for an occurrence and you must instead use Definition.

Ie use: MsgBox (oSS.Item (1).Definition.IsContentMember)

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 14 of 14

shastu
Advisor
Advisor

I am sure I tried that before and it didn't work.  This time I did so I don't know what I did wrong before.  In fact this is what I had pasted into my post above and I didn't think it worked.  But when I copy and paste it back from the post it still works.  Go figure.   Thanks for the help.

0 Likes