Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Duplicate Wall Finish from another Project

6 REPLIES 6
Reply
Message 1 of 7
Ryan_Daley
559 Views, 6 Replies

Duplicate Wall Finish from another Project

I'm trying to duplicate the finish material from another project, and apply it to the user selected WallType in the current project.  I am able to programmatically modify the WallType, however, I can't figure out how to use materials from other projects.  

 

CompoundStructure selectedCS = selectedWall.WallType.GetCompoundStructure();
if (selectedCS == null)
    return;
try
{
    selectedCS.SetMaterialId(0, materialId);
    selectedWall.WallType.SetCompoundStructure(selectedCS); 
}
catch (Exception ex)
{
    SimpleLog.Log(ex);
}

 

 

In order to get the MaterialId from another project, I've tried to duplicate a WallType using Jeremy Tammik's example.  However, in this example, the focus is on duplicating the properties, and not on the CompoundStructure.   

 

However, I thought I could still open a WallType from the other document that contains the desired material, and simply use the MaterialId of that WallType. 

 

 WallType wallType = null;

FilteredElementCollector wallTypes
    = new FilteredElementCollector(docHasFamily)
    .OfClass(typeof(WallType));


foreach (WallType wt in wallTypes)
{
    string name = wt.Name;


    if (name.Equals(wallTypeName))
    {
        wallType = wt;
        break;
    }
}

selectedCS.SetMaterialId(0, wallType.GetCompoundStructure().GetLayers()[0].MaterialId);
selectedWall.WallType.SetCompoundStructure(selectedCS); 

 



It doesn't work.  So I guess I need to figure out how I can load the material from the other document into my current document. 
 

Labels (3)
6 REPLIES 6
Message 2 of 7
jeremy_tammik
in reply to: Ryan_Daley

Maybe you can use one of the CopyElement methods of the ElementTransformUtils class on the Material object?

  

https://www.revitapidocs.com/2023/82e737d5-fda4-bc10-6099-88999cd51300.htm

  

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 7
Ryan_Daley
in reply to: jeremy_tammik

It returns null.  I'm not sure if its because I am trying to copy from another Document, or if its because I am trying to copy a Material.  It doesn't make much sense to copy a Material or a WallType using the ElementTransformUtils.CopyElement() method because every overload requires an XYZ location to copy to. 

 

ryanL3KA6_0-1683105665981.png

 

 

 

ICollection<ElementId> materialCopied = ElementTransformUtils.CopyElement(docHasFamily, materialId, new XYZ());

 

 

 

 

My plan was to mimic your Adding New Materials From List method.  I could manually copy the Color and the SurfacePattern of the material in the other Document.  However, this only works if the SurfacePatternId already exists in the active Document I am trying to copy to.          

This seems especially relevant if I want to copy the .png that is being used to set the Render Appearance of the Material.
Your method will work for many of the Material Properties, but it seems that many of the Properties that are defined by an Element can simply not be copied from another Document.  I hope I am wrong.  

Message 4 of 7
jeremy_tammik
in reply to: Ryan_Daley

Oh dear. Sorry about that. Yes, materials are a bit tricky, trying to reuse standard material stuff across all products, made by completely different teams... here are the possibilities that I am aware of:

  

   

I don't know how to best address your particular problem. I asked the development team for you.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 7
Ryan_Daley
in reply to: jeremy_tammik

Thank you very much Jeremy.

It seems I am not invited to the slack discussion:

ryanL3KA6_0-1683107258492.png

 

Message 6 of 7
jeremy_tammik
in reply to: Ryan_Daley

Nope, sorry, that is an internal link for my own use. Saves me keeping notes of everything elsewhere.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 7 of 7
jeremy_tammik
in reply to: Ryan_Daley

A thought from the devteam: Instead of moving the material, move an element which utilises the material.
 
  1. In the source model, generate a new floor type with 1 layer for every material they want to transfer, assigning the materials on a 1:1 basis (using a floor as it feels less likely to cause recalculation issues than a wall).
  2. Create a minimal instance of that floor offset 10 units below the lowest level.
  3. Use the copy element method to push the floor between projects.
  4. Roll back the transaction in the source model.
  5. Commit the transaction in the target model, then delete the floor.
  
Might not bring the materials over, but this does work in the UI if memory serves.
  
Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report