# Create A New Shape Within Existing Object

**URL:** https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514
**Category:** Maya
**Tags:** mel
**Created:** [May 14, 2008, 4:06am UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514 "2008-05-14T04:06:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cycloverid](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@cycloverid](https://forum.highend3d.com/u/cycloverid)
#### Post date: [May 14, 2008, 4:06am UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514/1 "2008-05-14T04:06:24Z")

</div>

Is it possible to create a new shape from an existing maya object in MEL?

Example: Say I create a polyCube and add a bunch of attributes to it. What I want to do is create an object with the same exact name and all the same attributes but instead with a polySphere. Ideally I'd want to use the same object but merely replace the shape node / input (whatever it is) with the polySphere.

What would the code look like to perform this operation?

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 14, 2008, 8:12am UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514/2 "2008-05-14T08:12:37Z")

</div>

Open your hypegraph delete the connection out form the cubr creation. put in a sphere creation node in place. Thats it.

---

<div class="post-metadata">

### Author: ![cycloverid](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@cycloverid](https://forum.highend3d.com/u/cycloverid)
#### Post date: [May 14, 2008, 12:20pm UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514/3 "2008-05-14T12:20:40Z")

</div>

How about in MEL?

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 14, 2008, 2:02pm UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514/4 "2008-05-14T14:02:45Z")

</div>

Do it by hand and look at what maya echoes.... that generates the code for you (and yes that is how i know what the mel, for whatever happens to be. So writing code you can as easily echo yourself is a bit obsolete). So yes thet is a mel description.

Tough post maya 8.0 theres a new mel command that can swap 2 nodes in the network called nodeCast thet does this but it can also fail miserably. Can make thsi a little less painfull to do. But basically it just kills 4 lines of code form a total of 6 so no biggie.

---

<div class="post-metadata">

### Author: ![cycloverid](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@cycloverid](https://forum.highend3d.com/u/cycloverid)
#### Post date: [May 14, 2008, 9:18pm UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514/5 "2008-05-14T21:18:23Z")

</div>

Cool, thanks. So I looked at the echoed commands and the code looks like this:  
(given that you create a cube and a sphere pCube1 and pSphere1 and want to replace the cube shape with the sphere shape)

disconnectAttr polyCube1.output |pCube1|pCubeShape1.inMesh;  
disconnectAttr polySphere1.output |pSphere1|pSphereShape1.inMesh;  
connectAttr -f polySphere1.output pCubeShape1.inMesh;  
delete pSphere1;  
delete polyCube1;

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 15, 2008, 10:54am UTC](https://forum.highend3d.com/t/create-a-new-shape-within-existing-object/1514/6 "2008-05-15T10:54:47Z")

</div>

you can streamline it abit by just creating the relevant node with create node instead of creating the dag for the sphere. But tahts about it.
