Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic place Structural Shapes:Channels, how to change length?

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
cean_au
1539 Views, 11 Replies

iLogic place Structural Shapes:Channels, how to change length?

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)

 

 

 

11 REPLIES 11
Message 2 of 12
Mario-Villada
in reply to: cean_au

Try changing the parameter called "G_L"

 

Message 3 of 12

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.

Message 4 of 12

hi, can you please ping the code to modify the parameter by ilogic. I have same issue in selecting bolt type and length of a content center file.
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/ilogic-to-trigger-and-insert-custom-co...
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 5 of 12

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.

Message 6 of 12

Hi,

 

Got message: "ModelParameter is not defined". I am using autodesk inventor 2011. Kindly help

codeError.png

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 7 of 12

The code is for VBA

But I guess ilogic can be as simple as getting the parameter like the in picture below.ilogic.JPG

 

Message 8 of 12

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

 

 

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 9 of 12
Carthik_Babu
in reply to: Carthik_Babu

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)

ContentFamily_CreateMember Method.jpg

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 10 of 12
adam.nagy
in reply to: Carthik_Babu

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,



Adam Nagy
Autodesk Platform Services
Message 11 of 12
Carthik_Babu
in reply to: adam.nagy

Hi Adam Nagy,

 

Thanks al lot for the solution.....Smiley Happy

 

I have modified the code as below, it worked......Smiley Very Happy

 

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

 

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 12 of 12
Carthik_Babu
in reply to: Carthik_Babu

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

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report