1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
NAME:
DESCRIPTION: ;
PARAMETER:
[
{
name : 'prefix',
title : '前缀名',
type : 'LineEdit',
property : {tool_tip : '前缀名,默认是org-'},
},
{
name : 'suffix',
title : '后缀名',
type : 'LineEdit',
property : {tool_tip : '后缀名,默认没有'},
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2020-04-20 Scott Sun
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> 备份层 </p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> 前缀后缀 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
console.log("==============================>备份层");
// 引入模块 包
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var database = require("topsin.database");
database.addConnection($.conf.database_conf, "DFM");
var QDfm = database.query("DFM");
if ($.conf.product_type == "aimdfm") {
QDfm.updateRow({
table: "pdm_aimdfm_task",
data: {
current_process_title: $.process_title
},
where: { id: $.task_id }
});
}
var GEN = $.gen;
var Job = $.job_name;
var db = $.db
var Status = 'ok';
var resultData = [];
var PAR = {};
if ($.hasOwnProperty('script_parameter')){
PAR = JSON.parse($.script_parameter);
}
try {
var par = PAR;
var default_par = {
prefix: "org-",
suffix: "",
auto_save: "No",
}
for(var key in default_par){ // 设置默认属性
if (!par.hasOwnProperty(key) || par[key] == ""){
par[key] = default_par[key]
}
}
if(_.isEmpty(Job)){throw "参数Job不存在"}
var job = Job.toLowerCase()
// 检查料号是否存在
if(!GEN.isJobExists({job:job})){throw "料号已经:"+job+"不存在"}
// 检查料号是否被打开
if(!GEN.isJobOpen({job:job})){ GEN.openJob({job:job}) }
// 检查料号是否能够check out
if(GEN.checkInout({job:job,mode:"test"}) != 0){ throw "the job check" }
GEN.checkInout({job:job,mode:"out"});
// 通过matrix获取board层
var matrix = GEN.getMatrix({job:job})
var board_layers = Object.keys(matrix).reduce(function(a,b){
if(matrix[b].context == "board"){
a.push(b)
}
return a
},[])
board_layers.forEach(function(layer){
var new_layer = par.prefix + layer + par.suffix
if(GEN.isLayerExists({job:job,layer:new_layer})){
GEN.deleteLayer({job:job,layer:new_layer})
}
GEN.matrixAddLayer({job:job,layer:new_layer,context:'misc',type:matrix[layer].layer_type})
})
var stepList = GEN.getStepList({job:job})
stepList.forEach(function(step){
GEN.openStep({job:job,name:step})
// 逐层备份原稿层,备份名为prefix + 层名 + suffix
board_layers.forEach(function(layer){
var new_layer = par.prefix + layer + par.suffix
GEN.affectedLayer({affected:'no',mode:'all'})
GEN.workLayer({name:layer,display_number:2,clear_before:'yes'})
GEN.selClearFeature()
GEN.selAllFeat()
GEN.selCopyOther({dest:"layer_name",target_layer:new_layer})
GEN.selClearFeature()
GEN.clearLayers()
})
GEN.closeStep()
})
// 保存
if(/yes/ig.test(par.auto_save)){
GEN.checkInout({job:job,mode:"out"}) // 结束保存料号 关闭料号
GEN.saveJob({ job: job });
GEN.checkInout({job:job,mode:"in"})
GEN.closeJob({job:job})
} else {
GEN.checkInout({job:job,mode:"in"})
}
QDfm.updateRow({
table: "pdm_aimdfm_task",
data: {
progress: 33.33
},
where: { id: $.task_id }
});
if (GEN.hasError()) {
Status = 'error';
resultData.push({ type: "error", title: "GEN错误!", detail: [{ desc: _.join(GEN.STATUS, "\n") }] });
return {
status: Status,
result_data: resultData
};
} else {
resultData.push({ type: "info", title: "操作完成, 请注意检查!" });
return {
status: Status,
result_data: resultData
};
}
} catch (e) {
Status = 'error';
resultData.push({type: "error", title: "脚本执行出错!", detail: [{desc: _.toString(e)}]});
return {status: Status, result_data: resultData};
}