自动化焊缝定义程序fe-safe

shell

python 复制代码
#-*- coding: utf-8 -*-
import re
import sys
import os
import os.path
import time
# import pingmianF
# from pingmianF import vector
import numpy as np
from tkinter import messagebox
from tkinter import filedialog
from tkinter import simpledialog


def popupmsg(msg):
    messagebox.showerror('Warning', msg)

#生成资源文件目录访问路径
def resource_path(relative_path):

    if getattr(sys, 'frozen', False): #是否Bundle Resource
        base_path = sys._MEIPASS
    else:
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)

# print(WLname)
# print(WDname)
# ['2_open_2_WELDLINE_370957', '1_open_2_WELDLINE_371520', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050']
# ['2_open_2_WELDDOMAIN_1449250', '1_open_2_WELDDOMAIN_1448858', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']


# print(start_node)
# print(start_element)
# ['2_open_2_WELDLINE_370957', '1_open_2_WELDLINE_371520', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050']
# ['2_open_2_WELDDOMAIN_1449450', '1_open_2_WELDDOMAIN_1448858', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']

def automation(path_inpname):
    ls_weldline = []
    ls_welddomain = []

    ls1 = []
    ls1_ = []
    ls1_data = []
    ls2 = []
    ls2_ = []
    ls2_data = []


    #访问res文件夹下数据.txt的内容
    filename = resource_path(os.path.join("file",path_inpname))
    with open(filename, 'r', encoding='utf-8') as fa:
        data_b = fa.read().splitlines()
        # print(data_b)
        for i in range(0,len(data_b)):

            data_b[i] = str.upper(data_b[i])
            if "WELDLINE_" in data_b[i]:
                ls1_.append(data_b[i])
                j=i+1
                while "*" not in data_b[j]:
                    ls1_data.append(data_b[j])
                    j=j+1
                ls1_ = ls1_+ ls1_data
                ls1_ = ','.join(ls1_)
                ls1.append(ls1_)
                ls1_ = []
                ls1_data = []

            if "WELDDOMAIN_" in data_b[i]:
                ls2_.append(data_b[i])
                k = i + 1
                while "*" not in data_b[k]:
                    ls2_data.append(data_b[k])
                    k=k+1
                ls2_ = ls2_ + ls2_data
                ls2_ = ','.join(ls2_)
                ls2.append(ls2_)
                ls2_ = []
                ls2_data = []

        print(ls1)
        print(ls2)
        ls = ls1 + ls2
        print(ls)

        # ['*NSET, NSET=Closed_2_weldline_126578_143528\n', '*NSET, NSET=Closed_2_weldline_126051_144027\n', '*NSET, NSET=Open_3_weldline_126776_189374\n']
        # ['*ELSET, ELSET=Closed_2_welddomain_318468\n', '*ELSET, ELSET=Closed_2_welddomain_318666\n', '*ELSET, ELSET=Open_3_welddomain_628339\n']

        for i in range(0, len(ls1)):
            ls_weldline.append(ls1[i].strip('\n').split('=')[-1])
        # print(ls_weldline)
        for j in range(0, len(ls2)):
            # print(ls_welddomain[j])
            ls_welddomain.append(ls2[j].strip('\n').split('=')[-1])


        # print(ls_welddomain)
        # print(len(ls_welddomain))
        # ['Closed_1_2_weldline_126578', 'Closed_2_2_weldline_126051, 'Open_3_3_weldline_126776']
        # ['Closed_1_2_welddomain_318468', 'Closed_2_2_welddomain_318666', 'Open_3_3_welddomain_628339']

#提取出所有weldline和welddomain所在行及命名部分
    data = ls_weldline + ls_welddomain
    WLname = []
    WDname = []
    content = []

    result_dict = {}
    for item in data:
        key = int(item.split('_')[1])  # 获取首个数字作为键
        value = item[0:]  # 获取后续数字作为值

        if key in result_dict:
            result_dict[key].append(value)
        else:
            result_dict[key] = [value]

    print(result_dict)

    # ['1_open_2_WELDLINE_371520', '2_open_2_WELDLINE_370957', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050', '1_open_2_WELDDOMAIN_1448858', '2_open_2_WELDDOMAIN_1449450', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']
    # {1: [['open', '2', 'WELDLINE', '371520'], ['open', '2', 'WELDDOMAIN', '1448858']], 2: [['open', '2', 'WELDLINE', '370957'], ['open', '2', 'WELDDOMAIN', '1449450']], 3: [['open', '2', 'WELDLINE', '371799'], ['open', '2', 'WELDDOMAIN', '1449047']], 4: [['open', '2', 'WELDLINE', '371050'], ['open', '2', 'WELDDOMAIN', '1449218']]}
    WLD = []
    for i in range(0, len(result_dict)):
        WLD = list(result_dict.values())
    # print(WLD)
    # print(len(WLD))

    for i in range(len(WLD)):
        WLname.append(WLD[i][0])
        WDname.append(WLD[i][1])
    print(WLname)
    print(WDname)
    content = WLname + WDname

    # ['2_open_2_WELDLINE_370957', '1_open_2_WELDLINE_371520', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050']
    # ['2_open_2_WELDDOMAIN_1449250', '1_open_2_WELDDOMAIN_1448858', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']



    new_content = []
    old_content = []
  # print(content)
        # ['NSET COUNT = 37\n*NSET, NSET=2_open_2_WELDLINE_370957\n    274706,    370957,    372104,    372107,    372108,    372115,    372116,    372125,\n    372126,    372133,    372134,    372142,    372143,    372152,    372153,    372162,\n    372163,    372164,    372166,    572824,    572826,    572831,    572834,    572836,\n    572840,    572843,    572846,    572848,    572852,    572854,    572857,    572861,\n    572863,    572866,    572869,    572873,    572876,\n\n',
        # 'NSET COUNT = 20\n*NSET, NSET=1_open_2_WELDLINE_371222\n    299140,    371520,    372110,    372112,    372118,    372121,    372122,    372123,\n    372130,    372131,    372138,    372139,    372146,    372148,    372149,    372157,\n    372159,    373496,    373497,    373498,\n\n',
        # 'NSET COUNT = 18\n*NSET, NSET=3_open_2_WELDLINE_371799\n    298792,    371799,    372168,    372176,    372178,    372184,    372185,    372192,\n    372203,    372205,    372214,    372227,    373506,    373507,    373508,    373509,\n    373510,    373511,\n',
        # 'NSET COUNT = 41\n*NSET, NSET=4_open_2_WELDLINE_371050\n    274430,    371050,    372171,    372179,    372188,    372197,    372207,    372208,\n    372209,    372210,    372216,    372217,    372218,    372229,    373499,    373500,\n    373501,    373502,    373503,    373504,    373505,    572820,    573233,    573324,\n    573326,    573327,    573329,    573341,    573343,    573345,    573347,    573349,\n    573351,    573352,    573354,    573355,    573357,    573358,    573360,    573414,\n    573415,\n',
        # 'ELSET COUNT = 38\n*ELSET,ELSET=1_open_2_WELDDOMAIN_1448858\n   1448891,   1448870,   1448864,   1448874,   1448862,   1448873,   1448866,   1448888,\n   1448863,   1448872,   1448884,   1448889,   1448892,   1448869,   1448859,   1448895,\n   1448868,   1448885,   1448876,   1448875,   1448880,   1448886,   1448883,   1448881,\n   1448858,   1448877,   1448878,   1448860,   1448871,   1448890,   1448867,   1448894,\n   1448879,   1448865,   1448861,   1448882,   1448893,   1448887,\n',
        # 'ELSET COUNT = 72\n*ELSET, ELSET=2_open_2_WELDDOMAIN_1449450\n   1449416,   1449417,   1449418,   1449419,   1449420,   1449421,   1449422,   1449423,\n   1449424,   1449425,   1449426,   1449427,   1449428,   1449429,   1449430,   1449431,\n   1449432,   1449433,   1449434,   1449435,   1449436,   1449437,   1449438,   1449439,\n   1449440,   1449441,   1449442,   1449443,   1449444,   1449445,   1449446,   1449447,\n   1449448,   1449449,   1449450,   1449451,   1656548,   1656549,   1656550,   1656551,\n   1656552,   1656553,   1656554,   1656555,   1656556,   1656557,   1656558,   1656559,\n   1656560,   1656561,   1656562,   1656563,   1656564,   1656565,   1656566,   1656567,\n   1656568,   1656569,   1656570,   1656571,   1656572,   1656573,   1656574,   1656575,\n   1656576,   1656577,   1656578,   1656579,   1656580,   1656581,   1656582,   1656583,\n',
        # 'ELSET COUNT = 34\n*ELSET, ELSET=4_open_2_WELDDOMAIN_1449218\n   1449218,   1449219,   1449220,   1449221,   1449222,   1449223,   1449224,   1449225,\n   1449226,   1449227,   1449228,   1449229,   1449230,   1449231,   1449232,   1449233,\n   1449234,   1449235,   1449236,   1449237,   S1449238,   1449239,   1449240,   1449241,\n   1449242,   1449243,   1449244,   1449245,   1449246,   1449247,   1449248,   1449249,\n   1449250,   1449251,   1449252,   1449253,   1449254,   1449255,   1449256,   1449257,\n   1656698,   1656699,   1656700,   1656701,   1656702,   1656703,   1656704,   1656705,\n   1656706,   1656707,   1656708,   1656709,   1656710,   1656711,   1656712,   1656713,\n   1656714,   1656715,   1656716,   1656717,   1656718,   1656719,   1656720,   1656721,\n   1656722,   1656723,   1656724,   1656725,   1656726,   1656727,   1656728,   1656729,\n   1656730,   1656731,   1656732,   1656733,   1656734,   1656735,   1656736,   1656737,\n\n\n',
        # 'ELSET COUNT = 38\n*ELSET, ELSET=3_open_2_WELDDOMAIN_1449047\n   1449047,   1449048,   1449049,   1449050,   1449051,   1449052,   1449053,   1449054,\n   1449055,   1449056,   1449057,   1449058,   1449059,   1449060,   1449061,   1449062,\n   1449063,   1449064,   1449065,   1449066,   1449067,   1449068,   1449069,   1449070,\n   1449071,   1449072,   1449073,   1449074,   1449075,   1449076,   1449077,   1449078,\n   1449079,   1449080,\n', 'ELSET COUNT = 80\n\n']

    for i in range(0, len(content)):
        list_1 = content[i].strip().split(',')
        # print("list" + str(list))
        target_number = list_1[0].split('_')[-1]
        old_content.append(list_1[0])
        data = list_1[1:]
        # print(data)
        # 将数据合并为一个字符串
        data_str = ''.join(data)
        # print(data_str)

        # data['    274706,    370957,    372104,    372107,    372108,    372115,    372116,    372125,', '    372126,    372133,    372134,    372142,    372143,    372152,    372153,    372162,', '    372163,    372164,    372166,    572824,    572826,    572831,    572834,    572836,', '    572840,    572843,    572846,    572848,    572852,    572854,    572857,    572861,', '    572863,    572866,    572869,    572873,    572876,', '', '']
        # data_str     274706,    370957,    372104,    372107,    372108,    372115,    372116,    372125,    372126,    372133,    372134,    372142,    372143,    372152,    372153,    372162,    372163,    372164,    372166,    572824,    572826,    572831,    572834,    572836,    572840,    572843,    572846,    572848,    572852,    572854,    572857,    572861,    572863,    572866,    572869,    572873,    572876,
        # 370957 存在于列表中。
        # ['    299140,    371520,    372110,    372112,    372118,    372121,    372122,    372123,', '    372130,    372131,    372138,    372139,    372146,    372148,    372149,    372157,', '    372159,    373496,    373497,    373498,', '', '']
        #     299140,    371520,    372110,    372112,    372118,    372121,    372122,    372123,    372130,    372131,    372138,    372139,    372146,    372148,    372149,    372157,    372159,    373496,    373497,    373498,
        # 371222 不存在于列表中,请输入正确标号。
        # ['    298792,    371799,    372168,    372176,    372178,    372184,    372185,    372192,', '    372203,    372205,    372214,    372227,    373506,    373507,    373508,    373509,', '    373510,    373511,', '']
        #     298792,    371799,    372168,    372176,    372178,    372184,    372185,    372192,    372203,    372205,    372214,    372227,    373506,    373507,    373508,    373509,    373510,    373511,
        # 371799 存在于列表中。
        # ['    274430,    371050,    372171,    372179,    372188,    372197,    372207,    372208,', '    372209,    372210,    372216,    372217,    372218,    372229,    373499,    373500,', '    373501,    373502,    373503,    373504,    373505,    572820,    573233,    573324,', '    573326,    573327,    573329,    573341,    573343,    573345,    573347,    573349,', '    573351,    573352,    573354,    573355,    573357,    573358,    573360,    573414,', '    573415,', '']
        #     274430,    371050,    372171,    372179,    372188,    372197,    372207,    372208,    372209,    372210,    372216,    372217,    372218,    372229,    373499,    373500,    373501,    373502,    373503,    373504,    373505,    572820,    573233,    573324,    573326,    573327,    573329,    573341,    573343,    573345,    573347,    573349,    573351,    573352,    573354,    573355,    573357,    573358,    573360,    573414,    573415,
        # 371050 存在于列表中。
        # ['   1448891,   1448870,   1448864,   1448874,   1448862,   1448873,   1448866,   1448888,', '   1448863,   1448872,   1448884,   1448889,   1448892,   1448869,   1448859,   1448895,', '   1448868,   1448885,   1448876,   1448875,   1448880,   1448886,   1448883,   1448881,', '   1448858,   1448877,   1448878,   1448860,   1448871,   1448890,   1448867,   1448894,', '   1448879,   1448865,   1448861,   1448882,   1448893,   1448887,', '']
        #    1448891,   1448870,   1448864,   1448874,   1448862,   1448873,   1448866,   1448888,   1448863,   1448872,   1448884,   1448889,   1448892,   1448869,   1448859,   1448895,   1448868,   1448885,   1448876,   1448875,   1448880,   1448886,   1448883,   1448881,   1448858,   1448877,   1448878,   1448860,   1448871,   1448890,   1448867,   1448894,   1448879,   1448865,   1448861,   1448882,   1448893,   1448887,
        # 1448858 存在于列表中。
        # ['   1449416,   1449417,   1449418,   1449419,   1449420,   1449421,   1449422,   1449423,', '   1449424,   1449425,   1449426,   1449427,   1449428,   1449429,   1449430,   1449431,', '   1449432,   1449433,   1449434,   1449435,   1449436,   1449437,   1449438,   1449439,', '   1449440,   1449441,   1449442,   1449443,   1449444,   1449445,   1449446,   1449447,', '   1449448,   1449449,   1449450,   1449451,   1656548,   1656549,   1656550,   1656551,', '   1656552,   1656553,   1656554,   1656555,   1656556,   1656557,   1656558,   1656559,', '   1656560,   1656561,   1656562,   1656563,   1656564,   1656565,   1656566,   1656567,', '   1656568,   1656569,   1656570,   1656571,   1656572,   1656573,   1656574,   1656575,', '   1656576,   1656577,   1656578,   1656579,   1656580,   1656581,   1656582,   1656583,', '']
        #    1449416,   1449417,   1449418,   1449419,   1449420,   1449421,   1449422,   1449423,   1449424,   1449425,   1449426,   1449427,   1449428,   1449429,   1449430,   1449431,   1449432,   1449433,   1449434,   1449435,   1449436,   1449437,   1449438,   1449439,   1449440,   1449441,   1449442,   1449443,   1449444,   1449445,   1449446,   1449447,   1449448,   1449449,   1449450,   1449451,   1656548,   1656549,   1656550,   1656551,   1656552,   1656553,   1656554,   1656555,   1656556,   1656557,   1656558,   1656559,   1656560,   1656561,   1656562,   1656563,   1656564,   1656565,   1656566,   1656567,   1656568,   1656569,   1656570,   1656571,   1656572,   1656573,   1656574,   1656575,   1656576,   1656577,   1656578,   1656579,   1656580,   1656581,   1656582,   1656583,
        # 1449450 存在于列表中。
        # ['   1449218,   1449219,   1449220,   1449221,   1449222,   1449223,   1449224,   1449225,', '   1449226,   1449227,   1449228,   1449229,   1449230,   1449231,   1449232,   1449233,', '   1449234,   1449235,   1449236,   1449237,   S1449238,   1449239,   1449240,   1449241,', '   1449242,   1449243,   1449244,   1449245,   1449246,   1449247,   1449248,   1449249,', '   1449250,   1449251,   1449252,   1449253,   1449254,   1449255,   1449256,   1449257,', '   1656698,   1656699,   1656700,   1656701,   1656702,   1656703,   1656704,   1656705,', '   1656706,   1656707,   1656708,   1656709,   1656710,   1656711,   1656712,   1656713,', '   1656714,   1656715,   1656716,   1656717,   1656718,   1656719,   1656720,   1656721,', '   1656722,   1656723,   1656724,   1656725,   1656726,   1656727,   1656728,   1656729,', '   1656730,   1656731,   1656732,   1656733,   1656734,   1656735,   1656736,   1656737,', '', '', '']
        #    1449218,   1449219,   1449220,   1449221,   1449222,   1449223,   1449224,   1449225,   1449226,   1449227,   1449228,   1449229,   1449230,   1449231,   1449232,   1449233,   1449234,   1449235,   1449236,   1449237,   S1449238,   1449239,   1449240,   1449241,   1449242,   1449243,   1449244,   1449245,   1449246,   1449247,   1449248,   1449249,   1449250,   1449251,   1449252,   1449253,   1449254,   1449255,   1449256,   1449257,   1656698,   1656699,   1656700,   1656701,   1656702,   1656703,   1656704,   1656705,   1656706,   1656707,   1656708,   1656709,   1656710,   1656711,   1656712,   1656713,   1656714,   1656715,   1656716,   1656717,   1656718,   1656719,   1656720,   1656721,   1656722,   1656723,   1656724,   1656725,   1656726,   1656727,   1656728,   1656729,   1656730,   1656731,   1656732,   1656733,   1656734,   1656735,   1656736,   1656737,
        # 1449218 存在于列表中。
        # ['   1449047,   1449048,   1449049,   1449050,   1449051,   1449052,   1449053,   1449054,', '   1449055,   1449056,   1449057,   1449058,   1449059,   1449060,   1449061,   1449062,', '   1449063,   1449064,   1449065,   1449066,   1449067,   1449068,   1449069,   1449070,', '   1449071,   1449072,   1449073,   1449074,   1449075,   1449076,   1449077,   1449078,', '   1449079,   1449080,', '']
        #    1449047,   1449048,   1449049,   1449050,   1449051,   1449052,   1449053,   1449054,   1449055,   1449056,   1449057,   1449058,   1449059,   1449060,   1449061,   1449062,   1449063,   1449064,   1449065,   1449066,   1449067,   1449068,   1449069,   1449070,   1449071,   1449072,   1449073,   1449074,   1449075,   1449076,   1449077,   1449078,   1449079,   1449080,
        # 1449047 存在于列表中。

        if target_number in data_str:
            # print(f"{target_number} 存在于列表中。")
            new_content.append(list_1[0])

        else:
            # print(f"{target_number} 不存在于列表中,请输入正确标号。")
            new = simpledialog.askinteger(title="",
                                          prompt=list_1[0]+"的"+target_number+"输入有误,请重新输入起始单元或起始节点号:")
            # print(new)
            #     content = str(content).replace(str(target_number),str(new))
            # print(content)
            new_list = list_1[0].replace(str(target_number), str(new))
            # print()
            new_content.append(new_list)


    print(new_content)
    print(old_content)

    filename1 = resource_path(os.path.join("file","weld-current_modify.wdf"))
    os.remove(filename1)

    filename2 = resource_path(os.path.join("file","weld_current_shell.txt"))

    f1 = open(filename1,'a',encoding='utf-8')


    f1.write('<weld_definition>\n')

    with open(filename2,'r',encoding='utf-8') as f2:

        # content = f1.read()
        # f1.seek(0,0)
        # f1.write('<weld_definition>\n'+content)
        for i in range(0,len(ls1)):
            lines = f2.read()
            f2.seek(0)

            lines = lines.replace('%New_Line',old_content[i].upper())
            plate_thick = str.upper(old_content[i].strip('\n').split('_')[2])
            if 'P' in plate_thick:
                lines = lines.replace('%plate_thickness', plate_thick.replace('P','.'))
            else:
                lines = lines.replace('%plate_thickness', plate_thick)
            # "PART-1-1_"+
            lines = lines.replace('%welddomain',"PART-1-1_"+old_content[i+len(ls1)].upper())
            lines = lines.replace('%start_element', new_content[i+len(ls1)].strip('\n').split('_')[-1])

            # lines = lines.replace('%reference_normal',str(pingmianF.vector(node_list[j],node_list[j+1],node_list[j+2])))
            # print(vector(node_list[j], node_list[j + 1], node_list[j + 2]))

            # if '%weldline' in line:

                # f1.write(line.replace('%weldline', 'weldline1234_4567'))
            # "PART-1-1_"+
            lines = lines.replace('%weldline',"PART-1-1_"+old_content[i].upper()+"_nodal")
            lines = lines.replace('%start_node', new_content[i].strip('\n').split('_')[-1])

            lines = lines.replace('%weld_type', old_content[i].strip('\n').split('_')[0].capitalize())

            f1.write(lines)


            # j = j+3

        f1.write('</weld_definition>')
    f1.close()
    f2.close()
    fa.close()

if __name__ == '__main__':
    path_inpname = filedialog.askopenfilenames(title="Select Text File",
                                       filetypes=[("INP File", "*.inp"), ("All Files", "*.*")])
    # print(path_inpname)
    automation(path_inpname[0])

    print('工具运行成功!')
    # except:
    #     popupmsg('工具运行不成功!')
# f2.close()

solid

python 复制代码
#-*- coding: utf-8 -*-
import re
import sys
import os
import os.path
import time
import pingmianF
from pingmianF import vector
import numpy as np
from tkinter import messagebox
from tkinter import filedialog
from tkinter import simpledialog


def popupmsg(msg):
    messagebox.showerror('Warning', msg)

#生成资源文件目录访问路径
def resource_path(relative_path):

    if getattr(sys, 'frozen', False): #是否Bundle Resource
        base_path = sys._MEIPASS
    else:
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)

# print(WLname)
# print(WDname)
# ['2_open_2_WELDLINE_370957', '1_open_2_WELDLINE_371520', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050']
# ['2_open_2_WELDDOMAIN_1449250', '1_open_2_WELDDOMAIN_1448858', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']


# print(start_node)
# print(start_element)
# ['2_open_2_WELDLINE_370957', '1_open_2_WELDLINE_371520', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050']
# ['2_open_2_WELDDOMAIN_1449450', '1_open_2_WELDDOMAIN_1448858', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']
def automation(path_inpname):
    ls_weldline = []
    ls_welddomain = []
    ls_face = []

    ls1 = []
    ls1_ = []
    ls1_data = []
    ls2 = []
    ls2_ = []
    ls2_data = []
    ls3 = []
    ls3_ = []
    ls3_data = []


    #访问res文件夹下数据.txt的内容
    filename = resource_path(os.path.join("file",path_inpname))
    with open(filename, 'r', encoding='utf-8') as fa:
        data_b = fa.read().splitlines()
        # print(data_b)
        for i in range(0,len(data_b)):

            data_b[i] = str.upper(data_b[i])
            if "WELDLINE_" in data_b[i]:
                ls1_.append(data_b[i])
                j=i+1
                while "*" not in data_b[j]:
                    ls1_data.append(data_b[j])
                    j=j+1
                ls1_ = ls1_+ ls1_data
                ls1_ = ','.join(ls1_)
                ls1.append(ls1_)
                ls1_ = []
                ls1_data = []

            if "WELDDOMAIN_" in data_b[i]:
                ls2_.append(data_b[i])
                k = i + 1
                while "*" not in data_b[k]:
                    ls2_data.append(data_b[k])
                    k=k+1
                ls2_ = ls2_ + ls2_data
                ls2_ = ','.join(ls2_)
                ls2.append(ls2_)
                ls2_ = []
                ls2_data = []


            if "FACE_" in data_b[i]:
                ls3_.append(data_b[i])
                m = i + 1
                while "*" not in data_b[m]:
                    ls3_data.append(data_b[m])
                    m=m+1
                ls3_ = ls3_ + ls3_data
                ls3_ = ','.join(ls3_)
                ls3.append(ls3_)
                ls3_ = []
                ls3_data = []
        #
        # print(ls1)
        # print(ls2)
        # print(ls3)
        ls = ls1 + ls2 +ls3
        # print(ls)

        # ['*NSET, NSET=Closed_2_weldline_126578_143528\n', '*NSET, NSET=Closed_2_weldline_126051_144027\n', '*NSET, NSET=Open_3_weldline_126776_189374\n']
        # ['*ELSET, ELSET=Closed_2_welddomain_318468\n', '*ELSET, ELSET=Closed_2_welddomain_318666\n', '*ELSET, ELSET=Open_3_welddomain_628339\n']

        for i in range(0, len(ls1)):
            ls_weldline.append(ls1[i].strip('\n').split('=')[-1])
        # print(ls_weldline)
        for j in range(0, len(ls2)):
            # print(ls_welddomain[j])
            ls_welddomain.append(ls2[j].strip('\n').split('=')[-1])
        for k in range(0, len(ls3)):
            # print(ls_welddomain[j])
            ls_face.append(ls3[k].strip('\n').split('=')[-1])


        # print(ls_welddomain)
        # print(len(ls_welddomain))
        # ['Closed_1_2_weldline_126578', 'Closed_2_2_weldline_126051, 'Open_3_3_weldline_126776']
        # ['Closed_1_2_welddomain_318468', 'Closed_2_2_welddomain_318666', 'Open_3_3_welddomain_628339']

#提取出所有weldline和welddomain所在行及命名部分
    data = ls_weldline + ls_welddomain + ls_face
    # print(data)
    WLname = []
    WDname = []
    WFname = []
    content = []

    result_dict = {}
    for item in data:
        key = int(item.split('_')[1])  # 获取首个数字作为键
        value = item[0:]  # 获取后续数字作为值

        if key in result_dict:
            result_dict[key].append(value)
        else:
            result_dict[key] = [value]

    # print(result_dict)

    # ['1_open_2_WELDLINE_371520', '2_open_2_WELDLINE_370957', '3_open_2_WELDLINE_371799', '4_open_2_WELDLINE_371050', '1_open_2_WELDDOMAIN_1448858', '2_open_2_WELDDOMAIN_1449450', '3_open_2_WELDDOMAIN_1449047', '4_open_2_WELDDOMAIN_1449218']
    # {1: [['open', '2', 'WELDLINE', '371520'], ['open', '2', 'WELDDOMAIN', '1448858']], 2: [['open', '2', 'WELDLINE', '370957'], ['open', '2', 'WELDDOMAIN', '1449450']], 3: [['open', '2', 'WELDLINE', '371799'], ['open', '2', 'WELDDOMAIN', '1449047']], 4: [['open', '2', 'WELDLINE', '371050'], ['open', '2', 'WELDDOMAIN', '1449218']]}
    WLD = []
    for i in range(0, len(result_dict)):
        WLD = list(result_dict.values())
    # print(WLD)
    # print(len(WLD))

    for i in range(len(WLD)):
        WLname.append(WLD[i][0])
        WDname.append(WLD[i][1])
        WFname.append(WLD[i][2])
    # print(WLname)
    # print(WDname)
    # print(WFname)
    content = WLname + WDname
    node_set = []
    for i in range(0,len(WFname)):
        WFname[i] = WFname[i].strip().split(",")
        node_set.append(WFname[i][1:4])

    # print(node_set)
    #node_set为法平面的三个点
    new_content = []
    old_content = []

    for i in range(0, len(content)):
        list_1 = content[i].strip().split(',')
        # print("list" + str(list))
        target_number = list_1[0].split('_')[-1]
        old_content.append(list_1[0])
        data = list_1[1:]
        # print(data)
        # 将数据合并为一个字符串
        data_str = ''.join(data)
        # print(data_str)

        # data['    274706,    370957,    372104,    372107,    372108,    372115,    372116,    372125,', '    372126,    372133,    372134,    372142,    372143,    372152,    372153,    372162,', '    372163,    372164,    372166,    572824,    572826,    572831,    572834,    572836,', '    572840,    572843,    572846,    572848,    572852,    572854,    572857,    572861,', '    572863,    572866,    572869,    572873,    572876,', '', '']
        # data_str     274706,    370957,    372104,    372107,    372108,    372115,    372116,    372125,    372126,    372133,    372134,    372142,    372143,    372152,    372153,    372162,    372163,    372164,    372166,    572824,    572826,    572831,    572834,    572836,    572840,    572843,    572846,    572848,    572852,    572854,    572857,    572861,    572863,    572866,    572869,    572873,    572876,
        # 370957 存在于列表中。
        # ['    299140,    371520,    372110,    372112,    372118,    372121,    372122,    372123,', '    372130,    372131,    372138,    372139,    372146,    372148,    372149,    372157,', '    372159,    373496,    373497,    373498,', '', '']
        #     299140,    371520,    372110,    372112,    372118,    372121,    372122,    372123,    372130,    372131,    372138,    372139,    372146,    372148,    372149,    372157,    372159,    373496,    373497,    373498,
        # 371222 不存在于列表中,请输入正确标号。
        # ['    298792,    371799,    372168,    372176,    372178,    372184,    372185,    372192,', '    372203,    372205,    372214,    372227,    373506,    373507,    373508,    373509,', '    373510,    373511,', '']
        #     298792,    371799,    372168,    372176,    372178,    372184,    372185,    372192,    372203,    372205,    372214,    372227,    373506,    373507,    373508,    373509,    373510,    373511,
        # 371799 存在于列表中。
        # ['    274430,    371050,    372171,    372179,    372188,    372197,    372207,    372208,', '    372209,    372210,    372216,    372217,    372218,    372229,    373499,    373500,', '    373501,    373502,    373503,    373504,    373505,    572820,    573233,    573324,', '    573326,    573327,    573329,    573341,    573343,    573345,    573347,    573349,', '    573351,    573352,    573354,    573355,    573357,    573358,    573360,    573414,', '    573415,', '']
        #     274430,    371050,    372171,    372179,    372188,    372197,    372207,    372208,    372209,    372210,    372216,    372217,    372218,    372229,    373499,    373500,    373501,    373502,    373503,    373504,    373505,    572820,    573233,    573324,    573326,    573327,    573329,    573341,    573343,    573345,    573347,    573349,    573351,    573352,    573354,    573355,    573357,    573358,    573360,    573414,    573415,
        # 371050 存在于列表中。
        # ['   1448891,   1448870,   1448864,   1448874,   1448862,   1448873,   1448866,   1448888,', '   1448863,   1448872,   1448884,   1448889,   1448892,   1448869,   1448859,   1448895,', '   1448868,   1448885,   1448876,   1448875,   1448880,   1448886,   1448883,   1448881,', '   1448858,   1448877,   1448878,   1448860,   1448871,   1448890,   1448867,   1448894,', '   1448879,   1448865,   1448861,   1448882,   1448893,   1448887,', '']
        #    1448891,   1448870,   1448864,   1448874,   1448862,   1448873,   1448866,   1448888,   1448863,   1448872,   1448884,   1448889,   1448892,   1448869,   1448859,   1448895,   1448868,   1448885,   1448876,   1448875,   1448880,   1448886,   1448883,   1448881,   1448858,   1448877,   1448878,   1448860,   1448871,   1448890,   1448867,   1448894,   1448879,   1448865,   1448861,   1448882,   1448893,   1448887,
        # 1448858 存在于列表中。
        # ['   1449416,   1449417,   1449418,   1449419,   1449420,   1449421,   1449422,   1449423,', '   1449424,   1449425,   1449426,   1449427,   1449428,   1449429,   1449430,   1449431,', '   1449432,   1449433,   1449434,   1449435,   1449436,   1449437,   1449438,   1449439,', '   1449440,   1449441,   1449442,   1449443,   1449444,   1449445,   1449446,   1449447,', '   1449448,   1449449,   1449450,   1449451,   1656548,   1656549,   1656550,   1656551,', '   1656552,   1656553,   1656554,   1656555,   1656556,   1656557,   1656558,   1656559,', '   1656560,   1656561,   1656562,   1656563,   1656564,   1656565,   1656566,   1656567,', '   1656568,   1656569,   1656570,   1656571,   1656572,   1656573,   1656574,   1656575,', '   1656576,   1656577,   1656578,   1656579,   1656580,   1656581,   1656582,   1656583,', '']
        #    1449416,   1449417,   1449418,   1449419,   1449420,   1449421,   1449422,   1449423,   1449424,   1449425,   1449426,   1449427,   1449428,   1449429,   1449430,   1449431,   1449432,   1449433,   1449434,   1449435,   1449436,   1449437,   1449438,   1449439,   1449440,   1449441,   1449442,   1449443,   1449444,   1449445,   1449446,   1449447,   1449448,   1449449,   1449450,   1449451,   1656548,   1656549,   1656550,   1656551,   1656552,   1656553,   1656554,   1656555,   1656556,   1656557,   1656558,   1656559,   1656560,   1656561,   1656562,   1656563,   1656564,   1656565,   1656566,   1656567,   1656568,   1656569,   1656570,   1656571,   1656572,   1656573,   1656574,   1656575,   1656576,   1656577,   1656578,   1656579,   1656580,   1656581,   1656582,   1656583,
        # 1449450 存在于列表中。
        # ['   1449218,   1449219,   1449220,   1449221,   1449222,   1449223,   1449224,   1449225,', '   1449226,   1449227,   1449228,   1449229,   1449230,   1449231,   1449232,   1449233,', '   1449234,   1449235,   1449236,   1449237,   S1449238,   1449239,   1449240,   1449241,', '   1449242,   1449243,   1449244,   1449245,   1449246,   1449247,   1449248,   1449249,', '   1449250,   1449251,   1449252,   1449253,   1449254,   1449255,   1449256,   1449257,', '   1656698,   1656699,   1656700,   1656701,   1656702,   1656703,   1656704,   1656705,', '   1656706,   1656707,   1656708,   1656709,   1656710,   1656711,   1656712,   1656713,', '   1656714,   1656715,   1656716,   1656717,   1656718,   1656719,   1656720,   1656721,', '   1656722,   1656723,   1656724,   1656725,   1656726,   1656727,   1656728,   1656729,', '   1656730,   1656731,   1656732,   1656733,   1656734,   1656735,   1656736,   1656737,', '', '', '']
        #    1449218,   1449219,   1449220,   1449221,   1449222,   1449223,   1449224,   1449225,   1449226,   1449227,   1449228,   1449229,   1449230,   1449231,   1449232,   1449233,   1449234,   1449235,   1449236,   1449237,   S1449238,   1449239,   1449240,   1449241,   1449242,   1449243,   1449244,   1449245,   1449246,   1449247,   1449248,   1449249,   1449250,   1449251,   1449252,   1449253,   1449254,   1449255,   1449256,   1449257,   1656698,   1656699,   1656700,   1656701,   1656702,   1656703,   1656704,   1656705,   1656706,   1656707,   1656708,   1656709,   1656710,   1656711,   1656712,   1656713,   1656714,   1656715,   1656716,   1656717,   1656718,   1656719,   1656720,   1656721,   1656722,   1656723,   1656724,   1656725,   1656726,   1656727,   1656728,   1656729,   1656730,   1656731,   1656732,   1656733,   1656734,   1656735,   1656736,   1656737,
        # 1449218 存在于列表中。
        # ['   1449047,   1449048,   1449049,   1449050,   1449051,   1449052,   1449053,   1449054,', '   1449055,   1449056,   1449057,   1449058,   1449059,   1449060,   1449061,   1449062,', '   1449063,   1449064,   1449065,   1449066,   1449067,   1449068,   1449069,   1449070,', '   1449071,   1449072,   1449073,   1449074,   1449075,   1449076,   1449077,   1449078,', '   1449079,   1449080,', '']
        #    1449047,   1449048,   1449049,   1449050,   1449051,   1449052,   1449053,   1449054,   1449055,   1449056,   1449057,   1449058,   1449059,   1449060,   1449061,   1449062,   1449063,   1449064,   1449065,   1449066,   1449067,   1449068,   1449069,   1449070,   1449071,   1449072,   1449073,   1449074,   1449075,   1449076,   1449077,   1449078,   1449079,   1449080,
        # 1449047 存在于列表中。

        if target_number in data_str:
            # print(f"{target_number} 存在于列表中。")
            new_content.append(list_1[0])

        else:
            # print(f"{target_number} 不存在于列表中,请输入正确标号。")
            new = simpledialog.askinteger(title="",
                                          prompt=list_1[0]+"的"+target_number+"输入有误,请重新输入起始单元或起始节点号:")
            # print(new)
            #     content = str(content).replace(str(target_number),str(new))
            # print(content)
            new_list = list_1[0].replace(str(target_number), str(new))
            # print()
            new_content.append(new_list)

    # print("new_content"+str(new_content))
    # print(old_content)


    filename = resource_path(os.path.join("file",path_inpname))
    # print(filename)
    node_coordinate = []
    ls4 = []
    ls4_ = []
    ls4_data = []
    with open(filename,'r',encoding='utf-8') as fa:
        data_c = fa.read().splitlines()
    # print(data_b)
    for i in range(0, len(data_c)):

        data_c[i] = str.upper(data_c[i])
        if "*NODE" in data_c[i]:
            n = i + 1
            while "*" not in data_c[n]:
                ls4_data.append(data_c[n])
                n = n + 1
            ls4.append(ls4_data)
            ls4_data = []
            break

    # print(ls4)
    node_cor = []
    node_cor = ls4[0]

    #node_cor里面含所有节点坐标
    node = []
    for j in range(0,len(node_set)):
        for k in range(0,3):
            for i in range(0, len(node_cor)):
                str1 = node_cor[i].split(',')[0]
                int_str1 = int(str1)
                if int_str1 == int(node_set[j][k]):
                    node_coordinate.append(node_cor[i])
                    break
    # print(node_coordinate)

    #node_coordinate
    #['126051,        -213.32157,      -23.94757,       55.92702\n',
    # '126578,         -49.68242,      -23.94821,      -50.66072\n',
    # '126776,        -114.42335,      -23.94608,      -46.53174\n',
    # '127140,        -212.51184,      -23.98995,       56.26252\n',
    # '143528,         -48.68259,      -23.94195,      -50.67784\n',
    # '143529,         -48.67345,      -23.97157,      -50.15527\n',
    # '144028,        -212.89419,      -23.97285,       57.18638\n',
    # '189374,        -115.39657,      -23.94313,      -46.30191\n',
    # '189375,        -115.09989,      -23.98079,      -45.04446\n']

    node_list = []
    for j in range (0,len(node_coordinate)):
        str3 = node_coordinate[j].strip(' ').strip('\n').split(',')[1:4]
        node_list.append(str3)
    # print(node_list)

    #['126776,        -114.42335,      -23.94608,      -46.53174\n',
    # '189374,        -115.39657,      -23.94313,      -46.30191\n',
    # '189375,        -115.09989,      -23.98079,      -45.04446\n',
    # '144028,        -212.89419,      -23.97285,       57.18638\n',
    # '127140,        -212.51184,      -23.98995,       56.26252\n',
    # '126051,        -213.32157,      -23.94757,       55.92702\n',
    # '143529,         -48.67345,      -23.97157,      -50.15527\n',
    # '143528,         -48.68259,      -23.94195,      -50.67784\n',
    # '126578,         -49.68242,      -23.94821,      -50.66072\n']

    # [['        -114.42335', '      -23.94608', '      -46.53174'],
    # ['        -115.39657', '      -23.94313', '      -46.30191'],
    # ['        -115.09989', '      -23.98079', '      -45.04446'],
    # ['        -212.89419', '      -23.97285', '       57.18638'],
    # ['        -212.51184', '      -23.98995', '       56.26252'],
    # ['        -213.32157', '      -23.94757', '       55.92702'],
    # ['         -48.67345', '      -23.97157', '      -50.15527'],
    # ['         -48.68259', '      -23.94195', '      -50.67784'],
    # ['         -49.68242', '      -23.94821', '      -50.66072']]

    filename1 = resource_path(os.path.join("file","weld-current_modify.wdf"))
    os.remove(filename1)

    filename2 = resource_path(os.path.join("file","weld_current.txt"))

    f1 = open(filename1,'a',encoding='utf-8')


    f1.write('<weld_definition>\n')

    j = 0
    with open(filename2,'r',encoding='utf-8') as f2:

        # content = f1.read()
        # f1.seek(0,0)
        # f1.write('<weld_definition>\n'+content)
        for i in range(0,len(ls1)):
            lines = f2.read()
            f2.seek(0)
            lines = lines.replace('%New_Line',old_content[i].upper())

            plate_thick = str.upper(WLname[i].strip('\n').split('_')[2])
            if 'P' in plate_thick:
                lines = lines.replace('%plate_thickness', plate_thick.replace('P', '.'))
            else:
                lines = lines.replace('%plate_thickness', plate_thick)
            # "PART-1-1_"+
            lines = lines.replace('%welddomain',"PART-1-1_"+old_content[i+len(ls1)].upper())
            lines = lines.replace('%start_element', new_content[i+len(ls1)].strip('\n').split('_')[-1])

            lines = lines.replace('%reference_normal',str(pingmianF.vector(node_list[j],node_list[j+1],node_list[j+2])))
            # print(vector(node_list[j], node_list[j + 1], node_list[j + 2]))

            # if '%weldline' in line:

                # f1.write(line.replace('%weldline', 'weldline1234_4567'))
            # "PART-1-1_"+
            lines = lines.replace('%weldline',"PART-1-1_"+old_content[i].upper()+"_nodal")
            lines = lines.replace('%start_node', new_content[i].strip('\n').split('_')[-1])

            lines = lines.replace('%weld_type', new_content[i].strip('\n').split('_')[0].capitalize())

            f1.write(lines)


            j = j+3

        f1.write('</weld_definition>')


    f1.close()
    f2.close()
    fa.close()

if __name__ == '__main__':
    path_inpname = filedialog.askopenfilenames(title="Select Text File",
                                       filetypes=[("INP File", "*.inp"), ("All Files", "*.*")])
    # print(path_inpname)
    automation(path_inpname[0])

    print('工具运行成功!')
    # except:
    #     popupmsg('工具运行不成功!')
# f2.close()

pingmianF

python 复制代码
# import numpy as np
#
# def compute_normal_vector(point1, point2, point3):
#     vector1 = np.array(point2) - np.array(point1)
#     vector2 = np.array(point3) - np.array(point1)
#     normal_vector = np.cross(vector1, vector2)
#     return normal_vector
#
# # 示例输入
# point1 = [-114.42335,      -23.94608,      -46.53174]
# point2 = [-115.39657,      -23.94313,      -46.30191]
# point3 = [-115.09989,      -23.98079,      -45.04446]
#
# normal_vector = compute_normal_vector(point1, point2, point3)
# print(normal_vector)
# # 在上面的代码示例中,我们使用了numpy库来进行向量的计算。
# # compute_normal_vector函数接受三个点作为输入,然后使用numpy库中的array函数将这些点转换为数组。
# # 接着,我们计算两个向量vector1和vector2,它们分别是point2-point1和point3-point1。
# # 最后,我们使用numpy库中的cross函数计算向量的叉积,得到平面的法向量。


# import read_inp_auto as read_inp
import numpy as np


p1 =['        -114.42335', '      -23.94608', '      -46.53174']
p2 =['        -115.39657', '      -23.94313', '      -46.30191']
p3 =['        -115.09989', '      -23.98079', '      -45.04446']

def vector(p1,p2,p3):

    # 定义三个点的坐标
    point1 = np.array(p1)
    point2 = np.array(p2)
    point3 = np.array(p3)

    float_point1 = point1.astype(np.float64)
    float_point2 = point2.astype(np.float64)
    float_point3 = point3.astype(np.float64)
    # 计算两个向量
    vector1 = float_point2 - float_point1
    vector2 = float_point3 - float_point1

    # 计算法向量
    normal_vector = np.cross(vector1, vector2)

    # 归一化为单位向量
    unit_normal_vector = normal_vector / np.linalg.norm(normal_vector)
    vector_final =",".join(("{:.4f}".format(num) for num in unit_normal_vector))

    return vector_final
# print(vector(p1,p2,p3))

weld-current

python 复制代码
   <!--fe-safe weld definition file-->
    <groups>
        <group name="%welddomain" type="elemental"></group>
    </groups>
    <weld name="%New_Line" type="line">
        <parameter id="plate thickness">
            <!--Plate Thickness-->
            <value>%plate_thickness</value>
        </parameter>
        <parameter id="smoothing iterations">
            <!--Number of smoothing iterations-->
            <value>2</value>
        </parameter>
        <parameter id="ir function">
            <!--I(r) Function-->
            <value>Structural Joints / Displacement Control</value>
        </parameter>
        <parameter id="weld end correction">
            <!--Weld End Correction-->
            <value>Virtual node (original)</value>
        </parameter>
        <parameter id="element type">
            <!--Element type-->
            <value>Solids</value>
        </parameter>
        <parameter id="weld line group name">
            <!--Weld line nodes-->
            <value>%weldline</value>
        </parameter>
        <parameter id="weld toe elements">
            <!--Weld reference elements-->
            <value>%welddomain</value>
        </parameter>
        <parameter id="start node">
            <!--Start Node-->
            <value>%start_node</value>
        </parameter>
        <parameter id="start element">
            <!--Start Element-->
            <value>%start_element</value>
        </parameter>
        <parameter id="reference normal">
            <!--Reference Normal-->
            <value>%reference_normal</value>
        </parameter>
        <parameter id="weld type">
            <!--Weld type-->
            <value>%weld_type</value>
        </parameter>
        <parameter id="failure mode">
            <!--Failure Mode-->
            <value>Unspecified Failure Mode</value>
        </parameter>
        <parameter id="through thickness node validation tolerance">
            <!--Through thickness node validation cone tolerance-->
            <value>0.1</value>
        </parameter>
        <parameter id="Through thickness node search co-planarity tolerance angle">
            <!--Through thickness node search co-planarity tolerance angle-->
            <value>5</value>
        </parameter>
        <group name="%weldline" type="nodal" id="weld nodes"></group>
    </weld>
相关推荐
阡之尘埃1 小时前
Python数据分析案例61——信贷风控评分卡模型(A卡)(scorecardpy 全面解析)
人工智能·python·机器学习·数据分析·智能风控·信贷风控
一坨阿亮2 小时前
Linux 使用中的问题
linux·运维
wclass-zhengge4 小时前
Docker篇(Docker Compose)
运维·docker·容器
李启柱4 小时前
项目开发流程规范文档
运维·软件构建·个人开发·设计规范
丕羽4 小时前
【Pytorch】基本语法
人工智能·pytorch·python
bryant_meng5 小时前
【python】Distribution
开发语言·python·分布函数·常用分布
2401_857622665 小时前
SpringBoot健身房管理:敏捷与自动化
spring boot·后端·自动化
力姆泰克5 小时前
看电动缸是如何提高农机的自动化水平
大数据·运维·服务器·数据库·人工智能·自动化·1024程序员节
BPM_宏天低代码5 小时前
低代码 BPA:简化业务流程自动化的新趋势
运维·低代码·自动化
sun0077006 小时前
拷贝 cp -rdp 和 cp -a
linux·运维·服务器