-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformCopy.fs.txt
More file actions
110 lines (96 loc) · 4.31 KB
/
Copy pathTransformCopy.fs.txt
File metadata and controls
110 lines (96 loc) · 4.31 KB
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
FeatureScript 2796;
import(path : "onshape/std/common.fs", version : "2796.0");
import(path : "onshape/std/coordSystem.fs", version : "2796.0");
import(path : "onshape/std/evaluate.fs", version : "2796.0");
import(path : "onshape/std/feature.fs", version : "2796.0");
import(path : "onshape/std/query.fs", version : "2796.0");
import(path : "onshape/std/transform.fs", version : "2796.0");
import(path : "onshape/std/propertytype.gen.fs", version : "2796.0");
annotation { "Feature Type Name" : "Transform Copy",
"Feature Type Description" : "Copy a body to multiple mate connector locations" }
export const transformCopyMulti = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Body to copy",
"Filter" : EntityType.BODY && BodyType.SOLID,
"MaxNumberOfPicks" : 1 }
definition.bodyToCopy is Query;
annotation { "Name" : "Source mate connector",
"Filter" : QueryFilterCompound.ALLOWS_AXIS,
"MaxNumberOfPicks" : 1 }
definition.sourceMateConnector is Query;
annotation { "Name" : "Target mate connectors",
"Filter" : QueryFilterCompound.ALLOWS_AXIS,
"MaxNumberOfPicks" : 500 }
definition.targetMateConnectors is Query;
annotation { "Name" : "Delete original", "Default" : false }
definition.deleteOriginal is boolean;
}
{
// Validate body selection
var bodies = evaluateQuery(context, definition.bodyToCopy);
if (size(bodies) == 0)
{
throw regenError("Please select a body to copy", ["bodyToCopy"]);
}
if (size(bodies) > 1)
{
throw regenError("Please select only one body to copy", ["bodyToCopy"]);
}
var bodyToCopy = bodies[0];
// Validate source mate connector
var sourceMateConnectors = evaluateQuery(context, definition.sourceMateConnector);
if (size(sourceMateConnectors) == 0)
{
throw regenError("Please select a source mate connector", ["sourceMateConnector"]);
}
if (size(sourceMateConnectors) > 1)
{
throw regenError("Please select only one source mate connector", ["sourceMateConnector"]);
}
var sourceMateConnector = sourceMateConnectors[0];
// Validate target mate connectors
var targetMateConnectors = evaluateQuery(context, definition.targetMateConnectors);
if (size(targetMateConnectors) == 0)
{
throw regenError("Please select at least one target mate connector", ["targetMateConnectors"]);
}
// Get source coordinate system
var sourceCS = evMateConnector(context, {
"mateConnector" : sourceMateConnector
});
// Get original part name for naming copies
var originalName = try silent(getProperty(context, {
"entity" : bodyToCopy,
"propertyType" : PropertyType.NAME
}));
if (originalName == undefined)
{
originalName = "Part";
}
// Create a copy at each target mate connector
for (var i = 0; i < size(targetMateConnectors); i += 1)
{
var targetMateConnector = targetMateConnectors[i];
// Get target coordinate system
var targetCS = evMateConnector(context, {
"mateConnector" : targetMateConnector
});
// Calculate transformation from source to target
// This aligns the source mate connector to the target mate connector
var transform = toWorld(targetCS) * fromWorld(sourceCS);
// Create the copy using opPattern with the transformation
opPattern(context, id + ("copy" ~ i), {
"entities" : bodyToCopy,
"transforms" : [transform],
"instanceNames" : [originalName ~ "_Copy_" ~ (i + 1)]
});
}
// Delete original body if requested
if (definition.deleteOriginal)
{
opDeleteBodies(context, id + "deleteOriginal", {
"entities" : bodyToCopy
});
}
});