查看: 523|回复: 3
收起左侧

[AVEVA MARINE] TRIBON&AM SCH解析 生成零件属性编辑器,原码

[复制链接]
发表于 2023-8-2 11:24 | 显示全部楼层 |阅读模式 来自: 中国上海
本帖最后由 笑遥佛 于 2023-8-2 11:31 编辑

TRIBON没有零件属性编辑器,可以利用SCH做一个属性编辑器,选择零件,GET到SCH,然后跳出零件属性,保存里后台自动激活板架更新零件。
由于SCH的装配信息是一个序号号符串,无法判断是那个组立,所以我先得到装配列表,然后利用字典就可以选择变更装配组立了。
板缝属性
image.png --> 型材属性
image.png -->
开孔属性
image.png -->


image.png -->
原码
  1. # -*- coding: cp936 -*-
复制代码
代码里面可能有多余的import ,不用删掉就可以了。
1690946821665.png -->


回复

使用道具 举报

龙船学院
 楼主| 发表于 2023-8-2 11:31 | 显示全部楼层 来自: 中国上海
  1. # -*- coding: cp936 -*-
  2. #
  3. #        肖恢满 VX:56095181
  4. #
  5. ####################################################################################################################
  6. #                                        All Module File
  7. ####################################################################################################################
  8. from wxPython.wx import *
  9. from wxPython.grid import *
  10. from wxPython.lib.anchors import LayoutAnchors
  11. from win32api import *
  12. import wx.lib.mixins.listctrl
  13. import kcs_hullpan
  14. import kcs_ui
  15. import kcs_util
  16. import kcs_dex
  17. import KcsPanelSchema
  18. import time
  19. import xyf
  20. import string
  21. import os
  22. import sys
  23. import win32api
  24. import kcs_hull
  25. import kcs_draft
  26. import CommonSample
  27. import KcsModel
  28. import odbc
  29. import KcsCaptureRegion2D
  30. import KcsLinetype
  31. import KcsPoint2D
  32. import getpass
  33. import KcsContour2D
  34. import KcsColour
  35. import KcsLinetype
  36. import KcsRline2D
  37. import re
  38. import copy
  39. import KcsRectangle2D
  40. import KcsText
  41. import KcsTransformation2D
  42. import KcsVector2D
  43. import KcsVector3D
  44. import math
  45. import KcsPolygon2D
  46. import KcsPrintOptions
  47. import KcsCursorType
  48. import KcsStat_point2D_req
  49. import kcs_struct
  50. import kcs_db
  51. import kcs_modelstruct
  52. import KcsPoint3D
  53. import kcs_assembly

  54. from KcsStringlist import Stringlist
  55. from KcsObject import Object
  56. from KcsObjectCriteria import ObjectCriteria
  57. from KcsDateTime import DateTime

  58. kcs_draft.highlight_off(0)
  59. tbenvtable = xyf.get_env()
  60. sch_path = kcs_util.TB_environment_get('SB_SHIPSCH')
  61. proj_str = kcs_util.TB_environment_get("SB_PROJ_HULL")
  62. bin_path = kcs_util.TB_environment_get('SB_SYSTEM')   


  63. block = kcs_util.TB_environment_get('HH_BLOCK_NO')
  64. blocks = [block]
  65. try:
  66.     rblock = kcs_util.TB_environment_get('HH_BLOCK_NO_MIRROR')
  67.     if rblock != block:
  68.         blocks.append(rblock)
  69. except:
  70.     pass
  71.    
  72. def ListSubAssemblies(resultList, offset, name):
  73.     try:
  74.         subAssemblies = kcs_assembly.assembly_sub_get(name)
  75.         for assembly in subAssemblies:
  76.             resultList.append((0, assembly[0], assembly[1], offset))
  77.             ListSubAssemblies(resultList, offset + 1, assembly[1])
  78.     except:
  79.         pass
  80.         
  81. TreeList = []
  82. for block_str in blocks:   
  83.     block_ass_str = kcs_assembly.assembly_internal_name_get('-' + block_str)
  84.     rootass = kcs_assembly.assembly_sub_get(block_ass_str)
  85.     for assembly in rootass:
  86.         TreeList.append((0, assembly[0], assembly[1], 0))
  87.         ListSubAssemblies(TreeList, 1, assembly[1])
  88. TreeList.sort()

  89. TreeDic = {}
  90. TreeDic1 = {}
  91. TreeLis = []
  92. for a in TreeList:
  93.     TreeDic[a[2]] = a[1]
  94.     TreeDic1[a[1]] = a[2]
  95.     TreeLis.append(a[1])


  96. class MyFrame(wxFrame):
  97.     __module__ = __name__

  98.     def __init__(self, parent, ID, title):
  99.         wxFrame.__init__(self, parent, ID, title, wxPoint(GetSystemMetrics(0) - 553, 130),
  100.                          wxSize(520, 725), style=wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN)
  101.         # global text_plan_name, text_patr_typ, text_old_sch, bt_select_model, ResuwxGrid1, text_new_sch, bt_modify_model, text_patr_id
  102.         # global bt_paste_model, bt_copy_model, text_tree_sch

  103.         self.panel = wxPanel(size=wxSize(510, 725), parent=self, id=-1, name='panel1',
  104.                              style=wxTAB_TRAVERSAL | wxCLIP_CHILDREN, pos=wxPoint(0, 0))
  105.         self.panel.SetAutoLayout(True)

  106.         wxStaticText(self.panel, -1, '板架名:', wxPoint(10, 10))  # 放置文字
  107.         self.text_plan_name = wxTextCtrl(self.panel, -1, "", wxPoint(60, 7), wxSize(150, -1))

  108.         wxStaticText(self.panel, -1, '零件类型:', wxPoint(220, 10))  # 放置文字
  109.         self.text_patr_typ = wxTextCtrl(self.panel, -1, "", wxPoint(280, 7), wxSize(70, -1))

  110.         wxStaticText(self.panel, -1, 'ID:', wxPoint(360, 10))  # 放置文字
  111.         self.text_patr_id = wxTextCtrl(self.panel, -1, "", wxPoint(390, 7), wxSize(20, -1))
  112.         self.text_patr_id.Enable(False)
  113.         
  114.         self.sb1 = wxStaticBox(self.panel, -1, "原SCH语句", wxPoint(10, 35), wxSize(490, 100))
  115.         self.sb1.SetConstraints(LayoutAnchors(self.sb1, True, True, True, False))
  116.         
  117.         self.text_old_sch = wxTextCtrl(self.sb1, -1, "", wxPoint(5, 15), wxSize(480, 80), style=wxTE_MULTILINE)
  118.         self.text_old_sch.SetConstraints(LayoutAnchors(self.text_old_sch, True, True, True, False))      ##布局限制
  119.         
  120.         self.sb2 = wxStaticBox(self.panel, -1, "新SCH语句", wxPoint(10, 550), wxSize(490, 100))
  121.         self.sb2.SetConstraints(LayoutAnchors(self.sb2, True, True, True, False))
  122.         
  123.         self.text_new_sch = wxTextCtrl(self.sb2, -1, "", wxPoint(5, 15), wxSize(480, 80), style=wxTE_MULTILINE)
  124.         self.text_new_sch.SetConstraints(LayoutAnchors(self.text_new_sch, True, True, True, False))      ##布局限制
  125.         
  126.         self.bt_select_model = wxButton(self.panel, -1, "选择零件", wxPoint(430, 6), wxSize(70, -1))
  127.         EVT_BUTTON(self, self.bt_select_model.GetId(), self.Evt_select_model)
  128.         self.bt_select_model.SetBackgroundColour(wxCYAN)
  129.         
  130.         
  131.         self.bt_modify_model = wxButton(self.panel, -1, "保存编辑SCH修改", wxPoint(10, 655), wxSize(485, -1))
  132.         EVT_BUTTON(self, self.bt_modify_model.GetId(), self.Evt_modify_model)
  133.         self.bt_modify_model.SetConstraints(LayoutAnchors(self.bt_modify_model, True, True, True, False))
  134.         self.bt_modify_model.SetBackgroundColour(wxCYAN)
  135.         
  136.         ########################################## 绘制列表 ##################################################################
  137.         self.GR = wxGrid(self.panel, -1,  wxPoint(10, 145), wxSize(480, 395))
  138.         self.GR.SetConstraints(LayoutAnchors(self.GR, True, True, True, False))      ##布局限制
  139.         self.GR.CreateGrid(0, 3)
  140.         self.GR.SetColLabelValue(0, "说明")
  141.         self.GR.SetColLabelValue(1, "参数")
  142.         self.GR.SetColLabelValue(2, "值")
  143.         self.GR.SetRowLabelSize(0)
  144.         self.GR.SetColLabelSize(20)
  145.         self.GR.SetColSize(0, 80)
  146.         self.GR.SetColSize(1, 80)
  147.         self.GR.SetColSize(2, 290)
  148.         self.select_model()
  149.         EVT_GRID_CELL_CHANGE(self, self.Evt_grid_edit)
  150.         
  151.         EVT_CLOSE(self, self.OnClose)
  152.         
  153.     ##关闭窗口
  154.     def OnClose(self, event):
  155.         kcs_draft.highlight_off(0)
  156.         self.Destroy()
  157.         
  158.     def Evt_select_model(self, event):
  159.         self.select_model()
  160.         self.Show(False)
  161.         self.Show(True)
  162.             
  163.         

  164.     def Evt_modify_model(self, event):
  165.         try:
  166.             kcs_hull.pan_modify(self.text_plan_name.GetValue(), 2)
  167.             kcs_hullpan.stmt_exec_single(int(self.text_patr_id.GetValue()), self.text_new_sch.GetValue(),
  168.                                          self.text_plan_name.GetValue())
  169.             kcs_hull.pan_store()
  170.             kcs_hull.pan_skip()
  171.             kcs_ui.message_noconfirm('笑遥佛HOOK:' + self.text_plan_name.GetValue() + '修改完成')
  172.         except:
  173.             kcs_ui.message_confirm('笑遥佛HOOK:' + self.text_plan_name.GetValue() + '修改失败')
  174.             kcs_hull.pan_skip()
  175.         
  176.         
  177.     def Evt_grid_edit(self, event):
  178.         self.xyf_new_sch()
  179.         try:
  180.             kcs_hull.pan_modify(self.text_plan_name.GetValue(), 2)
  181.             kcs_hullpan.stmt_exec_single(int(self.text_patr_id.GetValue()), self.text_new_sch.GetValue(),
  182.                                          self.text_plan_name.GetValue())
  183.             kcs_hull.pan_store()
  184.             kcs_hull.pan_skip()
  185.             kcs_ui.message_noconfirm('笑遥佛HOOK:' + self.text_plan_name.GetValue() + '修改完成')
  186.         except:
  187.             kcs_ui.message_confirm('笑遥佛HOOK:' + self.text_plan_name.GetValue() + '修改失败')
  188.             kcs_hull.pan_skip()
  189.         kcs_draft.dwg_repaint()
  190.         kcs_ui.app_window_refresh() #刷新屏幕        
  191.         
  192.     def select_model(self):
  193.         result = 1
  194.         while result:
  195.             kcs_draft.highlight_off(0)
  196.             coord = KcsPoint2D.Point2D()
  197.             model = KcsModel.Model()
  198.             try:
  199.                 res = kcs_ui.point2D_req('请选择模型', coord)
  200.                 if res[0] == kcs_util.ok():
  201.                     kcs_draft.highlight_off(0)
  202.                     handle = kcs_draft.component_identify(coord)                    
  203.                     model = kcs_draft.model_properties_get(handle, model)
  204.                     group_no = kcs_hullpan.group_get(model.Name, model.PartId)  # SCH组
  205.                     old_sch = kcs_hullpan.stmt_get(model.Name, group_no)
  206.                     self.text_plan_name.SetValue(model.Name)
  207.                     self.text_patr_typ.SetValue(model.PartType)
  208.                     self.text_patr_id.SetValue(str(group_no))
  209.                     self.text_old_sch.SetValue(old_sch)
  210.                     self.xyf_grid_list(old_sch)
  211.                     
  212.                     #显示型材的两个端点位置
  213.                     try:
  214.                         if model.PartType in ["stiffener","flange","pillar"]:
  215.                             if model.Type == "plane panel":  
  216.                                 tra_list = xyf.get_date("HULL.PAN('" + model.Name + "').TRA")[0]                           
  217.                                 temp_list = xyf.get_date("HULL.PAN('%s').%s(%d).END(1).POI" % (model.Name, model.PartType, abs(model.PartId) ))[0]
  218.                                 END1 = KcsPoint3D.Point3D(temp_list[0],temp_list[1],0)
  219.                                 old_matrix = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,1.0]
  220.                                 END1 = xyf.get_tra_cood(tra_list, END1, old_matrix)
  221.                                 
  222.                                 temp_list = xyf.get_date("HULL.PAN('%s').%s(%d).END(2).POI" % (model.Name, model.PartType, abs(model.PartId) ))[0]
  223.                                 END2 = KcsPoint3D.Point3D(temp_list[0],temp_list[1],0)
  224.                                 old_matrix = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,1.0]
  225.                                 END2 = xyf.get_tra_cood(tra_list, END2, old_matrix)
  226.                             elif model.Type == "curved panel":
  227.                                 temp_list = xyf.get_date("HULL.CPAN('%s').%s(%d).END(1).XYZ" % (model.Name, model.PartType, abs(PartId) % 1000 ))[0]
  228.                                 END1 = KcsPoint3D.Point3D(temp_list[0],temp_list[1],0)                           
  229.                                 temp_list = xyf.get_date("HULL.CPAN('%s').%s(%d).END(2).XYZ" % (model.Name, model.PartType, abs(PartId) % 1000 ))[0]
  230.                                 END2 = KcsPoint3D.Point3D(temp_list[0],temp_list[1],0)

  231.                             if model.ReflCode == 1:
  232.                                 END1.Y = END1.Y * -1.0
  233.                                 END2.Y = END2.Y * -1.0
  234.                                 
  235.                             vhandle = kcs_draft.view_identify(coord)
  236.                             END1_2d = KcsPoint2D.Point2D()
  237.                             kcs_draft.point_transform(vhandle, END1, END1_2d)
  238.                            
  239.                             END2_2d = KcsPoint2D.Point2D()
  240.                             kcs_draft.point_transform(vhandle, END2, END2_2d)
  241.                            
  242.                             text = xyf.text_pro("端点1", "微软雅黑", END1_2d, 3, 0, 0.8, "Red", "Solid")
  243.                             t_handle = kcs_draft.text_new(text)
  244.                             kcs_draft.element_highlight(t_handle)
  245.                             kcs_draft.element_delete(t_handle)
  246.                             text = xyf.text_pro("端点2", "微软雅黑", END2_2d, 3, 0, 0.8, "Red", "Solid")
  247.                             t_handle = kcs_draft.text_new(text)
  248.                             kcs_draft.element_highlight(t_handle)
  249.                             kcs_draft.element_delete(t_handle)                           
  250.                            
  251.                     except:
  252.                         pass
  253.                         
  254.                         
  255.                     #高亮同一个SCH的Part
  256.                     Shandle = kcs_draft.subview_identify(coord)
  257.                     Chandles = xyf.get_sub_handles(Shandle)
  258.                     for a in Chandles:
  259.                         try:
  260.                             model = kcs_draft.model_properties_get(a, model)
  261.                             if group_no == kcs_hullpan.group_get(model.Name, model.PartId):
  262.                                 kcs_draft.element_highlight(a)
  263.                         except:
  264.                             pass
  265.                     kcs_draft.dwg_repaint()
  266.                     kcs_ui.app_window_refresh() #刷新屏幕

  267.                     
  268.                     result = 0
  269.                 else:
  270.                     result = 0
  271.             except:
  272.                 kcs_draft.highlight_off(0)
  273.                 kcs_ui.message_confirm('请选择模型')

  274.         
  275.     def xyf_grid_list(self, old_sch):
  276.         z_d = {'STI': '型材', 'PRO': '型材规格', 'SID': '方向', 'QUA': '材质',
  277.                'ARP': '左装配', 'ARS': '右装配', 'AR': '装配', 'REV': '反向',
  278.                'CON': '连接型式', 'CUT': '切口', 'BEV': '坡口', 'POS': '位置号',
  279.                'SHR': '伸缩量', 'PO2': '位置号', 'PLA': '板材', 'MAT': '厚度',
  280.                'MSI': '板厚方向', 'AS1': '流向1', 'AS2': '流向2', 'AS3': '流向3',
  281.                'AS4': '流向4', 'COL': '颜色', 'NOT': '角隅', 'BRA': '肘板', 'HOL': '孔',
  282.                'EXC': '余量', 'BOU': '边界', 'FLA': '面板'}
  283.         old_sch = string.replace(old_sch, "  ", " ")
  284.         old_sch = string.replace(old_sch, ", ", " ")
  285.         old_sch = string.replace(old_sch, ";", "")

  286.         if self.GR.GetNumberRows() > 1:
  287.             self.GR.DeleteRows(0, self.GR.GetNumberRows())
  288.         old_sch_list = string.split(old_sch, ' ')
  289.         n = 0
  290.         for old_sch_list_str in old_sch_list:
  291.             self.GR.AppendRows()
  292.             # kcs_ui.message_confirm(old_sch_list_str)
  293.             try:
  294.                 b = string.split(old_sch_list_str, '=')
  295.                 if z_d.has_key(b[0]):
  296.                     self.GR.SetCellValue(n, 0, z_d[b[0]])
  297.                 else:
  298.                     self.GR.SetCellValue(n, 0, b[0])
  299.                 self.GR.SetCellValue(n, 1, b[0])
  300.                 if b[0] == 'SID' or b[0] == 'MSI':
  301.                     editor = apply(wxGridCellChoiceEditor, (['PS', 'SB', 'TOP', 'BOT', 'FOR', 'AFT'], False))
  302.                     self.GR.SetCellEditor(n, 2, editor)
  303.                 if b[0] == 'QUA':
  304.                     editor = apply(wxGridCellChoiceEditor,
  305.                                    (['A', 'AH32', 'AH36', 'B', 'D', 'DH32', 'DH36', 'E', 'EH32', 'EH36'], False))
  306.                     self.GR.SetCellEditor(n, 2, editor)
  307.                     
  308.                 if b[0] == 'MAT' or b[0] == 'POS' or b[0] == 'CON':
  309.                     editor = apply(wxGridCellNumberEditor, ())
  310.                     self.GR.SetCellEditor(n, 2, editor)
  311.                 self.GR.SetCellValue(n, 2, b[1])
  312.                
  313.                 if b[0] in ["AR","ARS","ARP"]:
  314.                     editor = apply(wxGridCellChoiceEditor,(TreeLis, False))
  315.                     self.GR.SetCellEditor(n, 2, editor)
  316.                     if TreeDic.has_key(b[1][1:-1]):
  317.                         self.GR.SetCellValue(n, 2, TreeDic[b[1][1:-1]])
  318.                
  319.             except:
  320.                 pass
  321.             n = n + 1
  322.             # self.GR.AutoSizeColumns(True)
  323.         self.GR.AppendRows()
  324.         self.GR.AppendRows()
  325.         self.xyf_new_sch()

  326.         
  327.     def xyf_new_sch(self):
  328.         temp_str = ''
  329.         for fr_no in range(self.GR.GetNumberRows()):
  330.             if self.GR.GetCellValue(fr_no, 1) <> '':
  331.                 if self.GR.GetCellValue(fr_no, 2) == '':
  332.                     temp_str = temp_str + self.GR.GetCellValue(fr_no, 1) + ", "
  333.                 else:                    
  334.                     if self.GR.GetCellValue(fr_no, 1) in ["AR","ARS","ARP"]:
  335.                         try:
  336.                             temp_str = temp_str + self.GR.GetCellValue(fr_no, 1) + "='" + TreeDic1[self.GR.GetCellValue(fr_no,2)] + "', "
  337.                         except:
  338.                             temp_str = temp_str + self.GR.GetCellValue(fr_no, 1) + "=" + self.GR.GetCellValue(fr_no,2) + ", "
  339.                     else:
  340.                         temp_str = temp_str + self.GR.GetCellValue(fr_no, 1) + "=" + self.GR.GetCellValue(fr_no,2) + ", "
  341.         temp_str = temp_str[:-2] + ';'
  342.         self.text_new_sch.Clear()
  343.         self.text_new_sch.AppendText(temp_str)



  344. class MyApp(wxApp):
  345.     __module__ = __name__

  346.     def __init__(self):
  347.         wxApp.__init__(self, redirect=True)

  348.     def OnInit(self):
  349.         frame = MyFrame(NULL, -1, '模型编辑器')
  350.         frame.Show(true)
  351.         self.SetTopWindow(frame)
  352.         return true


  353. def run(*args):
  354.     kcs_ui.message_confirm(args)
  355.     if time.time() < time.mktime((2025, 10, 15, 2, 1, 9, 2, 366, 0)):
  356.         app = MyApp()
  357.         app.MainLoop()

  358. if __name__ == '__main__':
  359.     run()
复制代码
回复 支持 反对

使用道具 举报

发表于 2023-8-18 07:26 来自手机 | 显示全部楼层 来自: 中国山东
点赞评论领大奖
回复 支持 反对

使用道具 举报

发表于 2023-8-25 21:39 | 显示全部楼层 来自: 日本
你卖给一些公司的二次开放里面管子部分用的我啊 兄弟
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|标签|免责声明|龙船社区

GMT+8, 2024-4-29 18:59

Powered by Imarine

Copyright © 2006, 龙船社区

快速回复 返回顶部 返回列表