NX Journal 図面サイズを取得
2019/12/04 categories:NX Journal| tags:NX Journal|VB|Python|
NXジャーナルで図面のサイズを取得するプログラムを作成しました。
Pythonコード
import NXOpen
def main():
theSession = NXOpen.Session.GetSession()
workPart = theSession.Parts.Work
lw = theSession.ListingWindow
lw.Open()
for sheet1 in workPart.DrawingSheets:
lw.WriteLine( sheet1.Name )
lw.WriteLine( sheetSize(sheet1) )
def sheetSize(sheet1):
size = [1189, 841, 594, 420, 297, 210, 148, 105, 74, 52, 37, 26, 18]
if sheet1.Height > sheet1.Length:
return "A" + str( size.index(sheet1.Height) )
else:
return "A" + str( size.index(sheet1.Length) )
if __name__ == '__main__':
main()
VBコード
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open
Dim dwgs As Drawings.DrawingSheetCollection = workPart.DrawingSheets
For Each sheet As Drawings.DrawingSheet In dwgs
lw.WriteLine( getSize(sheet) )
Next
End Sub
Function getSize(ByVal drawingSheet1 As Drawings.DrawingSheet)
Dim height As Integer
Dim length As Integer
Dim i As Long
Dim A() As Integer = {1189, 841, 594, 420, 297, 210, 148, 105, 74, 52, 37, 26, 18}
height = drawingSheet1.Height
length = drawingSheet1.Length
For i = 0 to UBOUND(A)
if A(i) = height then
if i = 0 then
getSize = "A" & i
exit for
else
if A(i-1) = length then
getSize = "A" & (i-1)
exit for
elseif A(i+1) = length then
getSize = "A" & i
exit for
end if
end if
end if
Next
End Function
End Module