Changing parameter values

Changing parameter values

Anonymous
Not applicable
4,278 Views
5 Replies
Message 1 of 6

Changing parameter values

Anonymous
Not applicable
Hello All,
I need help. I want to write a code in c# that will enable me change element parameters. E.g. if i have an element id of 14960, how do i access the element, access the element parameters and access the parameter called "Comments" so that if a write a value for comments, i can see it in the element properties in revit. Pls help.
I have already started by writing a code using the API and "external application: on startup". Pls i need just a sample code to show me how to change the value of an element parameter.
0 Likes
4,279 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Something like this:

For Each e As Autodesk.Revit.Element In doc.Selection.Elements
Dim myValue As Integer = 0
e.Parameter("myParameter").Set(myValue)
Next
Return IExternalCommand.Result.Succeeded

jvj
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thanks Jamie, but can you walk me through this code. That is can you start from calling the element with the id number (e.g. 156789). And writing "this is a door" to the "Comments" parameter. I just started learning c#. Pls.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Well, my first disclaimer is that my code is written in VB.Net not C#.Net, but the object relationship is the same. I don't know what you understand about the language, so I'm simply going to stick to the facts about the RevitAPI.dll.

If you have an element ID, then you ask revit for the element. To do this you need the document object. This is given to you by the command's event arguments typically called "commandData" you declare a variable "doc" as type Autodesk.Revit.Document and set it = commandData.Application.ActiveDocument

Now that you have the document, you need to get the element from it. Very simple declare "myElement" as Autodesk.Revit.Element = Doc.Element(elementID)... Ok not that simple, you have to turn your number 156789 into an elementID type variable, so if you don't already have the elementID type variable declaired you need to do that first. It is not that hard declare "myID" as new ElementID, then set myID.value = 156789.

Now you have a populated variable myElement that is the element using your elementID found in the active document. Next you want to change the parameter "Comments" to your favorite text. VERY Simple. myElement.Parameter("Comments").set("this is a door"). Bear in mind that the parameter name must be exact to work at all, that includes case sensitivity. There are other, more reliable ways, to do this, but you needed the ez route.

That's it, now trust Revit to perform the action when you finish your command (function), Return.IExternalCommand.Result.Succeeded

When you return result succeeded, revit will take your command, commit the changes, run it's own error control and attempt to perform all the actions you programmed.



jvj



ps, find and install RvtMgdDbg.dll. This will give you a good view up the skirt of RevitAPI.dll Edited by: JamieVJohnson on Mar 12, 2010 9:50 PM
Message 5 of 6

Anonymous
Not applicable
Thanks Jamie,
I will try to do that and let you know how it turns out.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks alot,
It worked.
0 Likes