how to swap a mesh using an array

I am trying to swap an object in a scene using code. I have successfully done it with materials but some objects require the whole mesh to be changed. can someone help me please my code so far is:

public var chairs : Mesh[];


function ChangeChair(inx : int){
	var meshf : Mesh = GetComponent(MeshFilter).mesh;
	meshf.MeshFilter.mesh = chairs[inx];
}

function OnGUI(){
	if (GUI.Button (Rect (20,100,80,20), "Chair 1")) {
		ChangeChair(0);
	}
	if (GUI.Button (Rect (20,120,80,20), "Chair 2")) {
		ChangeChair(1);
	}
}

Your variable meshf contains the mesh itself, not the MeshFilter. And in the second line you try to access the MeshFilter of the mesh, but a mesh doesn’t have a MeshFilter, however a MeshFilter has a mesh.
What about this:

function ChangeChair(inx : int){
    var meshf : MeshFilter = GetComponent(MeshFilter);
    meshf.mesh = chairs[inx];
}

meshf contains the MeshFilter and in the second line the mesh of this filter is assigned.
Hope it works :smiley: