Add content center iPart by row number

Add content center iPart by row number

Kevin.Shew
Participant Participant
1,112 Views
5 Replies
Message 1 of 6

Add content center iPart by row number

Kevin.Shew
Participant
Participant

My company has some iParts that were placed into the content center and I'm trying to modify them (i.e. hitting the "Change Size..." button but with iLogic) based off of a drop down menu from a custom parameter.  I am using the following to call the part:

 

Dim SOCOLET_LEFT = Components.AddContentCenterPart("SOCOLET (LEFT)",
                                                   "[Company] Part Library:Fittings:CS and SS:Olet",
                                                   "Olet, Sockolet - SW",
                                                   "FIT-SOL-CS-3M-1X6-10P")

 

However, I've run into an interesting problem.  The sockolets we purchase can be used on pipe ranging from 6.00" up to 10.00", hence the part number having 6-10P affixed to the end.  However, the pipe diameter changes for these in the model and the iPart table has different dimensions, depending on which pipe size you choose.  Under the "Member" column in the iPart table, these are what is listed:

 

FIT-SOL-CS-3M-1X6-10P - on 6

FIT-SOL-CS-3M-1X6-10P - on 8

FIT-SOL-CS-3M-1X6-10P - on 10

 

These three sockolets would fit on the respective pipe, but the part number that we use to order is still the same as above (without the " - on #").  Is there some way to call the specific row number when using the Components.AddContentCenterPart function instead of the family path?  Since all 3 of these have the same part number, but are functionally different, I can't specify which one I need.  Alternatively, being able to pull from the "Member" column instead of the "Part Number [Project]" column would also work.

0 Likes
Accepted solutions (1)
1,113 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

You could use the API directly rather than the ilogic snippet. The sample is here written in  VBA. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

A.Acheson
Mentor
Mentor

One method sticking with the ilogic snippet is to just drive the designation column or indeed the member column. You can do this using the findrow function

AAcheson_0-1653015171833.png

The find row function will actually find the row from the cell value without the column name but then the user doesn't know what is being searched for.  You can leave the occurrence name blank to use the default name.

Member Column:

Dim sMember As String
sMember = InputBox("Enter Member Name", "Member Name", "Sockolet_Reducing_CL3000-11")

Dim Sockolet_Reducing_CLPos = ThisAssembly.Geometry.Point(-36.710359, -13.762623, 3.279589)
Dim Sockolet_Reducing_CL = Components.AddContentCenterPart("",
                                                           "Tube & Pipe:Fittings:Branches",
                                                           "Sockolet Reducing CL3000",
                                                           {"Member",sMember },
                                                           Sockolet_Reducing_CLPos)

Designation Column:

Dim sDesignation As String
sDesignation = InputBox("Enter Designation number", "Designation#", "6-3")

Dim Sockolet_Reducing_CLPos = ThisAssembly.Geometry.Point(-36.710359, -13.762623, 3.279589)
Dim Sockolet_Reducing_CL = Components.AddContentCenterPart("Sockolet Reducing CL3000 6-3:1",
                                                           "Tube & Pipe:Fittings:Branches",
                                                           "Sockolet Reducing CL3000",
                                                           {"DESIGNATION",sDesignation},
                                                           Sockolet_Reducing_CLPos)

If you want to use the row number you will need to delve into the API a little deeper but you can also do a little more regarding replacing etc.  This rule is the reworked API sample. 

Sub Main
	Dim RowNo As Integer
	RowNo= InputBox("Enter member row number", "Member#", 1)

	ReplaceContentCenterPart(RowNo,"Tube & Pipe","Fittings","Branches","Sockolet Reducing CL3000")
	
End Sub													   
														   
														   

Sub ReplaceContentCenterPart(RowNo As Integer, Fold1 As String, Fold2 As String, _
										Fold3 As String, sFamDisName As String)
    '  a reference to the active assembly document.
    Dim oDoc As AssemblyDocument
     oDoc = ThisApplication.ActiveDocument

    ' Prompt user to pick an occurrence
    Dim oOcc As ComponentOccurrence
     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
     oOccDef = oOcc.Definition

    If Not oOccDef.IsContentMember Then
        MsgBox ("The occurrence does not reference a content part.")
        Exit Sub
    End If

    '  a reference to the ContentCenter object.
    Dim oContentCenter As ContentCenter
     oContentCenter = ThisApplication.ContentCenter

    ' Get the content node (category) e.g "Fasteners:Bolts:Hex Head"
    Dim oContentNode As ContentTreeViewNode
     oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item(Fold1).ChildNodes.Item(Fold2).ChildNodes.Item(Fold3)

    ' Get the family object. e.g "ISO 4015"
    Dim oFamily As ContentFamily
    For Each oFamily In oContentNode.Families
        If oFamily.DisplayName = sFamDisName Then
            Exit For
        End If
    Next
	
    ' Create a member based on the second row of the family.
    Dim sError As MemberManagerErrorsEnum
    Dim strContentPartFileName As String
    Dim strErrorMessage As String
    strContentPartFileName = oFamily.CreateMember(RowNo, sError, strErrorMessage)

    Call oOcc.Replace(strContentPartFileName, False)
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 6

Kevin.Shew
Participant
Participant

Unfortunately, the Designation column has the same problem that I described above.  I can use the Filename column or the Member column, since those are the only ones with a unique entry.  The row number would be ideal, but I can work with Filename or Member just fine.  I saw that Components.AddContentCenterPart has "findrow AsObject ()" as the fourth input, but I can't figure out how to make it actually work.  The only input that doesn't result in an error is placing a value from the Part Number column (although it might be the Designation column, since they have the same values).

0 Likes
Message 5 of 6

A.Acheson
Mentor
Mentor
Accepted solution

Have you tried the member column snippet posted above? I placed a title over head just for clarity. If you enter a column name it has to have the exact font case used in the family table. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 6

Kevin.Shew
Participant
Participant

So, I played with it more and it did actually solve my issue.  Here is the code that ended up working:

 

Dim SOCOLET_LEFT = Components.AddContentCenterPart("SOCOLET (LEFT)",
                                                   "[Company] Part Library:Fittings:CS and SS:Olet",
                                                   "Olet, Sockolet - SW",
{"Member", "FIT-SOL-CS-3M-1X6-10P - on 6"})

 

For some reason, I kept getting errors, but I think that was due to a formatting issue.  The bit in the brackets there let me customize which column I searched for, which is mainly what I was looking for.  Thank you very much for helping me get through this.