Inventorの部屋

iLogicによる設計の自動化などで作業効率化を図ります。

iLogic - 三面図一括配置

風船にコメントをつける

型式やメーカーなどの部品表の情報を風船の横に配置します。

  • 1.複数の設計ファイルで同じ自動化ルールを実行できるように外部ルールで作成します。
    iLogicブラウザの外部ルールで追加したフォルダを右クリックして[新しい外部ルールを作成]をクリック。
    ilogic - 風船にコメントをつける
  • 2.任意の名前を入力して[保存]をクリック。
    ilogic - 風船にコメントをつける
  • 3.下記コードを入力して[保存]をクリック。
    
    Sub Main()
        Dim oDrawDoc As DrawingDocument
        If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
            MessageBox.Show("このルールは図面ドキュメントでのみ実行できます。", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If
        oDrawDoc = ThisApplication.ActiveDocument
    
        Dim oSelected As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "バルーンを選択してください")
        If oSelected Is Nothing Then Return
    
        Dim oBalloon As Balloon
        If TypeOf oSelected Is Balloon Then
            oBalloon = oSelected
            ProcessBalloon(oBalloon, oDrawDoc)
        Else
            MessageBox.Show("選択されたオブジェクトはバルーンではありません。", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub
    
    Sub ProcessBalloon(ByVal oBalloon As Balloon, ByVal oDrawDoc As DrawingDocument)
        Dim oBOMRow As DrawingBOMRow
        Try
            oBOMRow = oBalloon.BalloonValueSets.Item(1).ReferencedRow
        Catch
            MessageBox.Show("バルーンがBOMを参照していません。", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End Try
        If oBOMRow Is Nothing Then Return
    
        Dim oBOM As DrawingBOM = oBOMRow.Parent
        Dim sPartNumber As String = ""
        Dim sQuantity As String = ""
        Dim sMaterial As String = ""
        Dim oColumn As DrawingBOMColumn
        
        For Each oColumn In oBOM.DrawingBOMColumns
            Dim sCellText As String = oBOMRow.Item(oColumn).Value
            
            ' 列タイトルを格納
            Select Case oColumn.Title.Trim()
                Case "図番/型式"
                    sPartNumber = sCellText
                Case "個数"
                    sQuantity = sCellText
                Case "材質/メーカー"
                    sMaterial = sCellText
            End Select
        Next
    
        If String.IsNullOrEmpty(sPartNumber) And String.IsNullOrEmpty(sQuantity) And String.IsNullOrEmpty(sMaterial) Then
            MessageBox.Show("「図番/型式」、「個数」、「材質/メーカー」のいずれの列も見つかりませんでした。", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If
    
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
        
        ' テキストのオフセット量を調整 (cm単位)
        Dim dOffsetX As Double = 0.5
        Dim dOffsetY As Double = 0.3
    
        Dim oNewPosition As Point2d = oTG.CreatePoint2d(oBalloon.Position.X + dOffsetX, oBalloon.Position.Y + dOffsetY)
    
        Dim sFirstLine As String = ""
        If Not String.IsNullOrEmpty(sPartNumber) Then
            sFirstLine = $"{sPartNumber}"
        End If
    
        Dim sSecondLine As String = ""
        If Not String.IsNullOrEmpty(sMaterial) Then
            sSecondLine = $"({sMaterial}、"
        End If
        If Not String.IsNullOrEmpty(sQuantity) Then
            If sSecondLine <> "" Then sSecondLine &= " "
            sSecondLine &= $"{sQuantity}個)"
        End If
    
        Dim notePlaced As Boolean = False
        ' 行間の距離を調整 (単位: cm)
        Dim verticalSpacing As Double = 0.35 
    
        If sFirstLine <> "" Then
            oSheet.DrawingNotes.GeneralNotes.AddFitted(oNewPosition, sFirstLine)
            notePlaced = True
        End If
    
        If sSecondLine <> "" Then
            Dim secondLinePosition As Point2d
            If notePlaced Then
                secondLinePosition = oTG.CreatePoint2d(oNewPosition.X, oNewPosition.Y - verticalSpacing)
            Else
                secondLinePosition = oNewPosition
            End If
            oSheet.DrawingNotes.GeneralNotes.AddFitted(secondLinePosition, sSecondLine)
        End If
    End Sub
    

    環境にあわせて下記を設定してください。
    ・「列タイトルを格納」で部品表の列タイトルを設定
    ・「テキストのオフセット量を調整 (cm単位)」でテキストの位置を調整
    ・「行間の距離を調整 (単位: cm)」でテキストの行間を調整

    作成した外部ルールをリボンやショートカットに登録しておくと便利です。

  • 4. 作成したルールを右クリックして[ルールを実行]し、風船をクリックすると風船の横にコメントが作成されます。
    ilogic - 風船にコメントをつける
3D CAD用パソコン比較