Create every possible instance of a Content Center Part

Create every possible instance of a Content Center Part

iogurt1
Advocate Advocate
4,965 Views
20 Replies
Message 1 of 21

Create every possible instance of a Content Center Part

iogurt1
Advocate
Advocate

For some reasons it would take too long to explain, we want to create every possible instance of a Content Center part. We have a Flange that has different sizes, schedules and materials (see picture). The family table shows that there are 298 possible iterations. Is it possible thru iLogic to create every possible part so we can check them into Vault? 

0 Likes
Accepted solutions (1)
4,966 Views
20 Replies
Replies (20)
Message 2 of 21

iogurt1
Advocate
Advocate

So I guess I just answered my own question and if someone later stumbles upon this, use the following code. Might not be the most efficient way to do it but it works.

 

Note: It creates the files in the background while the rule is running. And if your family table has less than 99999 rows, there will be an error once all the possible parts have been created so you know it's done.

 

 

i = 1
While i < 999999

Dim NewRow As Integer = i

'active assembly s
Dim oMainAsm As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oMainAsm.ComponentDefinition

' get the occurrence by its position in the occurrences collection
Dim oOcc As ComponentOccurrence = oAsmDef.Occurrences.Item(1)
Dim oDef As PartComponentDefinition = oOcc.Definition
Dim oDoc As PartDocument = oDef.Document

'reference to the CC properties - oProps
Dim oPropSets As PropertySets = oDoc.PropertySets
Dim oProps As PropertySet = oPropSets.Item("Content Library Component Properties")

' family id
Dim oProp As Inventor.Property = oProps.Item("FamilyId")
Dim FamilyId As String = oProp.Value
'MsgBox("FamilyId: " + FamilyId)

'reference to the ContentFamily
Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
Dim oFamily As ContentFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#")  
'MsgBox("Content Family DisplayName:  " + oFamily.DisplayName & vbNewLine & _'        "Rows in Family:  " & oFamily.TableRows.Count )'
''create new member file
Dim ErrorType As MemberManagerErrorsEnum
Dim strContentPartFileName As String
Dim strErrorMessage As String
strContentPartFileName = oFamily.CreateMember(NewRow, ErrorType, strErrorMessage)

i= i+1
End While  

 

Message 3 of 21

Jef_E
Collaborator
Collaborator
Accepted solution

Wow, thats written so expensive.. you do alot of steps 99999 times that are only required once? And get an error to know it's done? Is that a thing now?

 

I took the liberty to adjust that code a little.. didn't change anything except the loop and added an end message. I guess a For Each oRow As ContentTableRow In oFamily.TableRows would also be possible as loop

 

        'active assembly s
        Dim oMainAsm As AssemblyDocument = ThisDoc.Document
        Dim oAsmDef As AssemblyComponentDefinition = oMainAsm.ComponentDefinition

        ' get the occurrence by its position in the occurrences collection
        Dim oOcc As ComponentOccurrence = oAsmDef.Occurrences.Item(1)
        Dim oDef As PartComponentDefinition = oOcc.Definition
        Dim oDoc As PartDocument = oDef.Document

        'reference to the CC properties - oProps
        Dim oPropSets As PropertySets = oDoc.PropertySets
        Dim oProps As PropertySet = oPropSets.Item("Content Library Component Properties")

        ' family id
        Dim oProp As Inventor.Property = oProps.Item("FamilyId")
        Dim FamilyId As String = oProp.Value
        'MsgBox("FamilyId: " + FamilyId)

        'reference to the ContentFamily
        Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
        Dim oFamily As ContentFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#")
        'MsgBox("Content Family DisplayName:  " + oFamily.DisplayName & vbNewLine & _'        "Rows in Family:  " & oFamily.TableRows.Count )'
        ''create new member file
        Dim ErrorType As MemberManagerErrorsEnum
        Dim strContentPartFileName As String
        Dim strErrorMessage As String

        ' Do a loop here for all the rows.
        For i As Integer = 1 To oFamily.TableRows.Count
            strContentPartFileName = oFamily.CreateMember(i, ErrorType, strErrorMessage)
        Next

        ' Msgbox to alert the process is done.
        MsgBox("All " & oFamily.TableRows.Count & " c/c family items are created.")

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 4 of 21

iogurt1
Advocate
Advocate

Thanks for this. Yeah, letting an error show if something is done isn't the best way, glad there's a solution to this 🙂

0 Likes
Message 5 of 21

AreHoland
Contributor
Contributor

Hi,

thank you for sharing this rule, it saved me a lot of time generating members. I'm not very good with code, but i would very much like this rule to exclude rows in the family that is suppressed, or if part number contains "NA". Anyone got an idea on how to solve this?

 

Best Regards

Are

0 Likes
Message 6 of 21

Jef_E
Collaborator
Collaborator
        'active assembly s
        Dim oMainAsm As AssemblyDocument = ThisDoc.Document
        Dim oAsmDef As AssemblyComponentDefinition = oMainAsm.ComponentDefinition

        ' get the occurrence by its position in the occurrences collection
        Dim oOcc As ComponentOccurrence = oAsmDef.Occurrences.Item(1)
        Dim oDef As PartComponentDefinition = oOcc.Definition
        Dim oDoc As PartDocument = oDef.Document

        'reference to the CC properties - oProps
        Dim oPropSets As PropertySets = oDoc.PropertySets
        Dim oProps As PropertySet = oPropSets.Item("Content Library Component Properties")

        ' family id
        Dim oProp As Inventor.Property = oProps.Item("FamilyId")
        Dim FamilyId As String = oProp.Value
        'MsgBox("FamilyId: " + FamilyId)

        'reference to the ContentFamily
        Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
        Dim oFamily As ContentFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#")
        'MsgBox("Content Family DisplayName:  " + oFamily.DisplayName & vbNewLine & _'        "Rows in Family:  " & oFamily.TableRows.Count )'
        ''create new member file
        Dim ErrorType As MemberManagerErrorsEnum
        Dim strContentPartFileName As String
        Dim strErrorMessage As String

        ' Do a loop here for all the rows.
        For i As Integer = 1 To oFamily.TableRows.Count
If Not oFamily.TableRows.Item(i).IsSuppressed Then strContentPartFileName = oFamily.CreateMember(i, ErrorType, strErrorMessage)
End If Next ' Msgbox to alert the process is done. MsgBox("All " & oFamily.TableRows.Count & " c/c family items are created.")  

 

If you also need the NA function included let me know, I must think then 😉 I marked the changes with blue.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 7 of 21

AreHoland
Contributor
Contributor

Hi,

thank you very much, it worked perfect! I do not need the "NA" exclusion, i just need one of them:)

 

Best Regards

Are

0 Likes
Message 8 of 21

cmcconnell
Collaborator
Collaborator

Hello,

 

I also have a need to create the children from entire content center families.

 

Unfortunately, I do not know much about iLogic.

 

I have attempted to use this snippet in an assembly, and it throws the following error:

 

Error in rule: Rule0, in document: Assembly2.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

I am attempting to run the code in an assembly - is this the correct place? I should add that I am currently working in IV 2017.

Mechanix Design Solutions inc.
0 Likes
Message 9 of 21

MechMachineMan
Advisor
Advisor

How the rule is written:

 

1. Make an assembly file.

2. Place - FROM THE CONTENT CENTER - the content center item you would like to have every row generated for.

3. Run the rule.

4. Wait and watch the magic.


--------------------------------------
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
Message 10 of 21

jgoetsch
Enthusiast
Enthusiast

This process takes a very long time to run (8 seconds each. families rang from 500 to 3500 items). even on a CPU running at 5.2ghz. Is there anyway to improve the speed? Additionally can it be modified to work through all content center families that are in the assembly? This way I could build an assembly that has each of the families we have Modified and run them all at once.

0 Likes
Message 11 of 21

K.TRYFONIDIS
Advocate
Advocate

This is a Very nice proposal, have you managed to get any code for this proposal.

 

 

0 Likes
Message 12 of 21

JUSTIN_BRADFORD
Contributor
Contributor

Once the rule is run, do I need to check the part in? 

 

We are updating all of the family tables we have and now need each version checked into vault to not break all of our assemblies. 

 

 

0 Likes
Message 13 of 21

jgoetsch
Enthusiast
Enthusiast

No, I haven't had any response. I'm sure I could write it at this point, but "time is time, and I have none".

0 Likes
Message 14 of 21

iogurt1
Advocate
Advocate
As I remember it, you now have to check them all in, Yes
0 Likes
Message 15 of 21

jgoetsch
Enthusiast
Enthusiast

When we run this routine. We checkout all existing files from the the vault. Then run the program. then check everything back in.

0 Likes
Message 16 of 21

JUSTIN_BRADFORD
Contributor
Contributor

That makes sense. We were trying to figure out if we needed to delete the files from the vault, run this script and then basically check new files in. Or if this would update the existing files. 

0 Likes
Message 17 of 21

Jerzy.FabianskiNGSZF
Participant
Participant

Hello.

I'm pretty fresh with macros, trying to run following macro, but get some error.

I would be great full for any help on it.

So far I'm working on Inv. 2021 & installed latest visual studio in addition.

I have created assembly, placed C-C file in it and saved all on Hdd, but unfortunately it's not working.

0 Likes
Message 18 of 21

robmit_arm
Participant
Participant

1. This is iLogic not VBA.

2. This is internal rule, to run this iLogic you must save it within assembly file.

0 Likes
Message 19 of 21

Jerzy.FabianskiNGSZF
Participant
Participant
Thank you.
Working now.
0 Likes
Message 20 of 21

diego_dorta
Enthusiast
Enthusiast

thank you very usefull rule. is there the way to not only generete the file but also place them in the current assembly. this will be very time saving when you have to update the content center file after a family table change.

thank you

0 Likes