Good afternoon all,
I have a bit of a challenge I'm trying to solve.
I have a pipe assembly that has a few Ebows and Tee's in it. I need to change the size of some of the Elbows and Tee's and have been looking for a way to reach into the content center and change specific parts within my assembly.
I have given the parts to be changed a specific name in the browser but am unable to get much further from there.
Has anyone tried this? And better yet, any success?
If anyone could share a little insight with me I'd appreciate it.
Thanks,
Jeff
IV2014 SP2
I wish to change it's size but would like to be able to replace it. Right now my parts are CPVC but there are variations that require it to all be PVC.
If I have to have 2 different master assemblies for the different materials, I'll do that.
Here is the iLogic demo rule that replaces the 1st component with another family member with the known row number. Here the new member row is 4.
'This iLogic demo replaces the given standard component 'with another member from same family. ' row number of the new family member . Dim NewRow As Integer = 4 '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) 'replace the existing component with the new one oOcc.Replace(strContentPartFileName, False) Beep '---------------------------------------
Vladimir,
This looks like what I am trying to do.
I will be back in the office next week to try it.
Thank You for taking the time to look into this for me.
Jeff
Hi,
I find this a wonderful topic. But for me personal the essential part has not been addressed from the OP's question.
For me a important point is that he needs to change the size in the original question. I would also like to do this but in the API there is only a example for replacing the content-center part.
@Anonymous wrote:
I need to change the size of some of the Elbows and Tee's
@Anonymous wrote:
but would like to be able to replace it
So I think the main question here is, can you place a standard or custom content center component. And then change it's size via the API?
What is answered, is the part how to replace it. But this is a different operation with different consequences.
In example you place a custom content center in the assembly. This obligates you to save it somewhere.
So we know how to replace it from the content center as shown by @Vladimir.Ananyev, but can we change it's size too? If not, I will be obligated to look towards iParts to do the job, but my favor goes to the content center.
Hi,
I played around with things a bit.
If I inserted the Content Center part as Standard, then when changing the size through the UI the same thing will happen: the new size will be created and the component will be replaced with it, i.e. the component will reference a different part file.
If I inserted the Content Center part as Custom, then it's only created once, and when changing the size through the UI then a new member will be created and it will overwrite the originally created part file - so no "replace" happens as the referenced part file is simply overwritten with the newly created one. Should be possible through the API as well.
Cheers,
@adam.nagy wrote:Hi,
I played around with things a bit.
If I inserted the Content Center part as Standard, then when changing the size through the UI the same thing will happen: the new size will be created and the component will be replaced with it, i.e. the component will reference a different part file.
If I inserted the Content Center part as Custom, then it's only created once, and when changing the size through the UI then a new member will be created and it will overwrite the originally created part file - so no "replace" happens as the referenced part file is simply overwritten with the newly created one. Should be possible through the API as well.
Cheers,
Could you provide a sample for doing this via the API? This would be very helpfull. All I could find in the Programming help is this sample but it's not quite the same? It does not changes the size but replaces the component?
Sub ReplaceContentCenterPart() ' Set a reference to the active assembly document. Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument ' Prompt user to pick an occurrence Dim oOcc As ComponentOccurrence Set oOcc = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Pick occurrence to replace") If oOcc.DefinitionDocumentType <> kPartDocumentObject Then MsgBox "Occurrence does not reference a content part." Exit Sub End If Dim oOccDef As PartComponentDefinition Set oOccDef = oOcc.Definition If Not oOccDef.IsContentMember Then MsgBox "The occurrence does not reference a content part." Exit Sub End If ' Set a reference to the ContentCenter object. Dim oContentCenter As ContentCenter Set oContentCenter = ThisApplication.ContentCenter ' Get the content node (category) "Fasteners:Bolts:Hex Head" Dim oContentNode As ContentTreeViewNode Set oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Bolts").ChildNodes.Item("Hex Head") ' Get the "ISO 4015" Family object. Dim oFamily As ContentFamily For Each oFamily In oContentNode.Families If oFamily.DisplayName = "ISO 4015" Then Exit For End If Next ' Create a member based on the second row of the family. Dim error As MemberManagerErrorsEnum Dim strContentPartFileName As String Dim strErrorMessage As String strContentPartFileName = oFamily.CreateMember(2, error, strErrorMessage) Call oOcc.Replace(strContentPartFileName, False) End Sub
You should change the appropriate value in the members' active iPartTableRow as shown in the following vba code sample:
Sub test3() Dim oAssyDoc As Inventor.Document Set oAssyDoc = ThisApplication.ActiveDocument Dim oOccs As ComponentOccurrences Set oOccs = oAssyDoc.ComponentDefinition.Occurrences 'custom iPart member - here it's the first occurrence Dim oOcc As ComponentOccurrence Set oOcc = oOccs.Item(1) 'reference to the iPart member Dim oDef As PartComponentDefinition Set oDef = oOcc.Definition Dim oMember As iPartMember Set oMember = oDef.iPartMember 'reference to the iPart factory Dim oFactory As iPartFactory Set oFactory = oMember.ParentFactory 'table columns list Dim oColumns As iPartTableColumns Set oColumns = oFactory.TableColumns 'table rows list Dim oRows As iPartTableRows Set oRows = oFactory.TableRows Dim oRow As iPartTableRow Dim oColumn As iPartTableColumn Dim i As Integer, j As Integer 'print the current table content 'headers Debug.Print "i", For j = 1 To oColumns.Count Set oColumn = oColumns.Item(j) Debug.Print oColumn.DisplayHeading, Next j Debug.Print 'table cells' values For i = 1 To oRows.Count Set oRow = oRows.Item(i) Debug.Print i, For j = 1 To oColumns.Count Debug.Print oRow.Item(j).value, Next j Debug.Print Next 'change angle value in row 4 Set oRow = oMember.row oRow.Item(4).value = "38 deg" '<--- change to the required value 'reset active row Call oMember.ChangeRow(oRow) oAssyDoc.Update 'print the updated table content Debug.Print " --- Updated table ---" 'headers Debug.Print "i", For j = 1 To oColumns.Count Set oColumn = oColumns.Item(j) Debug.Print oColumn.DisplayHeading, Next j Debug.Print 'table cells' values For i = 1 To oRows.Count Set oRow = oRows.Item(i) Debug.Print i, For j = 1 To oColumns.Count Debug.Print oRow.Item(j).value, Next j Debug.Print Next Beep End Sub
I tested this code with the custom iPart file attached.
i Member Part Number d0 d1 1 Part1-01 Part1-01 3 0 deg 2 Part1-03 Part1-03 2 in 30 3 Part1-04 AAA 3 in 45 4 Part1-02 Part1-02 2 in 18 deg --- Updated table --- i Member Part Number d0 d1 1 Part1-01 Part1-01 3 0 deg 2 Part1-03 Part1-03 2 in 30 3 Part1-04 AAA 3 in 45 4 Part1-02 Part1-02 2 in 38 deg
Here is equivalent iLogic code (with debug printing removed). Place it in the assemble document.
Dim oAssyDoc As Inventor.AssemblyDocument = ThisDoc.Document Dim oOccs As ComponentOccurrences = oAssyDoc.ComponentDefinition.Occurrences 'custom iPart member - here it's the first occurrence Dim oOcc As ComponentOccurrence = oOccs.Item(1) 'reference to the iPart member Dim oDef As PartComponentDefinition = oOcc.Definition Dim oMember As iPartMember = oDef.iPartMember 'reference to the iPart factory Dim oFactory As iPartFactory = oMember.ParentFactory 'change angle value in row 4 Dim oRow As iPartTableRow = oMember.row oRow.Item(4).Value = "28 deg" '<--- change to the required value 'reset active row Call oMember.ChangeRow(oRow) oAssyDoc.Update Beep MsgBox("DONE")
Hi, thanks for that sample code. But i'm not sure that i'm getting it 100% Where is the link to this thread: "Ilogic to Change size on Content Center Components"?
Could you try the following code. It changes the size of the custom member via changing active row (plus prints some debugging information):
Sub TestObject() Dim oApp As Inventor.Application Set oApp = ThisApplication Dim oMainAsm As AssemblyDocument Set oMainAsm = oApp.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition Set oAsmDef = oMainAsm.ComponentDefinition ' get the 1st occurrence Dim oOcc As ComponentOccurrence Set oOcc = oAsmDef.Occurrences.Item(1) Dim oDef As PartComponentDefinition Set oDef = oOcc.Definition Dim oDoc As PartDocument Set oDoc = oDef.Document 'reference to the CC properties - oProps Dim oPropSets As PropertySets Set oPropSets = oDoc.PropertySets Dim oProps As PropertySet Set oProps = oPropSets.Item("Content Library Component Properties") ' family id Dim oProp As Inventor.Property Set oProp = oProps.Item("FamilyId") Dim FamilyId As String FamilyId = oProp.value Debug.Print "FamilyId: " + FamilyId 'reference to the ContentFamily Dim oContentCenter As ContentCenter Set oContentCenter = oApp.ContentCenter Dim oFamily As ContentFamily Set oFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#") Debug.Print "Content Family DisplayName: " + oFamily.DisplayName Debug.Print "Rows in Family: " & oFamily.TableRows.Count ' get the current MemberId Set oProp = oProps.Item("MemberId") Dim MemberId As Integer MemberId = CInt(oProp.value) Debug.Print "Current MemberId (row): " + CStr(MemberId) 'find nCol - table column for PARTNUMBER Dim nCol As Integer nCol = -1 Dim i As Integer For i = 1 To oFamily.TableColumns.Count If oFamily.TableColumns.Item(i).InternalName = "PARTNUMBER" Then nCol = i Exit For End If Next If nCol < 0 Then 'column not found - error message Exit Sub End If 'table row for the member Dim oRow As ContentTableRow Set oRow = oFamily.TableRows.Item(MemberId) 'get PartNumber Dim partNumber As String partNumber = oRow.Item(nCol).value Debug.Print "Member PartNumber: " & partNumber & vbCr ' Create a member based on the NewRow row in the family. Dim NewRow As Integer NewRow = 3 ' <--------------------- new member row Dim error As MemberManagerErrorsEnum Dim strContentPartFileName As String Dim strErrorMessage As String strContentPartFileName = oFamily.CreateMember(NewRow, error, strErrorMessage) Call oOcc.Replace(strContentPartFileName, False) Beep End Sub
cheers,
Yes! This is some good stuff. But unfortunally i'm getting this error, I don't see how you could run this code past this error? Or am I doing something wrong?
Debug data before the error, seems to be all correct.
FamilyId: d560d377-52f5-4751-b731-d8716562d772 Content Family DisplayName: EM - WN-flanges - ASME B16.5 Rows in Family: 109
Error produced on CInt(oProp.Value)
' get the current MemberId oProp = oProps.Item("MemberId") Dim MemberId As Integer MemberId = CInt(oProp.Value) Debug.Print("Current MemberId (row): " + CStr(MemberId))
Error message:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Additional information: Conversion from string "12d3857b-0da9-4bfd-ae39-ae80745c" to type 'Integer' is not valid.
Please don't tell me that this is a version issue, i'm using Autodesk Inventor 2014 SP2
I did some research on this error and it's quite logic that it's produced. In the programming help is stated:
kMemberIdContentLibrary 20 MemberId: String (VT_BSTR), Read Only, No UI, Row Id of the Member in the Family Table. Used to uniquely identify this Member in the Family Table.
So the MemberID should be a string as shown in the error message and therefor could not be convented to Integer.
Thus I made a little adjustment in the piece that produces the error. Now it works for me.
' get the current MemberId oProp = oProps.Item("MemberId") Dim MemberId As String MemberId = oProp.Value Debug.Print("Current MemberId (row): " + MemberId)
Now to illustrated what happend using this code:
I placed a standard content center part as custom into my assembly, let the code do it's magic and voila, another size of flange appeared on the spot.
The problem, this now is a standard content center part. So it did not change it's size but it replaced it. (obvious because at the end is stated oOcc.Replace)
The question still remains: can you change the size for content center parts via API without replacing it? ( Or should I use this technique to find the row values and adjust them into the part directly if it's a custom part, would be alot more coding.. Not my favorite solution because it's diffrent for each part.)
This piece of code is extremely usefull for me, but I would like to go a little bit further and change the size. Because we do like to work with custom content center parts where I work.
You cannot change the Inventor Content Center workflow. It treats standard and custom CC components a little bit differently. You may copy all the required standard components into the custom library or develop some alternatuive solution for CC to work around but this would require a lot of coding.
Correct me if i'm wrong, but how is this adjusting the content center workflow. The way I see it, it has 2 flows, but only 1 is accessible via the API?
For now, we are using the replace from content center technique? And we can't use the change size technique?
Let’s clarify – “Change Size” is a CC’s command. It will firstly generate a new file (they are based on the same family template file), and then replace.
You may customize your Custom CC member providing custom parameters’ values to the CreateMember method via the NameValueMap argument (see the code sample in the attachment):
' add length Dim nvm As NameValueMap Set nvm = ThisApplication.TransientObjects.CreateNameValueMap Call nvm.Add("B_L", length) 'B_L - length parameter name 'set the full filename for the member file Dim folder As String folder = Left(oAsmDoc.FullFileName, InStrRev(oAsmDoc.FullFileName, "\")) Dim fname As String fname = folder & "DIN 1026 - " & memberName & " - " & CStr(length) & ".ipt" 'create member file (gives an error if file was already created) Dim failureReason As MemberManagerErrorsEnum Dim failureMessage As String Dim memberFilename As String memberFilename = family.CreateMember( _ row, failureReason, failureMessage, _ ContentMemberRefreshEnum.kRefreshOutOfDateParts, _ True, fname, nvm)
If custom parts saved in the project workspace they are treated as regular Inventor files. In this case it is also possible to change their parameters (e.g., channel length is controlled by the user parameter B_L).
cheers,
Thank you @Vladimir.Ananyev for all your reply's. It's really helpfull. But just one more thing (for using content center parts as custom).. You say "It will firstly generate a new file (they are based on the same family template file), and then replace"
How does Inventor then do this? I have a flange placed as Custom and I added a chamfer on it. Now if I change size, it still is the same fle on the same location as I saved it + it still has the chamfer. Does it still generate a new file and then replace it?
Question: is it possible to get the Template Parameters for the content center family that is beeing used? If yes this would be a easy way to have a code that can change all the sizes for all the content center parts that are saved as custom.
Sorry for the long delay but this topic is interesting enough and we discussed it internally for some time.
If we talk about “Change Size as custom”, there is no existed API to support currently.
There is a series of internal logic that are implemented in CC.
For example,
…
In this case Inventor changes existing part document via Parameters API + iProperties APIs directly. No new part, no replacement. Of course, it is always better to have an appropriate API function, but in this particular case you are able to implement this workflow yourself.
You start with your CC custom component saved locally. You know its row in the CC family table and you know the new target row.
As user parameter names are the same as corresponding ContentTableColumn’s InternalNames you may update the user parameters’ values with the values read from the corresponding cells in the target row. The following function could be used to find the required column number by user parameter name:
Function GetColumnByName(ByRef family As ContentFamily, _ ByVal ColumnName As String) As Integer 'find CC family table column by its name ColumnName Dim i As Integer For i = 1 To family.TableColumns.Count If family.TableColumns.Item(i).InternalName = ColumnName Then Debug.Print "f-n GetColumnByName: " & i & " " & family.TableColumns.Item(i).InternalName GetColumnByName = i Exit Function End If Next GetColumnByName = -1 End Function
You should also update part number, stock number, MemberId, Member Revision and may be other iProperties as well. Finally you should rename component in the browser (name is usually based on part number) and update both part and assembly documents.
It is not easy to implement a general utility that could work with any CC family, but fortunately in most cases you work with several particular families (e.g., structural shapes – angles, channels, I-beams, etc.). This could simplify this implementation.
Can't find what you're looking for? Ask the community or share your knowledge.