Assistance to place a Content Center part into a subassembly

Assistance to place a Content Center part into a subassembly

JBerns
Advisor Advisor
726 Views
15 Replies
Message 1 of 16

Assistance to place a Content Center part into a subassembly

JBerns
Advisor
Advisor

Community,

 

I am trying to place Content Center parts into a subassembly.

 

The following iLogic code works well to place a part with a known Stock Number into a top-level assembly:

' Specify language
Components.ContentCenterLanguage = "en-US"

' Add hardware component
Dim oBolt1Pos = ThisAssembly.Geometry.Point(0.0, 0.0, 0.0)
Dim compBolt1 = Components.AddContentCenterPart("Bolt1", "Fasteners:Bolts:Hex Head", "Hex Cap Screw - Inch", {"StockNumber", "123-1234" }, oBolt1Pos)

 

To my knowledge, the API must be used to place a content Center part into a subassembly.

I do not know how to obtain the component by its Stock Number using the API.

What I have pieced together from other forum posts:

' Get the node in the content browser based on the names of the nodes in the hierarchy.
Dim SpringWasherNode As ContentTreeViewNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Washers").ChildNodes.Item("Spring")
    
' Find a specific family.
Dim family As ContentFamily
Dim checkFamily As ContentFamily
For Each checkFamily In SpringWasherNode.Families
   If checkFamily.DisplayName = "Lock Washer - Inch" Then
      family = checkFamily
      Exit For
   End If
Next

If Not family Is Nothing Then
   '''
   '''  GET COMPONENT BY ITS STOCK NUMBER. NEED HELP HERE.
   '''

   ' Create the member (part file) from the table.
   Dim failureReason As MemberManagerErrorsEnum
   Dim failureMessage As String
   Dim memberFilename As String
   memberFilename = family.CreateMember(????????, failureReason, failureMessage, kRefreshOutOfDateParts)
        
   ' Place the part into the assembly.
   Dim transMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
   transMatrix.Cell(2, 4) = offset
   Try
      Dim Occ As ComponentOccurrence = subasmDef.Occurrences.Add(memberFilename, transMatrix)
   Catch
   End Try
End If

 

Of course to test this code, you will need to modify to match names within your content center library.

 

Any assistance to identify the CC part by its stock number would be appreciated.

If there is a better method to place CC parts into a subassembly,  I welcome your suggestions.

 

BTW- I tried using Edit and ExitEdit, but that resulted in noticeable flickering as assemblies were edited and exited.

 

Thank you for your time and attention. I look forward to your replies.

 

Regards,
Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Accepted solutions (2)
727 Views
15 Replies
Replies (15)
Message 2 of 16

Curtis_Waguespack
Consultant
Consultant

@JBerns , I'm short on time ( stepping into a meeting) but if you have a cc part in the assembly you can extract the code to place it as shown by right clicking

 

Curtis_Waguespack_0-1739483942481.png

 

EESignature

0 Likes
Message 3 of 16

Curtis_Waguespack
Consultant
Consultant

@JBerns  my apologies I missed half of that message, I was probably just in a hurry and missed it but I would swear there was only one code block, etc.  In any case I missed part about the sub assembly, so disregard the previous message

 

But you are right in that the iLogic add component functions only work on the document the rule is run from, I think I have hack for this though.

If not would it work to have the rule in the sub assembly, and just run that rule from the top level?

I'll take a look at the API example you provided also.

 

 

EESignature

0 Likes
Message 4 of 16

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@JBerns , ok here's the example I had on hand. It's a bit of a workaround, but it is what I found to work pretty well.

  • We place the CC component at the top level, with the ilogic function
  • capture it's fulldocument name
  • delete it from the top level
  • and then place it in the sub assembly

Will this work for you?

 

'place the cc component
CC_Comp = Components.AddContentCenterPart("Bolt1", "Fasteners:Bolts:Socket Head", "ISO 4762", {"NLG", "2.5", "SIZE_SEL", "M1.6" })

'get the file path & name from the component occurrence 
oPath_Name = CC_Comp.Occurrence.Definition.Document.FullDocumentName

'delete the component from the top level
CC_Comp.Occurrence.Delete

'get the sub assembly occurrence
Dim SubAsmDoc As AssemblyDocument = Component.InventorComponent("Block Sub Assembly:1").Definition.Document

'get the sub assembly component definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = SubAsmDoc.ComponentDefinition

' Create a matrix.  
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix

'set an insert point
oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(0, 0, 0))

'add to the sub assembly 
oOcc = oAsmCompDef.Occurrences.Add(oPath_Name, oMatrix)

 

EESignature

0 Likes
Message 5 of 16

ryan.rittenhouse
Advocate
Advocate

Curtis' way looks like it'll work for you, but in case you want/need another option, you can give this a try. If you use the ObjectProvider, you can access the Components wrapper from the context of your subassembly. Using the example you posted, you could do something like this:

 

Dim subasmDoc As AssemblyDocument = subasmDef.Document
Dim compBolt1 As ComponentOccurrence = iLogicVb.CreateObjectProvider(subasmDoc).ThisAssembly.Components.AddContentCenterPart("Bolt1", "Fasteners:Bolts:Hex Head", "Hex Cap Screw - Inch", {"StockNumber", "123-1234" }, oBolt1Pos)

 

Hope it helps

 

-Ryan 

If this solved your problem, or answered your question, please click Accept Solution.
Message 6 of 16

JBerns
Advisor
Advisor

@Curtis_Waguespack,

Interesting approach to insert at top-level, capture info, delete, insert into subassembly.

Likely easier than another approach I considered, which was to insert and demote.

I am testing yours and Ryan's proposed solutions.

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 7 of 16

Curtis_Waguespack
Consultant
Consultant

@JBerns , I like @ryan.rittenhouse  suggestion ( I think WCrihfield pointed me to the ObjectProvider function recently, but I always forget about it)

 

With just a quick test I was not able to get the ObjectProvider to work, though.

 

This example places a standard CC fastener in the top level assembly ( that works) , but attempting to do so in the sub results in what appears to be a syntax error trying to find the CC member.

 

Maybe you guys can help understand what I need to get it to work?

 

'place at top level
Components.AddContentCenterPart("Bolt1", "Fasteners:Bolts:Socket Head", "ISO 4762", {"NLG", "2.5", "SIZE_SEL", "M1.6" })

'place in sub
Dim SubAsmDoc As AssemblyDocument = Component.InventorComponent("Block Sub Assembly:1").Definition.Document
Dim compBolt1 As ComponentOccurrence
compBolt1 = iLogicVb.CreateObjectProvider(SubAsmDoc).ThisAssembly.Components.AddContentCenterPart _
	("Bolt1", "Fasteners:Bolts:Socket Head", "ISO 4762", {"NLG", "2.5", "SIZE_SEL", "M1.6" })

 

Curtis_Waguespack_0-1739547421812.png

 

 

EESignature

0 Likes
Message 8 of 16

JBerns
Advisor
Advisor

@ryan.rittenhouse,

 

Your proposed solution is nearly working for me, but I am getting an error that it can't find that row in the content center.

I built the code below to insert an ANSI Hex Head Cap Screw in the top-level assembly and then in the subassembly.

 

''' INSERT PART AT TOP LEVEL ASSEMBLY WORKS

Dim Hex_Cap_Screw_Inch_1Pos = ThisAssembly.Geometry.Point(2, 6, 1.75)
Dim Hex_Cap_Screw_Inch_1 = Components.AddContentCenterPart("Hex Cap Screw - Inch 1/2-13 UNC - 2:1",
                                                            "Fasteners:Bolts:Hex Head",
                                                            "Hex Cap Screw - Inch",
                                                            {"DESIGNATION", "1/2-13 UNC - 2"},
                                                            Hex_Cap_Screw_Inch_1Pos)
''' INSERT PART IN SUBASSEMBLY FAILS
''' ERROR:
''' 	AddContentCenterPart: No content center row With the specification
''' 	"Fasteners:Bolts:Hex Head Hex Cap Screw - Inch DESIGNATION 1/2-13 UNC - 2" was found.

Dim compHCS1 As ComponentOccurrence = iLogicVb.CreateObjectProvider(oSub1Doc).ThisAssembly.Components.AddContentCenterPart(
	"Hex Cap Screw - Inch 1/2-13 UNC - 2:1",
	"Fasteners:Bolts:Hex Head",
	"Hex Cap Screw - Inch",
	{"DESIGNATION", "1/2-13 UNC - 2"},
	iLogicVb.CreateObjectProvider(oSub1Doc).ThisAssembly.Geometry.Point(-10, 0, 0)
	)

 

I copied the working code for the top-level into the code for the subassembly.

 

The error:

AddContentCenterPart: No content center row with the specification "Fasteners:Bolts:Hex Head Hex Cap Screw - Inch DESIGNATION 1/2-13 UNC - 2" was found.
Hex Cap Screw - Inch -> 1/2-13 UNC - 2,

 

JBerns_0-1739547301587.png

 

Could you test this code to see if it works for you?

 

Regards,

Jerry

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 9 of 16

ryan.rittenhouse
Advocate
Advocate

@JBerns - We don't use the content center, so I'm going to sent up a temporary one and see if I can get it working. You might be better off using Curtis' suggested route. I'll let you know if I get the object provider method to behave

If this solved your problem, or answered your question, please click Accept Solution.
0 Likes
Message 10 of 16

JBerns
Advisor
Advisor

@Curtis_Waguespack,

 

With one change to your code, the proposed solution works.

Lines 10-11 should declare a data type of ComponentOccurrence instead of an AssemblyDocument:

'get the sub assembly occurrence
Dim SubAsmDoc As ComponentOccurrence = Component.InventorComponent("Block Sub Assembly:1")

 I left the 'SubAsmDoc' for testing, but I will change it to 'SubAsmOcc' to match the data type. Other lines will be updated to match the change.

Thanks again for this interesting solution.

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 11 of 16

JBerns
Advisor
Advisor

@Curtis_Waguespack,

Yes, same for me - No content center row with specification...

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 12 of 16

Curtis_Waguespack
Consultant
Consultant

ooops! thanks for pointing that out Jerry.

I was juggling and struggling yesterday afternoon, lol... So I don't know how I was getting that to work yesterday( or thinking I was) , but I did see the same error just now on line 11. I updated the code in that post to work without error, for the next person that might find it.

 

I'd still like to get Ryan's suggestion working. Hopefully he'll provide some magic later, if not maybe we can have Mike Deck take a look.

 

EESignature

0 Likes
Message 13 of 16

JBerns
Advisor
Advisor

@Curtis_Waguespack,

I knew you were busy yesterday and understood the intention.

Wish all coding corrections were that easy.

Ryan is working on his code. I too hope he can find a solution.

Yes, Mike, would be a good suggestion. Perhaps also Wes.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 14 of 16

JBerns
Advisor
Advisor

@MjDeck (Mike),

Could you explain why the code in messages 7 and 8 above result in the error shown?

It's as though the CreateObjectProvider call is concatenating the arguments into a single string.

I have successfully used the CreateObjectProvider example by @ryan.rittenhouse with Constraints.AddByiMateAndEntity and Constraints.AddByiMates.

Both of these pass several strings.

I wonder why Components.AddContentCenterPart fails, which also uses several arguments.

Thank you for your time and attention. I look forward to your reply.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 15 of 16

MjDeck
Autodesk
Autodesk
Accepted solution

@JBerns , there is a limitation for the object provider here. The Content Center code needs to know which language to use. It is set automatically in the main assembly, but not in a subassembly. This is easy to work around.
Note: in the following I have the subassembly name hardcoded as "Sub588a:1". You'll have to change that.

Dim Hex_Cap_Screw_Inch_1Pos = ThisAssembly.Geometry.Point(2, 6, 1.75)
Dim Hex_Cap_Screw_Inch_1 = Components.AddContentCenterPart("Hex Cap Screw - Inch 1/2-13 UNC - 2:1",
                                                            "Fasteners:Bolts:Hex Head",
                                                            "Hex Cap Screw - Inch",
                                                            {"DESIGNATION", "1/2-13 UNC - 2"},
                                                            Hex_Cap_Screw_Inch_1Pos)

Dim oSub1Doc As Document = Component.InventorComponent("Sub588a:1").Definition.Document
Dim subObjects = iLogicVb.CreateObjectProvider(oSub1Doc)
subObjects.ThisAssembly.Components.ContentCenterLanguage = ThisAssembly.Components.ContentCenterLanguage

Dim compHCS1 = subObjects.ThisAssembly.Components.AddContentCenterPart(
	"Hex Cap Screw - Inch 1/2-13 UNC - 2:1",
	"Fasteners:Bolts:Hex Head",
	"Hex Cap Screw - Inch",
	{"DESIGNATION", "1/2-13 UNC - 2"},
	subObjects.ThisAssembly.Geometry.Point(-10, 0, 0) )

Mike Deck
Software Developer
Autodesk, Inc.

Message 16 of 16

JBerns
Advisor
Advisor

@MjDeck 

 

Thanks, Mike! I was trying to set the ContentCenterLanguage for the subassembly, but was not getting the context correct.

 

It is remarkable the commands/functions that can be used in subassemblies using the CreateObjectProvider.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes