Add 2 files
Browse files- README.md +6 -4
- index.html +960 -18
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: purple
|
6 |
sdk: static
|
7 |
pinned: false
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: pystrings
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
+
tags:
|
9 |
+
- deepsite
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
@@ -1,19 +1,961 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Python Strings and Methods for Autodesk Maya</title>
|
7 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
8 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css">
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
background-color: #1a1a1a;
|
12 |
+
color: #e0e0e0;
|
13 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
14 |
+
}
|
15 |
+
.method-container {
|
16 |
+
background-color: #2d2d2d;
|
17 |
+
border-radius: 8px;
|
18 |
+
margin-bottom: 20px;
|
19 |
+
transition: all 0.3s ease;
|
20 |
+
}
|
21 |
+
.method-container:hover {
|
22 |
+
box-shadow: 0 0 15px rgba(66, 153, 225, 0.3);
|
23 |
+
}
|
24 |
+
.play-button {
|
25 |
+
background-color: #4299e1;
|
26 |
+
transition: all 0.2s ease;
|
27 |
+
}
|
28 |
+
.play-button:hover {
|
29 |
+
background-color: #3182ce;
|
30 |
+
transform: scale(1.05);
|
31 |
+
}
|
32 |
+
.play-button:active {
|
33 |
+
transform: scale(0.98);
|
34 |
+
}
|
35 |
+
.result-box {
|
36 |
+
background-color: #363636;
|
37 |
+
border-left: 4px solid #4299e1;
|
38 |
+
font-family: 'Consolas', 'Courier New', monospace;
|
39 |
+
}
|
40 |
+
.section-title {
|
41 |
+
border-bottom: 2px solid #4299e1;
|
42 |
+
padding-bottom: 8px;
|
43 |
+
}
|
44 |
+
input[type="text"], textarea {
|
45 |
+
background-color: #363636;
|
46 |
+
border: 1px solid #4a4a4a;
|
47 |
+
color: #e0e0e0;
|
48 |
+
}
|
49 |
+
input[type="text"]:focus, textarea:focus {
|
50 |
+
border-color: #4299e1;
|
51 |
+
outline: none;
|
52 |
+
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.3);
|
53 |
+
}
|
54 |
+
code {
|
55 |
+
background-color: #363636;
|
56 |
+
padding: 2px 4px;
|
57 |
+
border-radius: 4px;
|
58 |
+
font-family: 'Consolas', 'Courier New', monospace;
|
59 |
+
}
|
60 |
+
</style>
|
61 |
+
</head>
|
62 |
+
<body class="px-4 py-6 max-w-6xl mx-auto">
|
63 |
+
<header class="mb-8">
|
64 |
+
<h1 class="text-4xl font-bold text-blue-400 mb-2">Python Strings and Methods for Autodesk Maya</h1>
|
65 |
+
<p class="text-lg text-gray-300">Interactive examples to practice string manipulation techniques useful in Maya scripting</p>
|
66 |
+
</header>
|
67 |
+
|
68 |
+
<main>
|
69 |
+
<!-- Introduction -->
|
70 |
+
<section class="mb-10">
|
71 |
+
<p class="mb-4">
|
72 |
+
In Maya Python scripting, strings are essential for working with node names, file paths, commands, and more.
|
73 |
+
This interactive guide lets you experiment with Python's string methods and see immediate results.
|
74 |
+
</p>
|
75 |
+
<p class="text-sm text-gray-400 italic mb-6">
|
76 |
+
For each example, enter your own text in the input field and click the play button to see the result.
|
77 |
+
</p>
|
78 |
+
</section>
|
79 |
+
|
80 |
+
<!-- Basic String Operations -->
|
81 |
+
<section class="mb-10">
|
82 |
+
<h2 class="text-2xl font-bold text-blue-300 section-title mb-4">Basic String Operations</h2>
|
83 |
+
|
84 |
+
<!-- Concatenation -->
|
85 |
+
<div class="method-container p-4 mb-6">
|
86 |
+
<h3 class="text-xl font-semibold mb-2">String Concatenation</h3>
|
87 |
+
<p class="mb-3">Combines two or more strings together using the <code>+</code> operator. In Maya, this is often used to build command strings or create full paths.</p>
|
88 |
+
|
89 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
90 |
+
<div>
|
91 |
+
<label class="block mb-2">First String:</label>
|
92 |
+
<input type="text" id="concat-input1" class="w-full p-2 rounded" value="sphere_" placeholder="Enter first string">
|
93 |
+
</div>
|
94 |
+
<div>
|
95 |
+
<label class="block mb-2">Second String:</label>
|
96 |
+
<input type="text" id="concat-input2" class="w-full p-2 rounded" value="01" placeholder="Enter second string">
|
97 |
+
</div>
|
98 |
+
</div>
|
99 |
+
|
100 |
+
<button onclick="concatStrings()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
101 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
102 |
+
</button>
|
103 |
+
|
104 |
+
<div class="mt-4">
|
105 |
+
<p class="font-medium mb-1">Result:</p>
|
106 |
+
<div id="concat-result" class="result-box p-3 rounded"></div>
|
107 |
+
</div>
|
108 |
+
|
109 |
+
<div class="mt-4 text-sm text-gray-400">
|
110 |
+
<p>Maya usage example:</p>
|
111 |
+
<pre class="bg-gray-800 p-2 rounded"><code>node_prefix = "pSphere"
|
112 |
+
node_number = "1"
|
113 |
+
full_node_name = node_prefix + node_number # Creates "pSphere1"
|
114 |
+
cmds.select(full_node_name)</code></pre>
|
115 |
+
</div>
|
116 |
+
</div>
|
117 |
+
|
118 |
+
<!-- Indexing -->
|
119 |
+
<div class="method-container p-4 mb-6">
|
120 |
+
<h3 class="text-xl font-semibold mb-2">String Indexing</h3>
|
121 |
+
<p class="mb-3">Access individual characters in a string using their index position (starting from 0). Useful for inspecting specific characters in node names.</p>
|
122 |
+
|
123 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
124 |
+
<div>
|
125 |
+
<label class="block mb-2">String:</label>
|
126 |
+
<input type="text" id="index-input" class="w-full p-2 rounded" value="pCube5_grp" placeholder="Enter a string">
|
127 |
+
</div>
|
128 |
+
<div>
|
129 |
+
<label class="block mb-2">Index Position:</label>
|
130 |
+
<input type="number" id="index-position" class="w-full p-2 rounded" value="1" min="0" placeholder="Enter index number">
|
131 |
+
</div>
|
132 |
+
</div>
|
133 |
+
|
134 |
+
<button onclick="indexString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
135 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
136 |
+
</button>
|
137 |
+
|
138 |
+
<div class="mt-4">
|
139 |
+
<p class="font-medium mb-1">Result:</p>
|
140 |
+
<div id="index-result" class="result-box p-3 rounded"></div>
|
141 |
+
</div>
|
142 |
+
|
143 |
+
<div class="mt-4 text-sm text-gray-400">
|
144 |
+
<p>Maya usage example:</p>
|
145 |
+
<pre class="bg-gray-800 p-2 rounded"><code>node_name = "pSphere1"
|
146 |
+
node_type = node_name[0] # Gets 'p' which can indicate a polygon object
|
147 |
+
if node_type == "p":
|
148 |
+
print("This is likely a polygon object")</code></pre>
|
149 |
+
</div>
|
150 |
+
</div>
|
151 |
+
|
152 |
+
<!-- Slicing -->
|
153 |
+
<div class="method-container p-4 mb-6">
|
154 |
+
<h3 class="text-xl font-semibold mb-2">String Slicing</h3>
|
155 |
+
<p class="mb-3">Extract a substring using the slice notation <code>[start:end]</code>. Useful for extracting parts of object names or file paths in Maya.</p>
|
156 |
+
|
157 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
|
158 |
+
<div>
|
159 |
+
<label class="block mb-2">String:</label>
|
160 |
+
<input type="text" id="slice-input" class="w-full p-2 rounded" value="pCylinder25_geo" placeholder="Enter a string">
|
161 |
+
</div>
|
162 |
+
<div>
|
163 |
+
<label class="block mb-2">Start Index:</label>
|
164 |
+
<input type="number" id="slice-start" class="w-full p-2 rounded" value="0" min="0" placeholder="Start index">
|
165 |
+
</div>
|
166 |
+
<div>
|
167 |
+
<label class="block mb-2">End Index:</label>
|
168 |
+
<input type="number" id="slice-end" class="w-full p-2 rounded" value="9" min="0" placeholder="End index">
|
169 |
+
</div>
|
170 |
+
</div>
|
171 |
+
|
172 |
+
<button onclick="sliceString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
173 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
174 |
+
</button>
|
175 |
+
|
176 |
+
<div class="mt-4">
|
177 |
+
<p class="font-medium mb-1">Result:</p>
|
178 |
+
<div id="slice-result" class="result-box p-3 rounded"></div>
|
179 |
+
</div>
|
180 |
+
|
181 |
+
<div class="mt-4 text-sm text-gray-400">
|
182 |
+
<p>Maya usage example:</p>
|
183 |
+
<pre class="bg-gray-800 p-2 rounded"><code>file_path = "C:/Projects/Maya/scenes/character_rig_v001.mb"
|
184 |
+
file_name = file_path[-11:] # Gets "v001.mb"
|
185 |
+
version_number = file_name[1:4] # Gets "001"</code></pre>
|
186 |
+
</div>
|
187 |
+
</div>
|
188 |
+
</section>
|
189 |
+
|
190 |
+
<!-- Case Methods -->
|
191 |
+
<section class="mb-10">
|
192 |
+
<h2 class="text-2xl font-bold text-blue-300 section-title mb-4">Case Methods</h2>
|
193 |
+
|
194 |
+
<!-- upper() -->
|
195 |
+
<div class="method-container p-4 mb-6">
|
196 |
+
<h3 class="text-xl font-semibold mb-2">.upper()</h3>
|
197 |
+
<p class="mb-3">Converts all characters in a string to uppercase. Useful for case-insensitive comparisons in Maya scripts.</p>
|
198 |
+
|
199 |
+
<div class="mb-4">
|
200 |
+
<label class="block mb-2">String:</label>
|
201 |
+
<input type="text" id="upper-input" class="w-full p-2 rounded" value="leftArm_ctrl" placeholder="Enter a string">
|
202 |
+
</div>
|
203 |
+
|
204 |
+
<button onclick="upperCaseString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
205 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
206 |
+
</button>
|
207 |
+
|
208 |
+
<div class="mt-4">
|
209 |
+
<p class="font-medium mb-1">Result:</p>
|
210 |
+
<div id="upper-result" class="result-box p-3 rounded"></div>
|
211 |
+
</div>
|
212 |
+
|
213 |
+
<div class="mt-4 text-sm text-gray-400">
|
214 |
+
<p>Maya usage example:</p>
|
215 |
+
<pre class="bg-gray-800 p-2 rounded"><code>user_input = "yes"
|
216 |
+
if user_input.upper() == "YES":
|
217 |
+
# Process regardless of input case (yes, Yes, YES)
|
218 |
+
cmds.polyCube(name="new_cube")</code></pre>
|
219 |
+
</div>
|
220 |
+
</div>
|
221 |
+
|
222 |
+
<!-- lower() -->
|
223 |
+
<div class="method-container p-4 mb-6">
|
224 |
+
<h3 class="text-xl font-semibold mb-2">.lower()</h3>
|
225 |
+
<p class="mb-3">Converts all characters in a string to lowercase. Useful for standardizing naming or case-insensitive comparisons.</p>
|
226 |
+
|
227 |
+
<div class="mb-4">
|
228 |
+
<label class="block mb-2">String:</label>
|
229 |
+
<input type="text" id="lower-input" class="w-full p-2 rounded" value="RightLeg_GRP" placeholder="Enter a string">
|
230 |
+
</div>
|
231 |
+
|
232 |
+
<button onclick="lowerCaseString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
233 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
234 |
+
</button>
|
235 |
+
|
236 |
+
<div class="mt-4">
|
237 |
+
<p class="font-medium mb-1">Result:</p>
|
238 |
+
<div id="lower-result" class="result-box p-3 rounded"></div>
|
239 |
+
</div>
|
240 |
+
|
241 |
+
<div class="mt-4 text-sm text-gray-400">
|
242 |
+
<p>Maya usage example:</p>
|
243 |
+
<pre class="bg-gray-800 p-2 rounded"><code>obj_name = "CHARACTER_RIG"
|
244 |
+
standardized_name = obj_name.lower() # "character_rig"
|
245 |
+
cmds.rename(obj_name, standardized_name)</code></pre>
|
246 |
+
</div>
|
247 |
+
</div>
|
248 |
+
|
249 |
+
<!-- title() -->
|
250 |
+
<div class="method-container p-4 mb-6">
|
251 |
+
<h3 class="text-xl font-semibold mb-2">.title()</h3>
|
252 |
+
<p class="mb-3">Converts the first character of each word to uppercase and the rest to lowercase. Useful for formatting display names in UIs.</p>
|
253 |
+
|
254 |
+
<div class="mb-4">
|
255 |
+
<label class="block mb-2">String:</label>
|
256 |
+
<input type="text" id="title-input" class="w-full p-2 rounded" value="character facial controls" placeholder="Enter a string">
|
257 |
+
</div>
|
258 |
+
|
259 |
+
<button onclick="titleCaseString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
260 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
261 |
+
</button>
|
262 |
+
|
263 |
+
<div class="mt-4">
|
264 |
+
<p class="font-medium mb-1">Result:</p>
|
265 |
+
<div id="title-result" class="result-box p-3 rounded"></div>
|
266 |
+
</div>
|
267 |
+
|
268 |
+
<div class="mt-4 text-sm text-gray-400">
|
269 |
+
<p>Maya usage example:</p>
|
270 |
+
<pre class="bg-gray-800 p-2 rounded"><code>control_description = "head rotation controls"
|
271 |
+
display_name = control_description.title() # "Head Rotation Controls"
|
272 |
+
cmds.button(label=display_name)</code></pre>
|
273 |
+
</div>
|
274 |
+
</div>
|
275 |
+
|
276 |
+
<!-- capitalize() -->
|
277 |
+
<div class="method-container p-4 mb-6">
|
278 |
+
<h3 class="text-xl font-semibold mb-2">.capitalize()</h3>
|
279 |
+
<p class="mb-3">Capitalizes the first character of the string and converts the rest to lowercase. Useful for formatting single labels or short descriptions.</p>
|
280 |
+
|
281 |
+
<div class="mb-4">
|
282 |
+
<label class="block mb-2">String:</label>
|
283 |
+
<input type="text" id="capitalize-input" class="w-full p-2 rounded" value="mainController" placeholder="Enter a string">
|
284 |
+
</div>
|
285 |
+
|
286 |
+
<button onclick="capitalizeString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
287 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
288 |
+
</button>
|
289 |
+
|
290 |
+
<div class="mt-4">
|
291 |
+
<p class="font-medium mb-1">Result:</p>
|
292 |
+
<div id="capitalize-result" class="result-box p-3 rounded"></div>
|
293 |
+
</div>
|
294 |
+
|
295 |
+
<div class="mt-4 text-sm text-gray-400">
|
296 |
+
<p>Maya usage example:</p>
|
297 |
+
<pre class="bg-gray-800 p-2 rounded"><code>error_message = "invalid selection"
|
298 |
+
formatted_message = error_message.capitalize() # "Invalid selection"
|
299 |
+
cmds.warning(formatted_message)</code></pre>
|
300 |
+
</div>
|
301 |
+
</div>
|
302 |
+
</section>
|
303 |
+
|
304 |
+
<!-- Search Methods -->
|
305 |
+
<section class="mb-10">
|
306 |
+
<h2 class="text-2xl font-bold text-blue-300 section-title mb-4">Search Methods</h2>
|
307 |
+
|
308 |
+
<!-- find() -->
|
309 |
+
<div class="method-container p-4 mb-6">
|
310 |
+
<h3 class="text-xl font-semibold mb-2">.find()</h3>
|
311 |
+
<p class="mb-3">Returns the index of the first occurrence of a substring, or -1 if not found. Useful for locating specific patterns in node names or paths.</p>
|
312 |
+
|
313 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
314 |
+
<div>
|
315 |
+
<label class="block mb-2">String:</label>
|
316 |
+
<input type="text" id="find-input" class="w-full p-2 rounded" value="character_arm_joint_01" placeholder="Enter a string">
|
317 |
+
</div>
|
318 |
+
<div>
|
319 |
+
<label class="block mb-2">Substring to Find:</label>
|
320 |
+
<input type="text" id="find-substring" class="w-full p-2 rounded" value="arm" placeholder="Enter substring to find">
|
321 |
+
</div>
|
322 |
+
</div>
|
323 |
+
|
324 |
+
<button onclick="findInString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
325 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
326 |
+
</button>
|
327 |
+
|
328 |
+
<div class="mt-4">
|
329 |
+
<p class="font-medium mb-1">Result:</p>
|
330 |
+
<div id="find-result" class="result-box p-3 rounded"></div>
|
331 |
+
</div>
|
332 |
+
|
333 |
+
<div class="mt-4 text-sm text-gray-400">
|
334 |
+
<p>Maya usage example:</p>
|
335 |
+
<pre class="bg-gray-800 p-2 rounded"><code>node_name = "character_arm_joint_01"
|
336 |
+
if node_name.find("arm") != -1:
|
337 |
+
print("This is an arm joint")
|
338 |
+
# Add arm-specific rigging code</code></pre>
|
339 |
+
</div>
|
340 |
+
</div>
|
341 |
+
|
342 |
+
<!-- startswith() -->
|
343 |
+
<div class="method-container p-4 mb-6">
|
344 |
+
<h3 class="text-xl font-semibold mb-2">.startswith()</h3>
|
345 |
+
<p class="mb-3">Checks if a string starts with a specified prefix, returning True or False. Useful for filtering nodes by prefix naming conventions.</p>
|
346 |
+
|
347 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
348 |
+
<div>
|
349 |
+
<label class="block mb-2">String:</label>
|
350 |
+
<input type="text" id="startswith-input" class="w-full p-2 rounded" value="jnt_spine_01" placeholder="Enter a string">
|
351 |
+
</div>
|
352 |
+
<div>
|
353 |
+
<label class="block mb-2">Prefix to Check:</label>
|
354 |
+
<input type="text" id="startswith-prefix" class="w-full p-2 rounded" value="jnt_" placeholder="Enter prefix to check">
|
355 |
+
</div>
|
356 |
+
</div>
|
357 |
+
|
358 |
+
<button onclick="checkStartsWith()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
359 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
360 |
+
</button>
|
361 |
+
|
362 |
+
<div class="mt-4">
|
363 |
+
<p class="font-medium mb-1">Result:</p>
|
364 |
+
<div id="startswith-result" class="result-box p-3 rounded"></div>
|
365 |
+
</div>
|
366 |
+
|
367 |
+
<div class="mt-4 text-sm text-gray-400">
|
368 |
+
<p>Maya usage example:</p>
|
369 |
+
<pre class="bg-gray-800 p-2 rounded"><code>all_nodes = cmds.ls()
|
370 |
+
joint_nodes = []
|
371 |
+
|
372 |
+
for node in all_nodes:
|
373 |
+
if node.startswith("jnt_"):
|
374 |
+
joint_nodes.append(node)
|
375 |
+
|
376 |
+
print(f"Found {len(joint_nodes)} joints")</code></pre>
|
377 |
+
</div>
|
378 |
+
</div>
|
379 |
+
|
380 |
+
<!-- endswith() -->
|
381 |
+
<div class="method-container p-4 mb-6">
|
382 |
+
<h3 class="text-xl font-semibold mb-2">.endswith()</h3>
|
383 |
+
<p class="mb-3">Checks if a string ends with a specified suffix, returning True or False. Useful for filtering nodes by suffix naming conventions.</p>
|
384 |
+
|
385 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
386 |
+
<div>
|
387 |
+
<label class="block mb-2">String:</label>
|
388 |
+
<input type="text" id="endswith-input" class="w-full p-2 rounded" value="character_head_ctrl" placeholder="Enter a string">
|
389 |
+
</div>
|
390 |
+
<div>
|
391 |
+
<label class="block mb-2">Suffix to Check:</label>
|
392 |
+
<input type="text" id="endswith-suffix" class="w-full p-2 rounded" value="_ctrl" placeholder="Enter suffix to check">
|
393 |
+
</div>
|
394 |
+
</div>
|
395 |
+
|
396 |
+
<button onclick="checkEndsWith()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
397 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
398 |
+
</button>
|
399 |
+
|
400 |
+
<div class="mt-4">
|
401 |
+
<p class="font-medium mb-1">Result:</p>
|
402 |
+
<div id="endswith-result" class="result-box p-3 rounded"></div>
|
403 |
+
</div>
|
404 |
+
|
405 |
+
<div class="mt-4 text-sm text-gray-400">
|
406 |
+
<p>Maya usage example:</p>
|
407 |
+
<pre class="bg-gray-800 p-2 rounded"><code>all_objects = cmds.ls()
|
408 |
+
control_objects = []
|
409 |
+
|
410 |
+
for obj in all_objects:
|
411 |
+
if obj.endswith("_ctrl"):
|
412 |
+
control_objects.append(obj)
|
413 |
+
|
414 |
+
cmds.select(control_objects) # Select all control objects</code></pre>
|
415 |
+
</div>
|
416 |
+
</div>
|
417 |
+
</section>
|
418 |
+
|
419 |
+
<!-- Modification Methods -->
|
420 |
+
<section class="mb-10">
|
421 |
+
<h2 class="text-2xl font-bold text-blue-300 section-title mb-4">Modification Methods</h2>
|
422 |
+
|
423 |
+
<!-- replace() -->
|
424 |
+
<div class="method-container p-4 mb-6">
|
425 |
+
<h3 class="text-xl font-semibold mb-2">.replace()</h3>
|
426 |
+
<p class="mb-3">Replaces occurrences of a substring with another substring. Perfect for renaming parts of object names or updating file paths.</p>
|
427 |
+
|
428 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
|
429 |
+
<div>
|
430 |
+
<label class="block mb-2">String:</label>
|
431 |
+
<input type="text" id="replace-input" class="w-full p-2 rounded" value="arm_left_ctrl" placeholder="Enter a string">
|
432 |
+
</div>
|
433 |
+
<div>
|
434 |
+
<label class="block mb-2">Text to Replace:</label>
|
435 |
+
<input type="text" id="replace-old" class="w-full p-2 rounded" value="left" placeholder="Text to replace">
|
436 |
+
</div>
|
437 |
+
<div>
|
438 |
+
<label class="block mb-2">Replacement Text:</label>
|
439 |
+
<input type="text" id="replace-new" class="w-full p-2 rounded" value="right" placeholder="Replacement text">
|
440 |
+
</div>
|
441 |
+
</div>
|
442 |
+
|
443 |
+
<button onclick="replaceInString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
444 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
445 |
+
</button>
|
446 |
+
|
447 |
+
<div class="mt-4">
|
448 |
+
<p class="font-medium mb-1">Result:</p>
|
449 |
+
<div id="replace-result" class="result-box p-3 rounded"></div>
|
450 |
+
</div>
|
451 |
+
|
452 |
+
<div class="mt-4 text-sm text-gray-400">
|
453 |
+
<p>Maya usage example:</p>
|
454 |
+
<pre class="bg-gray-800 p-2 rounded"><code>left_nodes = cmds.ls("*left*")
|
455 |
+
for node in left_nodes:
|
456 |
+
right_node_name = node.replace("left", "right")
|
457 |
+
duplicate_node = cmds.duplicate(node, name=right_node_name)
|
458 |
+
# Now mirror the duplicate to the right side</code></pre>
|
459 |
+
</div>
|
460 |
+
</div>
|
461 |
+
|
462 |
+
<!-- strip() -->
|
463 |
+
<div class="method-container p-4 mb-6">
|
464 |
+
<h3 class="text-xl font-semibold mb-2">.strip()</h3>
|
465 |
+
<p class="mb-3">Removes leading and trailing whitespace or specified characters. Useful for cleaning up user input or imported data.</p>
|
466 |
+
|
467 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
468 |
+
<div>
|
469 |
+
<label class="block mb-2">String (with whitespace or chars to remove):</label>
|
470 |
+
<input type="text" id="strip-input" class="w-full p-2 rounded" value=" pSphere1 " placeholder="Enter a string with whitespace">
|
471 |
+
</div>
|
472 |
+
<div>
|
473 |
+
<label class="block mb-2">Characters to Strip (optional):</label>
|
474 |
+
<input type="text" id="strip-chars" class="w-full p-2 rounded" placeholder="Enter specific chars to strip (leave empty for whitespace)">
|
475 |
+
</div>
|
476 |
+
</div>
|
477 |
+
|
478 |
+
<button onclick="stripString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
479 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
480 |
+
</button>
|
481 |
+
|
482 |
+
<div class="mt-4">
|
483 |
+
<p class="font-medium mb-1">Result:</p>
|
484 |
+
<div id="strip-result" class="result-box p-3 rounded"></div>
|
485 |
+
</div>
|
486 |
+
|
487 |
+
<div class="mt-4 text-sm text-gray-400">
|
488 |
+
<p>Maya usage example:</p>
|
489 |
+
<pre class="bg-gray-800 p-2 rounded"><code>user_input = " pCube1 " # User might add extra spaces
|
490 |
+
clean_input = user_input.strip()
|
491 |
+
if cmds.objExists(clean_input):
|
492 |
+
cmds.select(clean_input)
|
493 |
+
else:
|
494 |
+
cmds.warning("Object not found")</code></pre>
|
495 |
+
</div>
|
496 |
+
</div>
|
497 |
+
|
498 |
+
<!-- split() -->
|
499 |
+
<div class="method-container p-4 mb-6">
|
500 |
+
<h3 class="text-xl font-semibold mb-2">.split()</h3>
|
501 |
+
<p class="mb-3">Splits a string into a list using a delimiter. Perfect for parsing paths, node hierarchies, or breaking down complex names.</p>
|
502 |
+
|
503 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
504 |
+
<div>
|
505 |
+
<label class="block mb-2">String:</label>
|
506 |
+
<input type="text" id="split-input" class="w-full p-2 rounded" value="head_geo|head_eyebrows_geo|head_eyes_geo" placeholder="Enter a string">
|
507 |
+
</div>
|
508 |
+
<div>
|
509 |
+
<label class="block mb-2">Delimiter:</label>
|
510 |
+
<input type="text" id="split-delimiter" class="w-full p-2 rounded" value="|" placeholder="Enter delimiter character">
|
511 |
+
</div>
|
512 |
+
</div>
|
513 |
+
|
514 |
+
<button onclick="splitString()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
515 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
516 |
+
</button>
|
517 |
+
|
518 |
+
<div class="mt-4">
|
519 |
+
<p class="font-medium mb-1">Result:</p>
|
520 |
+
<div id="split-result" class="result-box p-3 rounded"></div>
|
521 |
+
</div>
|
522 |
+
|
523 |
+
<div class="mt-4 text-sm text-gray-400">
|
524 |
+
<p>Maya usage example:</p>
|
525 |
+
<pre class="bg-gray-800 p-2 rounded"><code>full_path = "characters|hero|skeleton|spine|neck|head"
|
526 |
+
path_components = full_path.split("|")
|
527 |
+
parent_node = path_components[-2] # "neck"
|
528 |
+
cmds.select(parent_node)</code></pre>
|
529 |
+
</div>
|
530 |
+
</div>
|
531 |
+
|
532 |
+
<!-- join() -->
|
533 |
+
<div class="method-container p-4 mb-6">
|
534 |
+
<h3 class="text-xl font-semibold mb-2">str.join()</h3>
|
535 |
+
<p class="mb-3">Joins elements of an iterable with a specified string. Useful for building paths, constructing node names, or formatting output.</p>
|
536 |
+
|
537 |
+
<div class="mb-4">
|
538 |
+
<label class="block mb-2">List of Strings (comma-separated):</label>
|
539 |
+
<input type="text" id="join-input" class="w-full p-2 rounded" value="character,rig,arm,left,01" placeholder="Enter comma-separated strings">
|
540 |
+
|
541 |
+
<label class="block mt-4 mb-2">Join Character:</label>
|
542 |
+
<input type="text" id="join-char" class="w-full p-2 rounded" value="_" placeholder="Character to join with">
|
543 |
+
</div>
|
544 |
+
|
545 |
+
<button onclick="joinStrings()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
546 |
+
<i class="fas fa-play mr-2"></i> Run Example
|
547 |
+
</button>
|
548 |
+
|
549 |
+
<div class="mt-4">
|
550 |
+
<p class="font-medium mb-1">Result:</p>
|
551 |
+
<div id="join-result" class="result-box p-3 rounded"></div>
|
552 |
+
</div>
|
553 |
+
|
554 |
+
<div class="mt-4 text-sm text-gray-400">
|
555 |
+
<p>Maya usage example:</p>
|
556 |
+
<pre class="bg-gray-800 p-2 rounded"><code>name_parts = ["character", "arm", "left", "ctrl"]
|
557 |
+
node_name = "_".join(name_parts) # "character_arm_left_ctrl"
|
558 |
+
cmds.circle(name=node_name)</code></pre>
|
559 |
+
</div>
|
560 |
+
</div>
|
561 |
+
</section>
|
562 |
+
|
563 |
+
<!-- Maya-Specific Examples -->
|
564 |
+
<section class="mb-10">
|
565 |
+
<h2 class="text-2xl font-bold text-blue-300 section-title mb-4">Maya-Specific Examples</h2>
|
566 |
+
|
567 |
+
<!-- Node Naming -->
|
568 |
+
<div class="method-container p-4 mb-6">
|
569 |
+
<h3 class="text-xl font-semibold mb-2">Node Naming Convention Tool</h3>
|
570 |
+
<p class="mb-3">Creates a Maya-style node name based on input parts. Demonstrates string concatenation and naming conventions.</p>
|
571 |
+
|
572 |
+
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-4">
|
573 |
+
<div>
|
574 |
+
<label class="block mb-2">Prefix:</label>
|
575 |
+
<select id="node-prefix" class="w-full p-2 rounded bg-gray-700 text-white">
|
576 |
+
<option value="c_">c_ (center)</option>
|
577 |
+
<option value="l_">l_ (left)</option>
|
578 |
+
<option value="r_">r_ (right)</option>
|
579 |
+
</select>
|
580 |
+
</div>
|
581 |
+
<div>
|
582 |
+
<label class="block mb-2">Body Part:</label>
|
583 |
+
<input type="text" id="node-bodypart" class="w-full p-2 rounded" value="arm" placeholder="Body part">
|
584 |
+
</div>
|
585 |
+
<div>
|
586 |
+
<label class="block mb-2">Index:</label>
|
587 |
+
<input type="number" id="node-index" class="w-full p-2 rounded" value="1" min="1" placeholder="Index number">
|
588 |
+
</div>
|
589 |
+
<div>
|
590 |
+
<label class="block mb-2">Type:</label>
|
591 |
+
<select id="node-type" class="w-full p-2 rounded bg-gray-700 text-white">
|
592 |
+
<option value="_jnt">_jnt (joint)</option>
|
593 |
+
<option value="_geo">_geo (geometry)</option>
|
594 |
+
<option value="_ctrl">_ctrl (controller)</option>
|
595 |
+
<option value="_grp">_grp (group)</option>
|
596 |
+
</select>
|
597 |
+
</div>
|
598 |
+
</div>
|
599 |
+
|
600 |
+
<button onclick="generateNodeName()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
601 |
+
<i class="fas fa-play mr-2"></i> Generate Node Name
|
602 |
+
</button>
|
603 |
+
|
604 |
+
<div class="mt-4">
|
605 |
+
<p class="font-medium mb-1">Result:</p>
|
606 |
+
<div id="maya-naming-result" class="result-box p-3 rounded"></div>
|
607 |
+
</div>
|
608 |
+
|
609 |
+
<div class="mt-4 text-sm text-gray-400">
|
610 |
+
<p>Maya usage example:</p>
|
611 |
+
<pre class="bg-gray-800 p-2 rounded"><code>def create_named_joint(side, part, index):
|
612 |
+
side_prefix = {
|
613 |
+
"left": "l_",
|
614 |
+
"right": "r_",
|
615 |
+
"center": "c_"
|
616 |
+
}.get(side, "c_")
|
617 |
+
|
618 |
+
node_name = f"{side_prefix}{part}{str(index).zfill(2)}_jnt"
|
619 |
+
return cmds.joint(name=node_name)
|
620 |
+
|
621 |
+
# Create joints with proper naming
|
622 |
+
spine_joint = create_named_joint("center", "spine", 1)
|
623 |
+
left_arm_joint = create_named_joint("left", "arm", 1)</code></pre>
|
624 |
+
</div>
|
625 |
+
</div>
|
626 |
+
|
627 |
+
<!-- Path Manipulation -->
|
628 |
+
<div class="method-container p-4 mb-6">
|
629 |
+
<h3 class="text-xl font-semibold mb-2">Maya File Path Manipulation</h3>
|
630 |
+
<p class="mb-3">Extract and modify parts of a Maya file path. Demonstrates how to work with file paths in Maya scripts.</p>
|
631 |
+
|
632 |
+
<div class="mb-4">
|
633 |
+
<label class="block mb-2">Maya File Path:</label>
|
634 |
+
<input type="text" id="filepath-input" class="w-full p-2 rounded" value="C:/Projects/Character/scenes/character_model_v001.mb" placeholder="Enter a file path">
|
635 |
+
</div>
|
636 |
+
|
637 |
+
<button onclick="analyzeFilePath()" class="play-button px-4 py-2 rounded text-white flex items-center">
|
638 |
+
<i class="fas fa-play mr-2"></i> Analyze Path
|
639 |
+
</button>
|
640 |
+
|
641 |
+
<div class="mt-4">
|
642 |
+
<p class="font-medium mb-1">Result:</p>
|
643 |
+
<div id="filepath-result" class="result-box p-3 rounded whitespace-pre-line"></div>
|
644 |
+
</div>
|
645 |
+
|
646 |
+
<div class="mt-4 text-sm text-gray-400">
|
647 |
+
<p>Maya usage example:</p>
|
648 |
+
<pre class="bg-gray-800 p-2 rounded"><code>def increment_version(file_path):
|
649 |
+
# Split the path to get the directory and filename
|
650 |
+
components = file_path.replace("\\", "/").split("/")
|
651 |
+
directory = "/".join(components[:-1])
|
652 |
+
file_name = components[-1]
|
653 |
+
|
654 |
+
# Find version number
|
655 |
+
if "_v" in file_name:
|
656 |
+
base_name, version_ext = file_name.split("_v")
|
657 |
+
version_num, ext = version_ext.split(".")
|
658 |
+
|
659 |
+
# Increment version
|
660 |
+
new_version = str(int(version_num) + 1).zfill(len(version_num))
|
661 |
+
new_file_name = f"{base_name}_v{new_version}.{ext}"
|
662 |
+
|
663 |
+
# Join to get new path
|
664 |
+
new_path = f"{directory}/{new_file_name}"
|
665 |
+
return new_path
|
666 |
+
|
667 |
+
return file_path
|
668 |
+
|
669 |
+
current_path = cmds.file(q=True, sn=True)
|
670 |
+
new_path = increment_version(current_path)
|
671 |
+
cmds.file(rename=new_path)
|
672 |
+
cmds.file(save=True)</code></pre>
|
673 |
+
</div>
|
674 |
+
</div>
|
675 |
+
</section>
|
676 |
+
</main>
|
677 |
+
|
678 |
+
<footer class="mt-12 text-center text-gray-500 text-sm">
|
679 |
+
<p>Interactive Python String Methods for Autodesk Maya</p>
|
680 |
+
<p class="mt-2">Use these examples in Maya's Script Editor for practical applications</p>
|
681 |
+
</footer>
|
682 |
+
|
683 |
+
<script>
|
684 |
+
// Basic String Operations
|
685 |
+
function concatStrings() {
|
686 |
+
const str1 = document.getElementById('concat-input1').value;
|
687 |
+
const str2 = document.getElementById('concat-input2').value;
|
688 |
+
const result = str1 + str2;
|
689 |
+
|
690 |
+
const resultBox = document.getElementById('concat-result');
|
691 |
+
resultBox.innerHTML = `Combined string: "${result}"<br>Python: str1 + str2`;
|
692 |
+
}
|
693 |
+
|
694 |
+
function indexString() {
|
695 |
+
const str = document.getElementById('index-input').value;
|
696 |
+
const index = parseInt(document.getElementById('index-position').value);
|
697 |
+
|
698 |
+
const resultBox = document.getElementById('index-result');
|
699 |
+
|
700 |
+
if (index < 0 || index >= str.length) {
|
701 |
+
resultBox.innerHTML = `Error: Index ${index} is out of range (0 to ${str.length - 1})`;
|
702 |
+
return;
|
703 |
+
}
|
704 |
+
|
705 |
+
const result = str[index];
|
706 |
+
resultBox.innerHTML = `Character at index ${index}: "${result}"<br>Python: str[${index}]`;
|
707 |
+
}
|
708 |
+
|
709 |
+
function sliceString() {
|
710 |
+
const str = document.getElementById('slice-input').value;
|
711 |
+
const start = parseInt(document.getElementById('slice-start').value);
|
712 |
+
const end = parseInt(document.getElementById('slice-end').value);
|
713 |
+
|
714 |
+
const resultBox = document.getElementById('slice-result');
|
715 |
+
|
716 |
+
if (start < 0 || start > str.length) {
|
717 |
+
resultBox.innerHTML = `Error: Start index ${start} is out of range (0 to ${str.length})`;
|
718 |
+
return;
|
719 |
+
}
|
720 |
+
|
721 |
+
if (end < start || end > str.length) {
|
722 |
+
resultBox.innerHTML = `Error: End index ${end} is invalid (should be between ${start} and ${str.length})`;
|
723 |
+
return;
|
724 |
+
}
|
725 |
+
|
726 |
+
const result = str.slice(start, end);
|
727 |
+
resultBox.innerHTML = `Slice from index ${start} to ${end}: "${result}"<br>Python: str[${start}:${end}]`;
|
728 |
+
}
|
729 |
+
|
730 |
+
// Case Methods
|
731 |
+
function upperCaseString() {
|
732 |
+
const str = document.getElementById('upper-input').value;
|
733 |
+
const result = str.toUpperCase();
|
734 |
+
|
735 |
+
const resultBox = document.getElementById('upper-result');
|
736 |
+
resultBox.innerHTML = `Uppercase: "${result}"<br>Python: str.upper()`;
|
737 |
+
}
|
738 |
+
|
739 |
+
function lowerCaseString() {
|
740 |
+
const str = document.getElementById('lower-input').value;
|
741 |
+
const result = str.toLowerCase();
|
742 |
+
|
743 |
+
const resultBox = document.getElementById('lower-result');
|
744 |
+
resultBox.innerHTML = `Lowercase: "${result}"<br>Python: str.lower()`;
|
745 |
+
}
|
746 |
+
|
747 |
+
function titleCaseString() {
|
748 |
+
const str = document.getElementById('title-input').value;
|
749 |
+
// JavaScript doesn't have a direct title() equivalent, so implement manually
|
750 |
+
const result = str.toLowerCase().replace(/(?:^|\s)\S/g, function(a) {
|
751 |
+
return a.toUpperCase();
|
752 |
+
});
|
753 |
+
|
754 |
+
const resultBox = document.getElementById('title-result');
|
755 |
+
resultBox.innerHTML = `Title case: "${result}"<br>Python: str.title()`;
|
756 |
+
}
|
757 |
+
|
758 |
+
function capitalizeString() {
|
759 |
+
const str = document.getElementById('capitalize-input').value;
|
760 |
+
// JavaScript doesn't have a direct capitalize() equivalent, implement manually
|
761 |
+
const result = str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
762 |
+
|
763 |
+
const resultBox = document.getElementById('capitalize-result');
|
764 |
+
resultBox.innerHTML = `Capitalized: "${result}"<br>Python: str.capitalize()`;
|
765 |
+
}
|
766 |
+
|
767 |
+
// Search Methods
|
768 |
+
function findInString() {
|
769 |
+
const str = document.getElementById('find-input').value;
|
770 |
+
const substr = document.getElementById('find-substring').value;
|
771 |
+
const result = str.indexOf(substr);
|
772 |
+
|
773 |
+
const resultBox = document.getElementById('find-result');
|
774 |
+
if (result === -1) {
|
775 |
+
resultBox.innerHTML = `Substring "${substr}" not found.<br>Python: str.find("${substr}") returned -1`;
|
776 |
+
} else {
|
777 |
+
resultBox.innerHTML = `Substring "${substr}" found at index ${result}.<br>Python: str.find("${substr}")`;
|
778 |
+
}
|
779 |
+
}
|
780 |
+
|
781 |
+
function checkStartsWith() {
|
782 |
+
const str = document.getElementById('startswith-input').value;
|
783 |
+
const prefix = document.getElementById('startswith-prefix').value;
|
784 |
+
const result = str.startsWith(prefix);
|
785 |
+
|
786 |
+
const resultBox = document.getElementById('startswith-result');
|
787 |
+
resultBox.innerHTML = `Does "${str}" start with "${prefix}"? ${result}<br>Python: str.startswith("${prefix}")`;
|
788 |
+
}
|
789 |
+
|
790 |
+
function checkEndsWith() {
|
791 |
+
const str = document.getElementById('endswith-input').value;
|
792 |
+
const suffix = document.getElementById('endswith-suffix').value;
|
793 |
+
const result = str.endsWith(suffix);
|
794 |
+
|
795 |
+
const resultBox = document.getElementById('endswith-result');
|
796 |
+
resultBox.innerHTML = `Does "${str}" end with "${suffix}"? ${result}<br>Python: str.endswith("${suffix}")`;
|
797 |
+
}
|
798 |
+
|
799 |
+
// Modification Methods
|
800 |
+
function replaceInString() {
|
801 |
+
const str = document.getElementById('replace-input').value;
|
802 |
+
const oldText = document.getElementById('replace-old').value;
|
803 |
+
const newText = document.getElementById('replace-new').value;
|
804 |
+
const result = str.replace(oldText, newText);
|
805 |
+
|
806 |
+
const resultBox = document.getElementById('replace-result');
|
807 |
+
resultBox.innerHTML = `Result: "${result}"<br>Python: str.replace("${oldText}", "${newText}")`;
|
808 |
+
}
|
809 |
+
|
810 |
+
function stripString() {
|
811 |
+
const str = document.getElementById('strip-input').value;
|
812 |
+
const chars = document.getElementById('strip-chars').value;
|
813 |
+
|
814 |
+
let result;
|
815 |
+
if (chars) {
|
816 |
+
// JavaScript doesn't have direct strip() with chars, simulate it
|
817 |
+
let startIndex = 0;
|
818 |
+
let endIndex = str.length - 1;
|
819 |
+
|
820 |
+
// Find start index (first char not in the chars)
|
821 |
+
while (startIndex <= endIndex && chars.includes(str[startIndex])) {
|
822 |
+
startIndex++;
|
823 |
+
}
|
824 |
+
|
825 |
+
// Find end index (last char not in the chars)
|
826 |
+
while (endIndex >= startIndex && chars.includes(str[endIndex])) {
|
827 |
+
endIndex--;
|
828 |
+
}
|
829 |
+
|
830 |
+
result = str.slice(startIndex, endIndex + 1);
|
831 |
+
} else {
|
832 |
+
result = str.trim();
|
833 |
+
}
|
834 |
+
|
835 |
+
const resultBox = document.getElementById('strip-result');
|
836 |
+
if (chars) {
|
837 |
+
resultBox.innerHTML = `Result: "${result}"<br>Python: str.strip("${chars}")`;
|
838 |
+
} else {
|
839 |
+
resultBox.innerHTML = `Result: "${result}"<br>Python: str.strip()`;
|
840 |
+
}
|
841 |
+
}
|
842 |
+
|
843 |
+
function splitString() {
|
844 |
+
const str = document.getElementById('split-input').value;
|
845 |
+
const delimiter = document.getElementById('split-delimiter').value;
|
846 |
+
const result = str.split(delimiter);
|
847 |
+
|
848 |
+
const resultBox = document.getElementById('split-result');
|
849 |
+
resultBox.innerHTML = `Split into list: [${result.map(item => `"${item}"`).join(', ')}]<br>Python: str.split("${delimiter}")`;
|
850 |
+
}
|
851 |
+
|
852 |
+
function joinStrings() {
|
853 |
+
const strList = document.getElementById('join-input').value.split(',');
|
854 |
+
const joinChar = document.getElementById('join-char').value;
|
855 |
+
const result = strList.join(joinChar);
|
856 |
+
|
857 |
+
const resultBox = document.getElementById('join-result');
|
858 |
+
resultBox.innerHTML = `Joined string: "${result}"<br>Python: "${joinChar}".join([${strList.map(item => `"${item}"`).join(', ')}])`;
|
859 |
+
}
|
860 |
+
|
861 |
+
// Maya-Specific Examples
|
862 |
+
function generateNodeName() {
|
863 |
+
const prefix = document.getElementById('node-prefix').value;
|
864 |
+
const bodyPart = document.getElementById('node-bodypart').value;
|
865 |
+
const index = document.getElementById('node-index').value;
|
866 |
+
const type = document.getElementById('node-type').value;
|
867 |
+
|
868 |
+
// Format index with leading zero if needed
|
869 |
+
const formattedIndex = index < 10 ? `0${index}` : index;
|
870 |
+
|
871 |
+
const nodeName = `${prefix}${bodyPart}${formattedIndex}${type}`;
|
872 |
+
|
873 |
+
const resultBox = document.getElementById('maya-naming-result');
|
874 |
+
resultBox.innerHTML = `Maya node name: "${nodeName}"<br>Python: f"{prefix}{bodyPart}{str(index).zfill(2)}{type}"`;
|
875 |
+
}
|
876 |
+
|
877 |
+
function analyzeFilePath() {
|
878 |
+
const filePath = document.getElementById('filepath-input').value;
|
879 |
+
|
880 |
+
// Replace Windows backslashes with forward slashes
|
881 |
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
882 |
+
|
883 |
+
// Split into directory and filename
|
884 |
+
const lastSlashIndex = normalizedPath.lastIndexOf('/');
|
885 |
+
const directory = normalizedPath.substring(0, lastSlashIndex);
|
886 |
+
const filename = normalizedPath.substring(lastSlashIndex + 1);
|
887 |
+
|
888 |
+
// Extract base name and extension
|
889 |
+
const lastDotIndex = filename.lastIndexOf('.');
|
890 |
+
const basename = filename.substring(0, lastDotIndex);
|
891 |
+
const extension = filename.substring(lastDotIndex + 1);
|
892 |
+
|
893 |
+
// Extract version if present (_v000 pattern)
|
894 |
+
let version = "None";
|
895 |
+
let versionNumber = "None";
|
896 |
+
let basePart = basename;
|
897 |
+
|
898 |
+
const versionMatch = basename.match(/(.*)_v(\d+)$/);
|
899 |
+
if (versionMatch) {
|
900 |
+
basePart = versionMatch[1];
|
901 |
+
version = `v${versionMatch[2]}`;
|
902 |
+
versionNumber = versionMatch[2];
|
903 |
+
}
|
904 |
+
|
905 |
+
// Create incremented version
|
906 |
+
let nextVersion = "None";
|
907 |
+
if (versionNumber !== "None") {
|
908 |
+
const numDigits = versionNumber.length;
|
909 |
+
const nextNum = parseInt(versionNumber) + 1;
|
910 |
+
nextVersion = `v${nextNum.toString().padStart(numDigits, '0')}`;
|
911 |
+
}
|
912 |
+
|
913 |
+
// Create next version path
|
914 |
+
let nextVersionPath = "None";
|
915 |
+
if (nextVersion !== "None") {
|
916 |
+
nextVersionPath = `${directory}/${basePart}_${nextVersion}.${extension}`;
|
917 |
+
}
|
918 |
+
|
919 |
+
const resultBox = document.getElementById('filepath-result');
|
920 |
+
resultBox.innerHTML = `Directory: ${directory}
|
921 |
+
Filename: ${filename}
|
922 |
+
Base Name: ${basename}
|
923 |
+
Extension: ${extension}
|
924 |
+
Clean Base: ${basePart}
|
925 |
+
Version: ${version}
|
926 |
+
Next Version: ${nextVersion}
|
927 |
+
Next Path: ${nextVersionPath}
|
928 |
+
|
929 |
+
# Python in Maya:
|
930 |
+
directory = "${directory}"
|
931 |
+
filename = "${filename}"
|
932 |
+
basename = "${basename}"
|
933 |
+
extension = "${extension}"
|
934 |
+
clean_base = "${basePart}"
|
935 |
+
version = "${version}"
|
936 |
+
next_version = "${nextVersion}"
|
937 |
+
next_path = "${nextVersionPath}"`;
|
938 |
+
}
|
939 |
+
|
940 |
+
// Initialize all examples on page load
|
941 |
+
document.addEventListener('DOMContentLoaded', function() {
|
942 |
+
concatStrings();
|
943 |
+
indexString();
|
944 |
+
sliceString();
|
945 |
+
upperCaseString();
|
946 |
+
lowerCaseString();
|
947 |
+
titleCaseString();
|
948 |
+
capitalizeString();
|
949 |
+
findInString();
|
950 |
+
checkStartsWith();
|
951 |
+
checkEndsWith();
|
952 |
+
replaceInString();
|
953 |
+
stripString();
|
954 |
+
splitString();
|
955 |
+
joinStrings();
|
956 |
+
generateNodeName();
|
957 |
+
analyzeFilePath();
|
958 |
+
});
|
959 |
+
</script>
|
960 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=subbuadd/pystrings" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
961 |
</html>
|