Set parameter by parameters

Set parameter by parameters

Anonymous
Not applicable
801 Views
6 Replies
Message 1 of 7

Set parameter by parameters

Anonymous
Not applicable

Hi,

 

I'm trying to code a simple block for a macro that defines a parameter in my sheet out of a number of parameters.

 

 

My coding looks like this:

 

/*
 * Created by SharpDevelop.
 * User: Kevin
 * Date: 23-7-2014
 * Time: 11:27
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using System.Collections.Generic;
using System.Linq;

namespace LaatsteWijziging
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.DB.Macros.AddInId("1B44BCE3-F409-416D-818A-0BDC66E4A1D8")]
	public partial class ThisDocument
	{
		private void Module_Startup(object sender, EventArgs e)
		{

		}

		
		private void Module_Shutdown(object sender, EventArgs e)
		{

		}

		#region Revit Macros generated code
		private void InternalStartup()
		{
			this.Startup += new System.EventHandler(Module_Startup);
			this.Shutdown += new System.EventHandler(Module_Shutdown);
		}
		#endregion
		public void wijziging_datum()
		{
			
		}
			public void GetSheetParams(ExternalCommandData commandData, string datum)
			{
				
				Document doc =  commandData.Application.ActiveUIDocument.Document;
				foreach (Element e in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)))
				{
					// zoek naar de parameter
					Parameter wijziging9 = e.get_Parameter("3BA_wijziging_datum_9");
					Parameter wijziging8 = e.get_Parameter("3BA_wijziging_datum_8");
					Parameter wijziging7 = e.get_Parameter("3BA_wijziging_datum_7");
					Parameter wijziging6 = e.get_Parameter("3BA_wijziging_datum_6");
					Parameter wijziging5 = e.get_Parameter("3BA_wijziging_datum_5");
					Parameter wijziging4 = e.get_Parameter("3BA_wijziging_datum_4");
					Parameter wijziging3 = e.get_Parameter("3BA_wijziging_datum_3");
					Parameter wijziging2 = e.get_Parameter("3BA_wijziging_datum_2");
					Parameter wijziging1 = e.get_Parameter("3BA_wijziging_datum_1");
					Parameter LaatsteWijziging = e.get_Parameter("laatste_wijziging");
						
					// vul de parameter in
					string datum9 = wijziging9.AsString();
					string datum8 = wijziging8.AsString();
					string datum7 = wijziging7.AsString();
					string datum6 = wijziging6.AsString();
					string datum5 = wijziging5.AsString();
					string datum4 = wijziging4.AsString();
					string datum3 = wijziging3.AsString();
					string datum2 = wijziging2.AsString();
					string datum1 = wijziging1.AsString();
					
					string wijziging0 = null;
					string cntrl = ("00-00-00");
					
					// zoek naar de laatste wijziging
					if (datum9 != cntrl)
						wijziging0 = datum9;
							
					else if (datum8 != cntrl)
						wijziging0 = datum8;
	
					else if (datum7 != cntrl)
						wijziging0 = datum7;
					
					else if (datum6 != cntrl)
						wijziging0 = datum6;
					
					else if (datum5 != cntrl)
						wijziging0 = datum5;
											
					else if (datum4 != cntrl)
						wijziging0 = datum4;
	
					else if (datum3 != cntrl)
						wijziging0 = datum3;
	
					else if (datum2 != cntrl)
						wijziging0 = datum2;
	
					else if (datum1 != cntrl)
						wijziging0 = datum1;
					
					else 
						wijziging0 = cntrl;	
					if (wijziging0 != null)
						LaatsteWijziging.SetValueString(wijziging0);
										
				}
			}
		}
	}

 Can somebody tell me what i'm doing wrong? Robot Very Happy

 

The build doesn't give any error's 

0 Likes
802 Views
6 Replies
Replies (6)
Message 2 of 7

Troy_Gates
Advocate
Advocate

For the line of code

 

LaatsteWijziging.SetValueString(wijziging0);

 

Replace with this code

 

e.get_Parameter("laatste_wijziging").Set(wijziging0);

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thanks for your reply!

 

The code should work now, but the macro magically disappears from the macro menu.

Is this cause of the ExternalCommandData? Or is there something else I look over

0 Likes
Message 4 of 7

Anonymous
Not applicable
Are there errors when you run build?
0 Likes
Message 5 of 7

Anonymous
Not applicable

Nope, no errors, no warnings, nothing.

0 Likes
Message 6 of 7

Anonymous
Not applicable
It looks like that i'm having to put the program under a other handler.
But since my programming skills in C# are not that quite good, how the hell do i do that?

Like the code that handle the Parameter handle section is the
public void GetSheetParams(ExternalCommandData commandData);
{}

And the code that handles the macro is
public void Wijziging_datum();
{
"What should i enter here?"
}
0 Likes
Message 7 of 7

Anonymous
Not applicable

If you're using a macro, then you shouldn't have any references to ExternalCommandData anywhere.

 

Instead, you should be able to access the Document object by referencing: this.ActiveUIDocument.Document.

 

To be able to run a macro from the Macro Manager, it must be a public void function that accepts no arguments.  This is why the "Wijziging_datum" function appeared in the list, but the "GetSheetParams" function did not.

0 Likes