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: 

My first basic script

2 REPLIES 2
Reply
Message 1 of 3
Maciej_Darmochwal
357 Views, 2 Replies

My first basic script

Hi,I have a probably simple problem.I want select many elements and add to paramaeter "Comments" value "Something".I dont know where the problem is ;/.

using System;
using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; namespace Lab1PlaceGroup { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class Class1 : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uiapp.ActiveUIDocument.Document; IList<Reference> pickedobj = uidoc.Selection.PickObjects(ObjectType.Element, "SELECT").ToList(); IList<Parameter> param = new List<Parameter>(); for (int i = 0; i < pickedobj.Count; i++) { Element elemm = uidoc.Document.GetElement(pickedobj.ElementAt(i)); Parameter par = elemm.LookupParameter("Comments"); param.Append(par); } using (Transaction t = new Transaction(doc, "ASD")) { t.Start("TRANS"); try { int a = 0; foreach (Parameter x in param) { param.ElementAt(a).Set("Something"); a++; } } catch { } t.Commit(); } return Result.Succeeded; } } }
2 REPLIES 2
Message 2 of 3

Dear Maciej,

 

Welcome to the Revit API!

 

Looking at your code, I would suggest that you simplify it significantly.

 

Then the error will probably go away by itself.

 

The BIM element has one single comment filed that you wish to set a value on, so there is no need to maintain a list of different parameters named "Comment" and loop through all of the with the call to Set.

 

Pick the one single parameter you need instead.

 

The best way to do so is to not use the "Comment" display name, but the built-in parameter enumeration value.

 

It may or may not be BuiltInParameter.ALL_MODEL_MARK.

 

To find out what it is, you should first of all install RevitLookup and explore the element that you wish to set the comment on to find the built-in parameter enumeration value corresponding to the parameter you wish to modify.

 

Let's say its value is B.

 

Then you can simply say:

 

  elemm.get_Parameter(B).Set("Something");

 

By the way, I would suggest that you make it simple for yourself: before doing anything else, work through the standard Revit API getting started material, the training videos, and the initial walkthroughs in the developer guide:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

That will explain all the fundamentals and get you up and running smoothly with less hassle.

 

Once you have done that read about how to research to solve a Revit API programming task:

 

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 

Good luck and have fun!

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

Thanks for your Replay!

It will help me a lot, I spend so much time to find why that didnt work and i think  it was this line:

param.Append(par);

 And it should be:

param.Add(par);

Thats a reason why script can not build a list of parameters.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community