-
Notifications
You must be signed in to change notification settings - Fork 2
/
Place objects at selected refs.pas
83 lines (69 loc) · 2.58 KB
/
Place objects at selected refs.pas
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
{
Run on something within your target file. Put in the EDIDs into the const down there.
Script will check if the refs you run it on have the given baseform, and if yes, place a new instance of the target object at them
}
unit userscript;
uses praUtil;
const
srcEdid = 'BTInt_Bld02FrontSidingACom04'; // put in the EDID of the original base object here
targetEdid = 'praBTI_Bld02CornerBrickACom02_BlackPlanes'; // put in the EDID of the other thingy here
layerEdid = 'BlackPlanes'; // put in the EDID of the layer to put the new refs on
var
targetFile, srcObj, targetObj, targetLayer: IInterface;
function createRefCopy(sourceElem: IInterface; targetFile: IwbFile): IInterface;
begin
addRequiredMastersSilent(sourceElem, targetFile);
Result := wbCopyElementToFile(sourceElem, targetFile, true, True);
end;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
Result := 1;
srcObj := FindObjectByEdid(srcEdid);
if(not assigned(srcObj)) then begin
AddMessage('Failed to find '+srcEdid);
exit;
end;
targetObj := FindObjectByEdid(targetEdid);
if(not assigned(targetObj)) then begin
AddMessage('Failed to find '+targetEdid);
exit;
end;
targetLayer := FindObjectByEdid(layerEdid);
if(not assigned(targetLayer)) then begin
AddMessage('Failed to find '+layerEdid);
exit;
end;
Result := 0;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
var
i: integer;
curRef, newRef: IInterface;
begin
Result := 0;
if(not assigned(targetFile)) then begin
targetFile := getFile(e);
end;
if(Signature(e) <> 'REFR') then begin
exit;
end;
if(isSameForm(pathLinksTo(e, 'NAME'), srcObj)) then begin
newRef := createRefCopy(e, targetFile);
AddMessage('Processing ' + FullPath(e));
setPathLinksTo(newRef, 'NAME', targetObj);
setPathLinksTo(newRef, 'XLYR', targetLayer);
end;
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
var
i: integer;
curRef, newRef: IInterface;
begin
Result := 0;
end;
end.