Message 1 of 10
		
    
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a list of Walls and I want to create a new View3D with the same walls but containing only the "Structure" function layers. I've implemented the code below.
I've realized that I need to duplicate the WallTypes and copy a new wall with just the filtered layers in the same location, because otherwise the original Walls & WallTypes will be modified. The code below works, but it's extremely slow for big models. Is there any way to optimize the process?
...
/* Create new View3D and make it active */
...
ICollection<ElementId> visibleIds = new List<ElementId>();                    
foreach(Wall wall in wallList)
{
	// Get WallType and CompoundStructure
	WallType wallType = wall.WallType;
	CompoundStructure compoundStructure = wallType.GetCompoundStructure();
	// Copy wall in the same position
	ICollection<ElementId> newWallId = ElementTransformUtils.CopyElement(ViewModel.CurrentDocument, wall.Id, new XYZ(0, 0, 0));
	// Duplicate WallType
	Wall newWall = ViewModel.CurrentDocument.GetElement(newWallId.ElementAt(0)) as Wall;
	WallType newWallType = newWall.WallType.Duplicate(newWall.WallType.Name + GenerateRandomSuffix()) as WallType;
	CompoundStructure newCompoundStructure = newWallType.GetCompoundStructure();
	IList<CompoundStructureLayer> newWallLayers = newCompoundStructure.GetLayers();
	
	// Filter just Structure layers and assign to new WallType
	IList<CompoundStructureLayer> filteredLayers =
		(from o in newWallLayers where o.Function.ToString() == "Structure" select o).ToList();
	newCompoundStructure.SetLayers(filteredLayers);
	newWallType.SetCompoundStructure(newCompoundStructure);
	newWall.WallType = newWallType;
	// Add walls to visible elements list
	visibleIds.Add(newWallId.ElementAt(0));
}
...
/* Hide all elements in View3D and just make "visibleIds" visible */
...
Solved! Go to Solution.
 
             
		
			 
		
			 
		
			 
					
				
		
 
		
			 Developer Advocacy and Support +
 Developer Advocacy and Support +  
					
				
I summarised the functionality that you implement and thought my list of steps might be of interest to other as well, so here goes:
Cheers,
Jeremy