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: 

API Place custom c/c part

1 REPLY 1
Reply
Message 1 of 2
Anonymous
322 Views, 1 Reply

API Place custom c/c part

Hi,

 

I'm looking for a way to place a custom content-center part in my assembly by rule.

Is this possible?

 

I found this code in the "programming help" but i cannot get it to work. And i guess it's for standard parts?

 

Sub PlaceContentCenterPart()

    ' Set a reference to the active assembly document.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    ' 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 first row of the family.
    Dim error As MemberManagerErrorsEnum
    Dim strContentPartFileName As String
    Dim strErrorMessage As String
    strContentPartFileName = oFamily.CreateMember(1, error, strErrorMessage)

    Dim oMat As Matrix
    Set oMat = ThisApplication.TransientGeometry.CreateMatrix

    ' Insert an instance of the content center member in the assembly.
    Call oDoc.ComponentDefinition.Occurrences.Add(strContentPartFileName, oMat)
End Sub

 

I'm getting these errors.

 

Rule Compile Errors in Plaats part, in Plaatsen van content center parts.iam

Error on Line 22 : Keyword is not valid as an identifier.
Error on Line 25 : Expression expected.

 

So I'm kinda stuck on this one. Getting this to work would save me loads of time in the future!

 

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

Oké,

 

The first obvious error is out.. My bad.. adjusted the API sample a little and got it to work. Got a Standard Bolt (first size available) placed in my assembly.

 

 

How can i get the Bolt to be placed as a custom part?

 

    ' 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) "Fasteners:Bolts:Hex Head"
    Dim oContentNode As ContentTreeViewNode
    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 = "DIN 931" Then
            Exit For
        End If
    Next

    ' Create a member based on the first row of the family.
    Dim oError As MemberManagerErrorsEnum
    Dim strContentPartFileName As String
    Dim strErrorMessage As String
    strContentPartFileName = oFamily.CreateMember(1, oError, strErrorMessage)

    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)

 

 

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

Post to forums  

Autodesk Design & Make Report