# Function WithDisplacement problem

**URL:** <https://discourse.mcneel.com/t/function-withdisplacement-problem/100058>\
**Category:** Rhino Developer\
**Created:** [April 14, 2020, 8:38am UTC](https://discourse.mcneel.com/t/function-withdisplacement-problem/100058 "2020-04-14T08:38:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jerry1/32/768458_2.png) [@jerry1](https://discourse.mcneel.com/u/jerry1)\
**Post date:** [April 14, 2020, 8:38am UTC](https://discourse.mcneel.com/t/function-withdisplacement-problem/100058/1 "2020-04-14T08:38:41Z")

</div>

Hello every one, I attempt to using the following function to extrude a mesh.

```auto
Public Function WithDisplacement (displacement As MeshDisplacementInfo) As Mesh
    Dim k As Rhino.Geometry.MeshDisplacementInfo
    k.ChannelNumber = 1
    k.BlackMove() = 3
    Dim sdd As Mesh
    sdd = msh(0).WithDisplacement(k)
    RhinoDoc.ActiveDoc.Objects.AddMesh(sdd)
    RhinoDoc.ActiveDoc.Views.Redraw()

```

But the result show me that k is nothing? How to solve this problem?

thanks~~

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/772741_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [April 14, 2020, 11:54pm UTC](https://discourse.mcneel.com/t/function-withdisplacement-problem/100058/2 "2020-04-14T23:54:30Z")

</div>

Hi @jerry1,

Does this helps?

[https://developer.rhino3d.com/api/RhinoCommon/html/M\_Rhino\_Geometry\_MeshDisplacementInfo\_\_ctor.htm](https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_MeshDisplacementInfo__ctor.htm)

– Dale

---

<div class="post-metadata">

**Author:** ![jerry1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jerry1/32/768458_2.png) [@jerry1](https://discourse.mcneel.com/u/jerry1)\
**Post date:** [April 15, 2020, 1:10am UTC](https://discourse.mcneel.com/t/function-withdisplacement-problem/100058/3 "2020-04-15T01:10:00Z")

</div>

Thanks. But I still have a problem. I modify my code:

```
    Dim s1 As Rhino.Render.RenderTexture
    Dim s2 As Rhino.Render.TextureMapping
    Dim k As New Rhino.Geometry.MeshDisplacementInfo(s1, s2)
    k.ChannelNumber = 1
    k.BlackMove = 3
    Dim sdd As Mesh
    sdd = msh(0).WithDisplacement(k)
    RhinoDoc.ActiveDoc.Objects.AddMesh(sdd)
    RhinoDoc.ActiveDoc.Views.Redraw()

    and the msh(0) already be added texture(see the figure). but I do not 
    know how to give s1 s2 value, how to do? many thanks. 

    ![r1|472x355](upload://kOnN9O5zgR6teIcVz643tAGPZe.jpeg)
```

---

<div class="post-metadata">

**Author:** ![jerry1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jerry1/32/768458_2.png) [@jerry1](https://discourse.mcneel.com/u/jerry1)\
**Post date:** [April 15, 2020, 1:10am UTC](https://discourse.mcneel.com/t/function-withdisplacement-problem/100058/4 "2020-04-15T01:10:57Z")

</div>

![r1](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/0/2/025a4841203d8766862858faff710df1498e5eb0.jpeg)

---

<div class="post-metadata">

**Author:** ![jerry1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jerry1/32/768458_2.png) [@jerry1](https://discourse.mcneel.com/u/jerry1)\
**Post date:** [April 16, 2020, 6:33am UTC](https://discourse.mcneel.com/t/function-withdisplacement-problem/100058/5 "2020-04-16T06:33:41Z")

</div>

I think that the problem has be solved through modifying the code:

```
    Dim objj As Rhino.DocObjects.RhinoObject
    objj = meshObjRefs(0).Object
    Dim sindex As Integer
    sindex = objj.Attributes.MaterialIndex
    Dim matt As Rhino.DocObjects.Material
    matt = RhinoDoc.ActiveDoc.Materials(sindex)
    '
    Dim s1 As Rhino.Render.RenderTexture
    Dim s2 As Rhino.Render.TextureMapping
    '
    s1 = matt.RenderMaterial.GetTextureFromUsage(Rhino.Render.RenderMaterial.StandardChildSlots.Diffuse)

    '
    Dim k11() As Integer
    k11 = objj.GetTextureChannels()
    s2 = objj.GetTextureMapping(k11(0))

    '
    Dim k As New Rhino.Geometry.MeshDisplacementInfo(s1, s2)
    k.BlackMove = 0.5
    k.FaceLimit = 10000000
    Dim sdd As Mesh
    msh = kpk.Item(0).Geometry
    sdd = msh.WithDisplacement(k)
    RhinoDoc.ActiveDoc.Objects.AddMesh(sdd)
    RhinoDoc.ActiveDoc.Views.Redraw()

   but when I execute the withDisplacement(k) function.....appear the warning 
   message" -- mesh memory limit hit "? could anyone help me?

```

 ![e11](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/f/3f3ac9faf1a2fc325e031cbcd48ca602928940b4.jpeg)
