How to resize certain Revit families using C# code?

How to resize certain Revit families using C# code?

konrad.pEGTVF
Contributor Contributor
226 Views
1 Reply
Message 1 of 2

How to resize certain Revit families using C# code?

konrad.pEGTVF
Contributor
Contributor

I wonder how can I resize, let's say a wall or a chair.

I would like to create a new one, or rather duplicate a family and resize the duplicated one to a different size.

How can I do that?

Thanks in advance,

0 Likes
227 Views
1 Reply
Reply (1)
Message 2 of 2

Mohamed_Arshad
Advisor
Advisor

Hi @konrad.pEGTVF 

To Duplicate any Element, you have to follow the below steps,

1. Get the Element you want to duplicate.

2. Duplicate with New Name.

3. Get the Parameter ex. Wall Height or Width.

4. Change the parameter in the duplicated type.

 

Reference Code:

            //Filter Wall Type
            WallType wallType = new FilteredElementCollector(doc)
                .OfClass(typeof(WallType))
                .Where(x => x.Name.Equals("Wall-Fnd_440Blk"))
                .First() as WallType;

            //Variable
            WallType newWallType = null;

            //Duplicate Wall Type
            using (Transaction createWallType = new Transaction(doc, "Create new Wall Type"))
            {
                createWallType.Start();

                //Duplicate Wall Type
                newWallType = wallType.Duplicate("New Automation Wall Type") as WallType;

                createWallType.Commit();
            }

            //Change Wall Width
            CompoundStructure structure = newWallType.GetCompoundStructure();

            using (Transaction changeWidth=new Transaction(doc,"Change Width"))
            {
                changeWidth.Start();

                structure.SetLayerWidth(0, 500 / 304.8);

                //Set Edited Structure to Wall Type.
                newWallType.SetCompoundStructure(structure);


                changeWidth.Commit();
            }

 

Hope this will Helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes