spratek
19.08.2015, 13:19
Dobrý den,
pokouším se pro Inventor napsat utilitku ve vb.net, která by uměla do plechu se čtyřmi děrami pro šrouby
s konstantní roztečí 110 mm
, vložit čtyři šrouby (nejlépe jako pole) do těchto děr, pokud označím jen jednu hranu otvoru pro šroub viz. obr.Hranu vybírám pomocí Dim partEdge As Edge partEdge = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select a circular edge.")Vše funguje, akorát nevím jak udělat to, aby šrouby vždy zapadly do děr, to znamená, že ať vyberu jakoukoliv ze čtyř děr, šrouby si najdou zbývající tři a ne jako na obrázku, kdy je natvrdo dán směr vyplnění pole komponent.Pole komponent vkládám následovněoAssyDef.OccurrencePatterns.AddRectangularPattern(objCol, oWorkAxesX, True, -11, no_x_rect, oWorkAxesY, True, -11, no_y_rect)Celý kód je pod obrázkem.R.M..Imports SystemImports System.Collections.GenericImports System.LinqImports System.TextImports InventorImports System.Runtime.InteropServicesPublic Class osy Public Sub Main() 'vloží šroub a připojí ho k označené díře Dim m_inventorApp As Inventor.Application = Nothing m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Dim asmDoc As AssemblyDocument asmDoc = m_inventorApp.ActiveDocument ' Have the user select a circular edge. Dim partEdge As Edge partEdge = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select a circular edge.") If partEdge Is Nothing Then Exit Sub End If ' Place the bolt into the assembly. Dim boltOcc As ComponentOccurrence boltOcc = asmDoc.ComponentDefinition.Occurrences.Add("e:\******\Atributy_HV_M20-105_(68-72).ipt", m_inventorApp.TransientGeometry.CreateMatrix) ' Get the part document of the bolt. Dim boltDoc As PartDocument boltDoc = boltOcc.Definition.Document ' Query the attributes in the part for the attribute set named "InsertEdge". Dim attribSets As AttributeSetsEnumerator attribSets = boltDoc.AttributeManager.FindAttributeSets("InsertEdge") 'attribSets = boltDoc.AttributeManager.FindAttributeSets("*") ' Assume success and get the parent from first item returned, ' which will be the edge. Dim boltEdge As Edge boltEdge = attribSets.Item(1).Parent.Parent ' Create a proxy for the edge. Dim boltEdgeProxy As EdgeProxy boltOcc.CreateGeometryProxy(boltEdge, boltEdgeProxy) ' Create a constraint. asmDoc.ComponentDefinition.Constraints.AddInsertConstraint(partEdge, boltEdgeProxy, True, 0) Dim oAssyDoc As AssemblyDocument oAssyDoc = m_inventorApp.ActiveDocument Dim oAssyDef As AssemblyComponentDefinition oAssyDef = oAssyDoc.ComponentDefinition If oAssyDef.Occurrences.Count < 2 Then MsgBox("Assembly must have 2 components") Exit Sub End If 'Dim Occurrence As ComponentOccurrenceProxy Dim Occurrence As ComponentOccurrence Occurrence = partEdge.Parent.Parent Dim XAxis As WorkAxis Dim YAxis As WorkAxis Dim Zaxis As WorkAxis ' With oAssyDef With Occurrence.Definition XAxis = .WorkAxes.Item(1) YAxis = .WorkAxes.Item(2) Zaxis = .WorkAxes.Item(3) End With Dim oWorkAxesX As WorkAxisProxy Occurrence.CreateGeometryProxy(XAxis, oWorkAxesX) Dim oWorkAxesY As WorkAxisProxy Occurrence.CreateGeometryProxy(YAxis, oWorkAxesY) 'Create an object collection Dim objCol As ObjectCollection objCol = m_inventorApp.TransientObjects.CreateObjectCollection() 'add the desired occurrence to be patterned objCol.Add(oAssyDef.Occurrences.ItemByName(boltOcc.Name)) 'set the number of patterns in the x direction Dim no_x_rect As Integer no_x_rect = 2 'set the number of patterns in the y direction Dim no_y_rect As Integer no_y_rect = 2 'Creating a Rectangular pattern oAssyDef.OccurrencePatterns.AddRectangularPattern(objCol, oWorkAxesX, True, -11, no_x_rect, oWorkAxesY, True, -11, no_y_rect) End SubEnd Class
spratek2015-08-19 15:35:05
pokouším se pro Inventor napsat utilitku ve vb.net, která by uměla do plechu se čtyřmi děrami pro šrouby
s konstantní roztečí 110 mm
, vložit čtyři šrouby (nejlépe jako pole) do těchto děr, pokud označím jen jednu hranu otvoru pro šroub viz. obr.Hranu vybírám pomocí Dim partEdge As Edge partEdge = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select a circular edge.")Vše funguje, akorát nevím jak udělat to, aby šrouby vždy zapadly do děr, to znamená, že ať vyberu jakoukoliv ze čtyř děr, šrouby si najdou zbývající tři a ne jako na obrázku, kdy je natvrdo dán směr vyplnění pole komponent.Pole komponent vkládám následovněoAssyDef.OccurrencePatterns.AddRectangularPattern(objCol, oWorkAxesX, True, -11, no_x_rect, oWorkAxesY, True, -11, no_y_rect)Celý kód je pod obrázkem.R.M..Imports SystemImports System.Collections.GenericImports System.LinqImports System.TextImports InventorImports System.Runtime.InteropServicesPublic Class osy Public Sub Main() 'vloží šroub a připojí ho k označené díře Dim m_inventorApp As Inventor.Application = Nothing m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Dim asmDoc As AssemblyDocument asmDoc = m_inventorApp.ActiveDocument ' Have the user select a circular edge. Dim partEdge As Edge partEdge = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select a circular edge.") If partEdge Is Nothing Then Exit Sub End If ' Place the bolt into the assembly. Dim boltOcc As ComponentOccurrence boltOcc = asmDoc.ComponentDefinition.Occurrences.Add("e:\******\Atributy_HV_M20-105_(68-72).ipt", m_inventorApp.TransientGeometry.CreateMatrix) ' Get the part document of the bolt. Dim boltDoc As PartDocument boltDoc = boltOcc.Definition.Document ' Query the attributes in the part for the attribute set named "InsertEdge". Dim attribSets As AttributeSetsEnumerator attribSets = boltDoc.AttributeManager.FindAttributeSets("InsertEdge") 'attribSets = boltDoc.AttributeManager.FindAttributeSets("*") ' Assume success and get the parent from first item returned, ' which will be the edge. Dim boltEdge As Edge boltEdge = attribSets.Item(1).Parent.Parent ' Create a proxy for the edge. Dim boltEdgeProxy As EdgeProxy boltOcc.CreateGeometryProxy(boltEdge, boltEdgeProxy) ' Create a constraint. asmDoc.ComponentDefinition.Constraints.AddInsertConstraint(partEdge, boltEdgeProxy, True, 0) Dim oAssyDoc As AssemblyDocument oAssyDoc = m_inventorApp.ActiveDocument Dim oAssyDef As AssemblyComponentDefinition oAssyDef = oAssyDoc.ComponentDefinition If oAssyDef.Occurrences.Count < 2 Then MsgBox("Assembly must have 2 components") Exit Sub End If 'Dim Occurrence As ComponentOccurrenceProxy Dim Occurrence As ComponentOccurrence Occurrence = partEdge.Parent.Parent Dim XAxis As WorkAxis Dim YAxis As WorkAxis Dim Zaxis As WorkAxis ' With oAssyDef With Occurrence.Definition XAxis = .WorkAxes.Item(1) YAxis = .WorkAxes.Item(2) Zaxis = .WorkAxes.Item(3) End With Dim oWorkAxesX As WorkAxisProxy Occurrence.CreateGeometryProxy(XAxis, oWorkAxesX) Dim oWorkAxesY As WorkAxisProxy Occurrence.CreateGeometryProxy(YAxis, oWorkAxesY) 'Create an object collection Dim objCol As ObjectCollection objCol = m_inventorApp.TransientObjects.CreateObjectCollection() 'add the desired occurrence to be patterned objCol.Add(oAssyDef.Occurrences.ItemByName(boltOcc.Name)) 'set the number of patterns in the x direction Dim no_x_rect As Integer no_x_rect = 2 'set the number of patterns in the y direction Dim no_y_rect As Integer no_y_rect = 2 'Creating a Rectangular pattern oAssyDef.OccurrencePatterns.AddRectangularPattern(objCol, oWorkAxesX, True, -11, no_x_rect, oWorkAxesY, True, -11, no_y_rect) End SubEnd Class
spratek2015-08-19 15:35:05