- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
this is the code for insert Bolt. But it's work for 1 bolt
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Inventor
Imports System.Runtime.InteropServices
Dim m_inventorApp As Inventor.Application = Nothing
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Dim oAssyDoc As AssemblyDocument
oAssyDoc = m_inventorApp.ActiveDocument
Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oAssyDoc.ComponentDefinition
' Select a circular edge on the component to be inserted
Dim partEdge As Edge
partEdge = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select a circular edge.")
If partEdge Is Nothing Then
Exit Sub
End If
' Get the occurrence of the component that contains the selected edge
Dim Occurrence As ComponentOccurrence
Occurrence = partEdge.Parent.Parent
' Select all the occurrences related to the component that contains the selected edge
Dim tr As TransientObjects
tr = m_inventorApp.TransientObjects
Dim coll As ObjectCollection
coll = tr.CreateObjectCollection()
Dim ac As AssemblyConstraint
For Each ac In Occurrence.Constraints
coll.Add(ac.OccurrenceOne)
coll.Add(ac.OccurrenceTwo)
Next
Dim occ As ComponentOccurrence
For Each occ In coll
oAssyDoc.SelectSet.Select(occ)
Next
' Select a hole on the steel plate to insert the component into
Dim oObject As Object
oObject = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select a hole on the steel plate to insert the component into")
If oObject Is Nothing Then
Exit Sub
End If
' Insert the component into the hole on the steel plate
Dim oInsert As InsertConstraint
oInsert = oAssyDef.Constraints.AddInsertConstraint(oObject, partEdge, True, 0)
' Select all the occurrences related to the inserted component
Dim newOccurrence As ComponentOccurrence
newOccurrence = oInsert.OccurrenceTwo
coll.Clear()
For Each ac In newOccurrence.Constraints
coll.Add(ac.OccurrenceOne)
coll.Add(ac.OccurrenceTwo)
Next
For Each occ In coll
oAssyDoc.SelectSet.Select(occ)
Next
' Select all the occurrences related to the copied and pasted component
Dim pasteOccurrence As ComponentOccurrence
pasteOccurrence = oAssyDef.Occurrences.Item(oAssyDef.Occurrences.Count)
coll.Clear()
For Each ac In pasteOccurrence.Constraints
coll.Add(ac.OccurrenceOne)
coll.Add(ac.OccurrenceTwo)
Next
For Each occ In coll
oAssyDoc.SelectSet.Select(occ)
Next
InventorVb.DocumentUpdate()
Solved! Go to Solution.