Copy Parameters

Copy Parameters

emaguilera
Contributor Contributor
825 Views
7 Replies
Message 1 of 8

Copy Parameters

emaguilera
Contributor
Contributor

Hi everyone,

I need to copy the content from the source parameters to the target parameters. I've written the following code, but it doesn't seem to work correctly. Can anyone help me figure out what's wrong?

 

    [Transaction(TransactionMode.Manual)]
    public class CopyParameterCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Autodesk.Revit.DB.Document doc = uiApp.ActiveUIDocument.Document;

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Element> allElements = collector.WhereElementIsNotElementType().ToElements();

            using (Transaction trans = new Transaction(doc, "Copiar parámetro "))
            {
                trans.Start();

                foreach (Element element in allElements)
                {
                    Parameter sourceParam = element.LookupParameter("Source-parameter");
                    Parameter targetParam = element.LookupParameter("Target-parameter");


                    if (sourceParam != null && sourceParam.HasValue)
                    {
                        string sourceValue = sourceParam.AsString();

                        if (targetParam != null && targetParam.StorageType == StorageType.String)
                        {
                            targetParam.Set(sourceValue);
                            sourceParam.Set(string.Empty);
                        }
                    }
                }

                trans.Commit();
            }

            return Result.Succeeded;
        }
    }
0 Likes
826 Views
7 Replies
Replies (7)
Message 2 of 8

jeremy_tammik
Alumni
Alumni

I cannot tell what the problem might be. What behaviour do you observe?

 

Your code looks sort of OK-ish, although I see a couple of issues that could easily be optimised.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 8

emaguilera
Contributor
Contributor

.

0 Likes
Message 4 of 8

emaguilera
Contributor
Contributor

.

emaguilera_0-1724171130177.png

I want what is in red to become what is in yellow.
I can't get it to work.

 

0 Likes
Message 5 of 8

jeremy_tammik
Alumni
Alumni

So, what is the problem with your script? What happens?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 8

MarryTookMyCoffe
Collaborator
Collaborator

maybe source and target parameter are type parameters, you look for them in instance not in symbol. debug it or if you don't know how make a simple dialog that show if any parameter was found.

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes
Message 7 of 8

emaguilera
Contributor
Contributor

The code basically doesn't work, it doesn't do what I want it to do.

0 Likes
Message 8 of 8

emaguilera
Contributor
Contributor

I managed to fix it, the error was in the parameter name... 😂
Regards,
Emanuel.

0 Likes