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: 

Combining parameters

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
dem1st
1475 Views, 5 Replies

Combining parameters

dem1st
Enthusiast
Enthusiast

Hi! Can anyone give a piece of advice on creating a plugin that'd take several parameter values and combine them into one parameter? Any resource on it or something similar to it would help greatly!

 

PS: I'm pretty new to C# and programming. A user will need to find the necessary categories and then specify parameters along with the "resulting" parameter containing every value (string). 

 

Basically, anology of this Dynamo script is needed (picture's attached).

 

Dynamo analogy.png

 

0 Likes

Combining parameters

Hi! Can anyone give a piece of advice on creating a plugin that'd take several parameter values and combine them into one parameter? Any resource on it or something similar to it would help greatly!

 

PS: I'm pretty new to C# and programming. A user will need to find the necessary categories and then specify parameters along with the "resulting" parameter containing every value (string). 

 

Basically, anology of this Dynamo script is needed (picture's attached).

 

Dynamo analogy.png

 

Tags (1)
Labels (1)
5 REPLIES 5
Message 2 of 6
franciscopossetto
in reply to: dem1st

franciscopossetto
Advocate
Advocate

Hey,

 

First of all, I would recommend you do this tutorial, to understand how Revit addíns are structured.  

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/lesso...

 

With regards to the logic, this schema should work in most cases:

 

Document doc = commandData.Application.ActiveUIDocument.Document;

//Get all elements of the Category Walls                
IEnumerable<Element> collector = new FilteredElementCollector(doc)
                                .OfCategory(BuiltInCategory.OST_Walls)
                                .WhereElementIsNotElementType()
                                .ToElements();

foreach(Element e in collector)
{
    //Get Parameter values
    string parameterValue1 = e.LookupParameter("Base Constraint").AsValueString();
    string parameterValue2 = e.LookupParameter("Top Constraint").AsValueString();
    string parameterValue3 = e.LookupParameter("Top Offset").AsValueString();

    string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;

    using (Transaction t = new Transaction(doc, "Set Parameter name"))
    {
        t.Start();
            e.LookupParameter("Comments").Set(newValue);
        t.Commit();
    }
}

 

 

Some comments :

- Collectors can be created to get elements of certain classes, categories, etc.

- To read the value of a parameter, in addition to the method LookupParameter you can use the method get_Parameter or get values from the Properties related with the element. (Syntax: object.Property)  

-The method Set is used to set a value. A value can also be set on a property (Syntax: object.Property = value)

-Any change to a document requires a transaction.

-To know more about Elements or methods you can use, I would recommend you install RevitLookup and see the Revit API online documentation: https://www.revitapidocs.com/ 

 

 

I hope it helps,

Good luck!

Github:
https://github.com/franpossetto

Hey,

 

First of all, I would recommend you do this tutorial, to understand how Revit addíns are structured.  

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/lesso...

 

With regards to the logic, this schema should work in most cases:

 

Document doc = commandData.Application.ActiveUIDocument.Document;

//Get all elements of the Category Walls                
IEnumerable<Element> collector = new FilteredElementCollector(doc)
                                .OfCategory(BuiltInCategory.OST_Walls)
                                .WhereElementIsNotElementType()
                                .ToElements();

foreach(Element e in collector)
{
    //Get Parameter values
    string parameterValue1 = e.LookupParameter("Base Constraint").AsValueString();
    string parameterValue2 = e.LookupParameter("Top Constraint").AsValueString();
    string parameterValue3 = e.LookupParameter("Top Offset").AsValueString();

    string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;

    using (Transaction t = new Transaction(doc, "Set Parameter name"))
    {
        t.Start();
            e.LookupParameter("Comments").Set(newValue);
        t.Commit();
    }
}

 

 

Some comments :

- Collectors can be created to get elements of certain classes, categories, etc.

- To read the value of a parameter, in addition to the method LookupParameter you can use the method get_Parameter or get values from the Properties related with the element. (Syntax: object.Property)  

-The method Set is used to set a value. A value can also be set on a property (Syntax: object.Property = value)

-Any change to a document requires a transaction.

-To know more about Elements or methods you can use, I would recommend you install RevitLookup and see the Revit API online documentation: https://www.revitapidocs.com/ 

 

 

I hope it helps,

Good luck!

Github:
https://github.com/franpossetto
Message 3 of 6
dem1st
in reply to: franciscopossetto

dem1st
Enthusiast
Enthusiast
Thanks for quite a thorough answer!
0 Likes

Thanks for quite a thorough answer!
Message 4 of 6
dem1st
in reply to: franciscopossetto

dem1st
Enthusiast
Enthusiast

Hello! The code works but partially. For some reason something is missing. It sets only the dashes. Is there anything we can change to get the right output? 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;

namespace CombineParameters  
{
    [Transaction(TransactionMode.Manual)]
    public class Class : 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 = uidoc.Document;

            //Create Filtered Element Collector and Filter
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_DuctFitting);

            //Applying Filter

            IList <Element> ducts = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();

            foreach (Element e in ducts)
            {
                //Get Parameter values
               
                string parameterValue1 = e.LookupParameter("AA").AsValueString();
                string parameterValue2 = e.LookupParameter("BB").AsValueString();
                string parameterValue3 = e.LookupParameter("CC").AsValueString();

                string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;
                


                using (Transaction t = new Transaction(doc, "Set Parameter name"))
                {
                    t.Start();
                  
                    e.LookupParameter("DD").Set(newValue);
                    
                    t.Commit();
                }
            }
            return Result.Succeeded;
        }
    }
}

 

fylypof_0-1619109053653.png

 

0 Likes

Hello! The code works but partially. For some reason something is missing. It sets only the dashes. Is there anything we can change to get the right output? 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;

namespace CombineParameters  
{
    [Transaction(TransactionMode.Manual)]
    public class Class : 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 = uidoc.Document;

            //Create Filtered Element Collector and Filter
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_DuctFitting);

            //Applying Filter

            IList <Element> ducts = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();

            foreach (Element e in ducts)
            {
                //Get Parameter values
               
                string parameterValue1 = e.LookupParameter("AA").AsValueString();
                string parameterValue2 = e.LookupParameter("BB").AsValueString();
                string parameterValue3 = e.LookupParameter("CC").AsValueString();

                string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;
                


                using (Transaction t = new Transaction(doc, "Set Parameter name"))
                {
                    t.Start();
                  
                    e.LookupParameter("DD").Set(newValue);
                    
                    t.Commit();
                }
            }
            return Result.Succeeded;
        }
    }
}

 

fylypof_0-1619109053653.png

 

Message 5 of 6
franciscopossetto
in reply to: dem1st

franciscopossetto
Advocate
Advocate
Accepted solution

Hey,

 

Change the method AsValueString to the method AsString, inside your foreach.

 

string parameterValue1 = e.LookupParameter("AA").AsString();
string parameterValue2 = e.LookupParameter("BB").AsString();
string parameterValue3 = e.LookupParameter("CC").AsString();

 

 

It should work.

Github:
https://github.com/franpossetto

Hey,

 

Change the method AsValueString to the method AsString, inside your foreach.

 

string parameterValue1 = e.LookupParameter("AA").AsString();
string parameterValue2 = e.LookupParameter("BB").AsString();
string parameterValue3 = e.LookupParameter("CC").AsString();

 

 

It should work.

Github:
https://github.com/franpossetto
Message 6 of 6
dem1st
in reply to: franciscopossetto

dem1st
Enthusiast
Enthusiast

It does work. Thanks a lot!

0 Likes

It does work. Thanks a lot!

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

Post to forums  

Autodesk Design & Make Report