Set material of subelement

Set material of subelement

Nurlan-A.
Advisor Advisor
553 Views
2 Replies
Message 1 of 3

Set material of subelement

Nurlan-A.
Advisor
Advisor

Hello!

Please help to copy material from one material parameter to another material parameter of the same element.

 

foreach(PlateInJoint pij in jointPlates)
	{
		Subelement subelem = pij.subelem;
		ParameterValue pv = subelem.GetParameterValue(new ElementId(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM));
		ElementIdParameterValue idpv = pv as ElementIdParameterValue;
		ElementId mid = idpv.Value;				
		Material platemat = this.GetMaterial(mid);//Existing material to copy
		List<ElementId> paramIds = subelem.GetAllParameters().ToList();
		foreach(ElementId paramId in paramIds)
			{
				BuiltInParameter bparam = (BuiltInParameter)paramId.IntegerValue;
				Element param = doc.GetElement(paramId);			
				if(param == null) continue;			
				if(param.Name == "CopyMaterial")//New material to paste
				{
				    How??
				    subelem.SetParameterValue(platemat);???
     				}

 

0 Likes
554 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Do the job manually in the user interface first and determine the proper parameter to use by examining the model before and after the modification using RevitLookup. There is no need to iterate over all element parameters. Once you know which built-in parameter you want to modify, you can access that directly. Avoid using display name string to identify parameters. The material parameter may take an element id value type.

  

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

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 3 of 3

Nurlan-A.
Advisor
Advisor

Hello Jeremy,

Thank you for  the tip. 

But when I try to snoop  parameters of the steel plate as subelement of the steel connection, RevitLookup gives an error.

Steps: Snoop Current Selection (a steel connection) > GetSubelements > Select a subelement (OST_StructConnectionPlates category) > GetAllParameters > error

So I cannot see parameters.

************** Exception text **************
System.NullReferenceException: Ссылка на объект не указывает на экземпляр объекта.(The object reference does not indicate an object instance.)
   в System.Object.GetType()
   в RevitLookup.Snoop.Forms.Objects.AddObjectsToTree(IEnumerable objs)
   в RevitLookup.Snoop.Forms.Objects.CommonInit(IEnumerable objs)
   в RevitLookup.Snoop.Data.Enumerable.DrillDown()
   в RevitLookup.Snoop.Utils.DataItemSelected(ListView lvCur)
   в System.Windows.Forms.Control.OnClick(EventArgs e)
   в System.Windows.Forms.ListView.WmReflectNotify(Message& m)
   в System.Windows.Forms.ListView.WndProc(Message& m)
   в System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam

 

0 Likes