[Inventor] Inventor ILogic 操作教程汇总

JUMU实名认证 发表于 2019-02-28 16:52 | 显示全部楼层 | 复制链接分享      上一主题  翻页  下一主题
遍历部件生成bom

Dim filename() As String
Dim num() As Integer
Dim count As Integer
Sub aa()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
ReDim filename(0) As String
ReDim num(0) As Integer
count = 0
Dim oCc As ComponentOccurrence
For Each oCc In oDoc.ComponentDefinition.Occurrences
    Call bb(oCc)
Next
End Sub
Private Sub bb(ByVal oInocc As ComponentOccurrence)
Dim oCcocc As ComponentOccurrence
If oInocc.SubOccurrences.count = 0 Then
    For i = 0 To count
        If oInocc.Definition.Document.DisplayName = filename(i) Then
            num(i) = num(i) + 1
            Exit Sub
        End If
    Next i
    count = count + 1
    ReDim Preserve filename(count)
    ReDim Preserve num(count)
    filename(count) = oInocc.Definition.Document.DisplayName
    num(count) = num(count) + 1
Else
    For Each oCcocc In oInocc.SubOccurrences
        Call bb(oCcocc)
    Next
End If
End Sub

精彩评论6

 楼主| JUMU实名认证 发表于 2019-02-28 16:53 | 显示全部楼层 | 复制链接分享
插入图框

Public Sub InsertCustomBorderOnSheet()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
   
    ' Obtain a reference to the desired border definition.
    Dim oBorderDef As BorderDefinition
    Set oBorderDef = oDrawDoc.BorderDefinitions.Item("A3/A4")
    MsgBox oBorderDef.Name
   
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
   
    ' Check to see if the sheet already has a border and delete it if it does.
    If Not oSheet.Border Is Nothing Then
        oSheet.Border.Delete
    End If
   
    ' This border definition contains one prompted string input.  An array
    ' must be input that contains the strings for the prompted strings.
    Dim sPromptStrings(1 To 1) As String
    sPromptStrings(1) = "This is the input for the prompted text."
   
    ' Add an instance of the border definition to the sheet.
    Dim oBorder As Border
    Set oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings)
End Sub
 楼主| JUMU实名认证 发表于 2019-02-28 16:53 | 显示全部楼层 | 复制链接分享
插入新零件
Public Sub AddOccurrence()
    ' Set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    ' Set a reference to the transient geometry object.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    Set oMatrix = oTG.CreateMatrix
    ' Set the rotation of the matrix for a 45 degree rotation about the Z axis.
    Call oMatrix.SetToRotation(3.14159265358979 / 4, _
                            oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))
    ' Set the translation portion of the matrix so the part will be positioned
    ' at (3,2,1).
    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))
    ' Add the occurrence.
    Dim oOcc As ComponentOccurrence
    Set oOcc = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)
End Sub
 楼主| JUMU实名认证 发表于 2019-02-28 16:54 | 显示全部楼层 | 复制链接分享
创建点样条曲线等

Public Sub SketchCurves()
    ' Create a new part.
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                  ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
                  
    ' Create a 2D sketch on the X-Y plane.
    Dim sketch1 As PlanarSketch
    Set sketch1 = partDef.Sketches.Add(partDef.WorkPlanes.Item(3))
   
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
   
    ' Create a spline based on control points.
    Dim pnts As ObjectCollection
    Set pnts = ThisApplication.TransientObjects.CreateObjectCollection
    Call pnts.Add(tg.CreatePoint2d(2, 0))
    Call pnts.Add(tg.CreatePoint2d(4, 1))
    Call pnts.Add(tg.CreatePoint2d(4, 2))
    Call pnts.Add(tg.CreatePoint2d(6, 3))
    Call pnts.Add(tg.CreatePoint2d(8, 1))
    Dim controlPointSpline As SketchControlPointSpline
    Set controlPointSpline = sketch1.SketchControlPointSplines.Add(pnts)
   
    ' Create a 2D sketch on the Y-Z plane.
    Dim sketch2 As PlanarSketch
    Set sketch2 = partDef.Sketches.Add(partDef.WorkPlanes.Item(1))
   
    ' Create a spline based on an equation.
    Dim equationCurve As SketchEquationCurve
    Set equationCurve = sketch2.SketchEquationCurves.Add(kParametric, kCartesian, _
                                ".001*t * cos(t)", ".001*t * sin(t)", 0, 360 * 3)
                                
    ' Create a 3D sketch.
    Dim sketch3 As sketch3D
    Set sketch3 = partDef.Sketches3D.Add
   
    ' Create a 3D spline based on control points.
    Set pnts = ThisApplication.TransientObjects.CreateObjectCollection
    Call pnts.Add(tg.CreatePoint(10, 0, 0))
    Call pnts.Add(tg.CreatePoint(12, 1, 3))
    Call pnts.Add(tg.CreatePoint(12, 2, -5))
    Call pnts.Add(tg.CreatePoint(14, 3, 2))
    Call pnts.Add(tg.CreatePoint(16, 1, -3))
    Dim controlPointSpline2 As SketchControlPointSpline3D
    Set controlPointSpline2 = sketch3.SketchControlPointSplines3D.Add(pnts)
   
    ' Create a 3D spline based on an equation.
    Dim equationCurve2 As SketchEquationCurve3D
    Set equationCurve2 = sketch3.SketchEquationCurves3D.Add(kCartesian, _
                            ".001*t * cos(t) + 8", ".001*t * sin(t)", "0.002*t", 0, 360 * 3)
                           
    ThisApplication.ActiveView.Fit
   
    ' Extrude the 2d curves.
    Dim prof As Profile
    Set prof = sketch1.Profiles.AddForSurface(controlPointSpline)
    Dim extrudeDef As ExtrudeDefinition
    Set extrudeDef = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(prof, kSurfaceOperation)
    Call extrudeDef.SetDistanceExtent(6, kSymmetricExtentDirection)
    Dim extrude1 As ExtrudeFeature
    Set extrude1 = partDef.Features.ExtrudeFeatures.Add(extrudeDef)
   
    ' Change the work surface to not be transparent.
    Dim surf As WorkSurface
    Set surf = extrude1.SurfaceBodies.Item(1).Parent
    surf.Translucent = False
   
    Set prof = sketch2.Profiles.AddForSurface(equationCurve)
    Set extrudeDef = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(prof, kSurfaceOperation)
    Call extrudeDef.SetDistanceExtent(9, kPositiveExtentDirection)
    Dim extrude2 As ExtrudeFeature
    Set extrude2 = partDef.Features.ExtrudeFeatures.Add(extrudeDef)
   
    ' Create a new sketch and an intersection curve.
    Dim interSketch As sketch3D
    Set interSketch = partDef.Sketches3D.Add
   
    Call interSketch.IntersectionCurves.Add(extrude1.SurfaceBodies.Item(1), extrude2.SurfaceBodies.Item(1))
End Sub

 楼主| JUMU实名认证 发表于 2019-02-28 16:55 | 显示全部楼层 | 复制链接分享
拉伸特征

Sub 创建模型实例()
    ' 得到零件组成参照.
    Dim oPartCompDef As PartComponentDefinition
    Set oPartCompDef = ThisApplication.ActiveDocument.ComponentDefinition
   
    ' 设定新草图面.
    Dim oSketch As Sketch
    Set oSketch = oPartCompDef.Sketches.Add(oPartCompDef.WorkPlanes.Item(3))
   
    '创建矩形草图.
    With ThisApplication.TransientGeometry
        Call oSketch.SketchLines.AddAsTwoPointRectangle _
             (.CreatePoint2d(0, 0), .CreatePoint2d(5, 3))
    End With
   
    ' 将草图定义为轮廓.
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid
   
    ' 创建拉伸特征.
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oPartCompDef.Features.ExtrudeFeatures.AddByDistanceExtent _
                   (oProfile, 2, kPositiveExtentDirection, kJoinOperation)
    Debug.Print "面: " & oExtrude.EndFaces.Count
   
    ' 创建在前边做好的拉伸终结面上的矩形草图,定义为轮廓,并拉伸-切割.
    Set oSketch = oPartCompDef.Sketches.AddWithOrientation _
                  (oExtrude.EndFaces.Item(1), _
                   oPartCompDef.WorkAxes.Item(1), _
                   True, True, oPartCompDef.WorkPoints.Item(1), False)
    With ThisApplication.TransientGeometry
        Call oSketch.SketchLines.AddAsTwoPointRectangle _
             (.CreatePoint2d(1, 1), .CreatePoint2d(4, 2))
    End With
    Set oProfile = oSketch.Profiles.AddForSolid
    Set oExtrude = oPartCompDef.Features.ExtrudeFeatures.AddByDistanceExtent _
                   (oProfile, 0.75, kNegativeExtentDirection, kCutOperation)
End Sub


 楼主| JUMU实名认证 发表于 2019-02-28 16:56 | 显示全部楼层 | 复制链接分享
'删除多余的图框
Public Sub getBorderNames()
Dim oDrawDoc As DrawingDocument
'Ensure the active document is a drawing
If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oBorders As BorderDefinitions
Dim oBorderDef As BorderDefinition
Set oBorders = oDrawDoc.BorderDefinitions
For Each oBorderDef In oBorders
Debug.Print oBorderDef.Name
On Error Resume Next
oBorderDef.Delete
Next oBorderDef
End If
End Sub
 楼主| JUMU实名认证 发表于 2019-02-28 16:56 | 显示全部楼层 | 复制链接分享
添加插入约束

Public Sub InsertConstraint()
    ' Set a reference to the assembly component definintion.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
   
    ' Set a reference to the select set.
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
   
    ' Validate the correct data is in the select set.
    If oSelectSet.Count  2 Then
        MsgBox "You must select the two circular edges for the insert."
        Exit Sub
    End If

    If Not TypeOf oSelectSet.Item(1) Is Edge Or Not TypeOf oSelectSet.Item(2) Is Edge Then
        MsgBox "You must select the two circular edges for the insert."
        Exit Sub
    End If

    ' Get the two edges from the select set.
    Dim oEdge1 As Edge
    Dim oEdge2 As Edge
    Set oEdge1 = oSelectSet.Item(1)
    Set oEdge2 = oSelectSet.Item(2)

    ' Create the insert constraint between the parts.
    Dim oInsert As InsertConstraint
    Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge2, True, 0)
End Sub

  距米网  

找到您想要的设计

工程师、学生在线交流学习平台
关注我们

手机版- 距米网 |苏公网安备32041102000587号

© 2017-2024 常州居居米智能技术有限公司 苏ICP备18040927号-1