-
Notifications
You must be signed in to change notification settings - Fork 1
/
Honeycomb.js
157 lines (131 loc) · 5.36 KB
/
Honeycomb.js
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
//Author-
//Description-
/*globals adsk*/
(function () {
"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}
var app = adsk.core.Application.get(), ui;
if (app) {
ui = app.userInterface;
}
// Create the command definition.
var createCommandDefinition = function() {
var commandDefinitions = ui.commandDefinitions;
// Be fault tolerant in case the command is already added...
var cmDef = commandDefinitions.itemById('Honeycomb');
if (!cmDef) {
var url = window.location.pathname;
var des = decodeURI(url);
//remove the / at beginning
var semicolonIndex = des.indexOf(":");
//It's a path on Windows
if(semicolonIndex != -1) {
des = des.substr(1);
}
var index = des.lastIndexOf('.');
var dir = des.substring(0, index);
cmDef = commandDefinitions.addButtonDefinition('Honeycomb',
'Create a honeycomb structure',
'Create a honeycomb structure.',
dir);
}
return cmDef;
};
// CommandCreated event handler.
var onCommandCreated = function(args) {
try {
// Connect to the CommandExecuted event.
var command = args.command;
command.execute.add(onCommandExecuted);
// Terminate the script when the command is destroyed
command.destroy.add(function () { adsk.terminate(); });
// Define the inputs.
var inputs = command.commandInputs;
inputs.addSelectionInput('profile', 'Sketch profile', 'Select the bounding sketch profile');
var initialVal3 = adsk.core.ValueInput.createByReal(5.0);
inputs.addValueInput('radius', 'Radius', 'mm' , initialVal3);
var initialVal = adsk.core.ValueInput.createByReal(2.0);
inputs.addValueInput('spacing', 'Spacing', 'mm' , initialVal);
var initialVal2 = adsk.core.ValueInput.createByReal(5.0);
inputs.addValueInput('perimeterSpacing', 'Perimeter spacing', 'mm' , initialVal2);
inputs.addBoolValueInput('cutComb', 'Press/pull the honeycomb', 'Press/pull');
}
catch (e) {
ui.messageBox('Failed to create command : ' + (e.description ? e.description : e));
}
};
// CommandExecuted event handler.
var onCommandExecuted = function(args) {
try {
var unitsMgr = app.activeProduct.unitsManager;
var command = adsk.core.Command(args.firingEvent.sender);
var inputs = command.commandInputs;
var profileInput;
var radiusInput;
var spacingInput;
var perimeterSpacingInput;
var cutCombInput;
// Problem with a problem - the inputs are empty at this point. We
// need access to the inputs within a command during the execute.
for (var n = 0; n < inputs.count; n++) {
var input = inputs.item(n);
if (input.id === 'profile') {
profileInput = adsk.core.SelectionCommandInput(input);
profileInput.addSelectionFilter(adsk.core.SelectionCommandInput.SketchCurves);
}
else if (input.id === 'radius') {
radiusInput = adsk.core.ValueCommandInput(input);
}
else if (input.id === 'spacing') {
spacingInput = adsk.core.ValueCommandInput(input);
}
else if (input.id === 'perimeterSpacing') {
perimeterSpacingInput = adsk.core.ValueCommandInput(input);
}
else if (input.id === 'cutComb') {
cutCombInput = adsk.core.StringValueCommandInput(input);
}
}
var profile;
var radius;
var spacing;
var perimeterSpacing;
var cutComb;
if (!profileInput || !radiusInput || !spacingInput || !perimeterSpacingInput || !cutCombInput) {
ui.messageBox("One of the inputs don't exist.");
profile = null;
radius = 5.0;
spacing = 2.0;
perimeterSpacing = 5.0;
cutComb = true;
}
else
{
//profile = ??;
radius = unitsMgr.evaluateExpression(radiusInput.expression, "mm");
spacing = unitsMgr.evaluateExpression(spacingInput.expression, "mm");
perimeterSpacing = unitsMgr.evaluateExpression(perimeterSpacingInput.expression, "mm");
cutComb = unitsMgr.evaluateExpression(cutCombInput);
}
}
catch (e) {
ui.messageBox('Failed to create honeycomb : ' + (e.description ? e.description : e));
}
};
try {
var command = createCommandDefinition();
var commandCreatedEvent = command.commandCreated;
commandCreatedEvent.add(onCommandCreated);
command.execute();
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
adsk.terminate();
}());