NX Journal 図面サイズを取得

Share on:

NXジャーナルで図面のサイズを取得するプログラムを作成しました。

Pythonコード

 1import NXOpen
 2
 3def main():
 4    theSession  = NXOpen.Session.GetSession()
 5    workPart = theSession.Parts.Work
 6    lw = theSession.ListingWindow
 7    lw.Open()
 8    
 9    for sheet1 in workPart.DrawingSheets:
10        lw.WriteLine( sheet1.Name )
11        lw.WriteLine( sheetSize(sheet1) )
12
13def sheetSize(sheet1):
14    size = [1189, 841, 594, 420, 297, 210, 148, 105, 74, 52, 37, 26, 18]
15
16    if sheet1.Height > sheet1.Length:
17        return "A" + str( size.index(sheet1.Height) )
18    else:
19        return "A" + str( size.index(sheet1.Length) )
20
21if __name__ == '__main__':
22    main()

VBコード

 1Imports System
 2Imports NXOpen
 3
 4Module NXJournal
 5    Sub Main (ByVal args() As String) 
 6        Dim theSession As Session = Session.GetSession()
 7        Dim workPart As Part = theSession.Parts.Work
 8
 9        Dim lw As ListingWindow = theSession.ListingWindow
10        lw.Open
11
12    Dim dwgs As Drawings.DrawingSheetCollection = workPart.DrawingSheets
13    For Each sheet As Drawings.DrawingSheet In dwgs
14            lw.WriteLine( getSize(sheet) )
15        Next
16
17    End Sub
18
19    Function getSize(ByVal drawingSheet1 As Drawings.DrawingSheet)
20        Dim height As Integer
21        Dim length As Integer
22        Dim i As Long
23
24        Dim A() As Integer = {1189, 841, 594, 420, 297, 210, 148, 105, 74, 52, 37, 26, 18}
25
26        height = drawingSheet1.Height
27        length = drawingSheet1.Length
28
29        For i = 0 to UBOUND(A)
30        if A(i) = height then
31        if i = 0 then
32            getSize = "A" & i
33            exit for
34        else
35            if A(i-1) = length then
36            getSize = "A" & (i-1)
37            exit for
38            elseif A(i+1) = length then
39            getSize = "A" & i
40            exit for
41            end if
42        end if
43        end if
44        Next
45    End Function
46
47End Module

関連記事