Writing wall builtin parameter (width) to a shared parameter for wall types

Writing wall builtin parameter (width) to a shared parameter for wall types

msweeneyPES
Participant Participant
2,548 Views
4 Replies
Message 1 of 5

Writing wall builtin parameter (width) to a shared parameter for wall types

msweeneyPES
Participant
Participant

I am fairly new to coding and the Revit API and I'm trying to write what should be a pretty basic Macro in C# to take the built in parameter of wall width and write it to a taggable shared parameter. I have been struggling to make this work. This seems so simple and I can make it work in Dynamo without an issue. I've tried getting the built in parameter, tried it as an element. i'm really struggling with what seems to be fairly easy. any pointers would be appreciated.

 

//collect all wall types
			FilteredElementCollector wallTypeColl = new FilteredElementCollector(doc);
			wallTypeColl.OfClass(typeof(WallType));

			//get basic walls
			foreach(WallType wt in wallTypeColl)
			{
				dblWidth=wt.Width;
				wallsBasic.Add(dblWidth.ToString());
				wt.LookupParameter(wallThickness).Set(dblWidth);
			}
0 Likes
Accepted solutions (1)
2,549 Views
4 Replies
Replies (4)
Message 2 of 5

JimJia
Alumni
Alumni

Dear msweeney,

 

I am afraid that I am not quite follow your question.

Could you describe what is the problem you met?

You cannot set the shared parameter value or there is any exception when you run the code or anything else?

 

Per your codes, you get wall type, find its "wallThickness" parameter and set its value to wt.Width.

 

we can give you some help if we can get some more details.

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: [email protected]
0 Likes
Message 3 of 5

BenoitE&A
Collaborator
Collaborator

Hi,

I have been struggling with that issue for a while.

The width parameter is a parameter of the WallType not of the Wall itself.

Try 

myWall.WallType.Width

as parameter on which you base your search instead of a direct parameter of the wall itself (I have tried all of them with no success).

 

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 4 of 5

JimJia
Alumni
Alumni

 

hi msweeney,

 

As Benoit mentioned:

"The width parameter is a parameter of the WallType not of the Wall itself." 

 

So you want to set width to Wall itself, you need to do as follows:

1. define a shared parameter to Wall 

2. copy the width value from WallType to shared parameter.

 

As how to create a shared parameter, you can refer to the attachment.

It is a SDK sample project.

The core codes to create shared parameter as below:

 

// cache application handle
                Autodesk.Revit.ApplicationServices.Application revitApp = m_commandData.Application.Application;

                // prepare shared parameter file
                m_commandData.Application.Application.SharedParametersFilename = paramFile;

                // open shared parameter file
                DefinitionFile parafile = revitApp.OpenSharedParameterFile();

                // create a group
                DefinitionGroup apiGroup = parafile.Groups.Create("SDKSampleRoomScheduleGroup");

                // create a visible "External Room ID" of text type.
                ExternalDefinitionCreationOptions ExternalDefinitionCreationOptions = new ExternalDefinitionCreationOptions(RoomsData.SharedParam, ParameterType.Text);
                Definition roomSharedParamDef = apiGroup.Definitions.Create(ExternalDefinitionCreationOptions);

                // get Rooms category
                Category roomCat = m_commandData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Rooms);
                CategorySet categories = revitApp.Create.NewCategorySet();
                categories.Insert(roomCat);

                // insert the new parameter
                InstanceBinding binding = revitApp.Create.NewInstanceBinding(categories);
                m_commandData.Application.ActiveUIDocument.Document.ParameterBindings.Insert(roomSharedParamDef, binding);

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: [email protected]
0 Likes
Message 5 of 5

msweeneyPES
Participant
Participant
Accepted solution

The answer seemed to be more in the collection of walls. Adjusting the filtered element collector to this 

 

//collect all wall types
            FilteredElementCollector wallTypeColl = new FilteredElementCollector(doc);
            wallTypeColl.OfClass(typeof(WallType)).OfCategory(BuiltInCategory.OST_Walls);

 

allowed the previously posted code to work as intended. 

 

Thanks. 

0 Likes