Hi,
I got this code below to place a channel in an assembly, but don't know how to change the length of the steel.
thanks for help
Cean
' Set a reference to the active assembly document. Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument ' Set a reference to the ContentCenter object. Dim oContentCenter As ContentCenter oContentCenter = ThisApplication.ContentCenter ' Get the content node (category) "Structural Shapes:Channels" Dim oContentNode As ContentTreeViewNode oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Structural Shapes").ChildNodes.Item("Channels") ' Get the "DIN 1026 U" Family object. Dim oFamily As ContentFamily For Each oFamily In oContentNode.Families If oFamily.DisplayName = "DIN 1026 U" Then Exit For End If Next ' Create a member based on the first row of the family. Dim myError As MemberManagerErrorsEnum Dim strContentPartFileName As String Dim strErrorMessage As String strContentPartFileName = oFamily.CreateMember(1, myError, strErrorMessage) MessageBox.Show(strContentPartFileName) Dim oMat As Matrix oMat = ThisApplication.TransientGeometry.CreateMatrix ' Insert an instance of the content center member in the assembly. call oDoc.ComponentDefinition.Occurrences.Add(strContentPartFileName, oMat)
Solved! Go to Solution.
Solved by Mario-Villada. Go to Solution.
Hi,
I believe Mario-Villada is correct. One of the parameters of the CC part should control the length of the steel. You could find it and modify it.
Have a look at a sample code in the programming help called " Model Parameters API Sample". you should find out which parameter controls the length and change it by code. here is some code from the help file.
' Obtain the Model Parameters collection Dim oModelParams As ModelParameters Set oModelParams = oParams.ModelParameters ' Iterate through the Model Parameters collection Dim iNumModelParams As Long Debug.Print "MODEL PARAMETER VALUES" For iNumModelParams = 1 To oModelParams.Count ' Display the Name Debug.Print " Name:" & oModelParams.Item(iNumModelParams).Name ' Display the Value Debug.Print " Value: " & oModelParams.Item(iNumModelParams).Value ' Display the units Debug.Print " Units: " & oModelParams.Item(iNumModelParams).Units ' Change the Model Parameter values oModelParams.Item(iNumModelParams).Value = oModelParams.Item(iNumModelParams).Value * 2 Next iNumModelParams ' Accessing a particular parameter if you know its name, the user and reference parameters can also be accessed in a similar way oModelParams.Item("d0").Name = "NewParam" ' Change the value of the newly named parameter "param1" oModelParams.Item("NewParam").Value = 25 ' Update the model. oPartDoc.Update
Please select this as solved if it helped you.
Hi,
Got message: "ModelParameter is not defined". I am using autodesk inventor 2011. Kindly help
The code is for VBA
But I guess ilogic can be as simple as getting the parameter like the in picture below.
Hi,
I tried the way, you have told by just handling part parameter by ilogic as shown in the below code.
Sub Main()
PlaceContentCenterPart_GND()
iLogicVb.UpdateWhenDone = True
ThisApplication.ActiveView.Fit
End Sub
Sub PlaceContentCenterPart_GND()
' Set a reference to the active assembly document.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the ContentCenter object.
Dim oContentCenter As ContentCenter
oContentCenter = ThisApplication.ContentCenter
' Get the content node (category)
Dim oContentNode As ContentTreeViewNode
oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Tube & Pipe").ChildNodes.Item("Conduits").ChildNodes.Item("Pipes")
' Get the Family object.
Dim oFamily As ContentFamily
For Each oFamily In oContentNode.Families
If oFamily.DisplayName = "ANSI/ASME B36.19M Pipe" Then
Exit For
End If
Next
' Create a member based on the first row of the family.
Dim Error1 As MemberManagerErrorsEnum
Dim strContentPartFileName As String
Dim strErrorMessage As String
strContentPartFileName = oFamily.CreateMember(1, Error1, strErrorMessage)
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create a matrix.
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
'place an instance of the component
'in this case at 0,0,0
'positioned at the co-ordinates
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))
oOccurrence = oAsmCompDef.Occurrences.Add(strContentPartFileName, oMatrix)
oOccurrence.Grounded = True
Pipe_Length = InputBox("Enter Pipe length (Unit:inches)", "Pipe length", "10")
Parameter(oOccurrence.Name, "L") = Pipe_Length
Component.Color(oOccurrence.Name) = "Red"
End Sub
It works. But the name of the inserted component (ANSI/ASME B36.19M Pipe 1/8 - Schedule 10S - 10:1), remains same. Is there is any way to assign Pipe Length in the code
oAsmCompDef.Occurrences.Add
which inserts the part into assembly.
Thanks in advance
Any help to handle
Sub CreateMember(Row As VARIANT, ByRef FailureReason As MemberManagerErrorsEnum, ByRef FailureMessage As String, ByRef Refresh As [defaultvalue(kUseDefaultRefreshSetting)] ContentMemberRefreshEnum, ByRef Custom As [defaultvalue(0)] Boolean, ByRef FileName As [defaultvalue("")] String, ByRef CustomInput As [optional] VARIANT, ByRef Options As [optional] VARIANT, Result As [out, retval] BSTR)
Hi Carthik,
You just need to provide custom parameter values for the member you are creating. Simply modify this part of the code:
Dim values As NameValueMap values = ThisApplication.TransientObjects.CreateNameValueMap Call values.Add("B_L", "0.5 in") Dim strErrorMessage As String strContentPartFileName = oFamily.CreateMember(1, myError, strErrorMessage, , , , values)
Cheers,
Hi Adam Nagy,
Thanks al lot for the solution.....
I have modified the code as below, it worked......
Sub Main()
PlaceContentCenterPart_GND()
iLogicVb.UpdateWhenDone = True
ThisApplication.ActiveView.Fit
End Sub
Sub PlaceContentCenterPart_GND()
' Set a reference to the active assembly document.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the ContentCenter object.
Dim oContentCenter As ContentCenter
oContentCenter = ThisApplication.ContentCenter
' Get the content node (category)
Dim oContentNode As ContentTreeViewNode
oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Tube & Pipe").ChildNodes.Item("Conduits").ChildNodes.Item("Pipes")
' Get the Family object.
Dim oFamily As ContentFamily
For Each oFamily In oContentNode.Families
If oFamily.DisplayName = "ANSI/ASME B36.19M Pipe" Then
Exit For
End If
Next
' Create a member based on the first row of the family.
Dim Error1 As MemberManagerErrorsEnum
Dim strContentPartFileName As String
Dim values As NameValueMap
values = ThisApplication.TransientObjects.CreateNameValueMap
Dim strErrorMessage As String
Pipe_Length = InputBox("Enter Pipe length (Unit:inches)", "Pipe length", "1")
Call values.Add("PL", Pipe_Length)
strContentPartFileName = oFamily.CreateMember(1, Error1, strErrorMessage, , , ,values)
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create a matrix.
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
'place an instance of the component
'in this case at 0,0,0
'positioned at the co-ordinates
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))
oOccurrence = oAsmCompDef.Occurrences.Add(strContentPartFileName, oMatrix)
oOccurrence.Grounded = True
Component.Color(oOccurrence.Name) = "Red"
End Sub
Hi,
To insert Content Center Part as Custom, Kindly find the code below. Hope it will be useful.
Sub Main()
PlaceContentCenterPart_GND()
iLogicVb.UpdateWhenDone = True
ThisApplication.ActiveView.Fit
End Sub
Sub PlaceContentCenterPart_GND()
Top_Node = "Tube & Pipe"
ChildNodes1 = "Conduits"
ChildNodes2 = "Pipes"
Family_Name = "ANSI/ASME B36.19M Pipe"
' Set a reference to the active assembly document.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim fileName As String = String.Empty
Dim CustomPartDirectory= ThisDoc.Path & "\"
Dim isCustom As Boolean = m_customInfo IsNot Nothing
Dim refresh As Inventor.ContentMemberRefreshEnum = ContentMemberRefreshEnum.kUseDefaultRefreshSetting
' Set a reference to the ContentCenter object.
Dim oContentCenter As ContentCenter
oContentCenter = ThisApplication.ContentCenter
' Get the content node (category)
Dim oContentNode As ContentTreeViewNode
oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item(Top_Node).ChildNodes.Item(ChildNodes1).ChildNodes.Item(ChildNodes2)
' Get the Family object.
Dim oFamily As ContentFamily
For Each oFamily In oContentNode.Families
If oFamily.DisplayName = Family_Name Then
Exit For
End If
Next
' Create a member based on the first row of the family.
Dim Error1 As MemberManagerErrorsEnum
Dim strContentPartFileName As String
Dim values As NameValueMap
values = ThisApplication.TransientObjects.CreateNameValueMap
Dim strErrorMessage As String
Pipe_Length = InputBox("Enter Pipe length (Unit:inches)", "Pipe length", "1")
fileName = IO.Path.Combine(CustomPartDirectory + "Output\" , MakeValidFileName(Family_Name + "" + "1/8 - Schedule 10S" + " - " +CStr(Pipe_Length)+ ".ipt"))
Call values.Add("PL", Pipe_Length)
MsgBox(fileName)
strContentPartFileName = oFamily.CreateMember(1, Error1, strErrorMessage,refresh,isCustom,fileName ,values)
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create a matrix.
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
'place an instance of the component
'in this case at 0,0,0
'positioned at the co-ordinates
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))
oOccurrence = oAsmCompDef.Occurrences.Add(strContentPartFileName, oMatrix)
oOccurrence.Grounded = True
Component.Color(oOccurrence.Name) = "Red"
End Sub
Public Shared Function MakeValidFileName(ByVal fileName As String) As String
Dim invalidChars As Char() = New Char() {"/"c, "\"c, ":"c, "<"c, ">"c, """"c}
If (fileName.IndexOfAny(invalidChars) < 0) Then
Return fileName
End If
For Each ch As Char In invalidChars
fileName = fileName.Replace(ch, "_"c)
Next
Return fileName
End Function
Example File:http://grabcad.com/library/ilogic-content-center-1