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: 

Push Walltype to doors

2 REPLIES 2
Reply
Message 1 of 3
will.wydock
469 Views, 2 Replies

Push Walltype to doors

I have been working on this macro for a while, we are looking for a way to have our door schedule to include the wall type(Type Mark parameter). I have attached where I am at. I had no issues with pulling an instance parameter in the wall to the instance parameter in the door, but I was not having much luck with the type parameter in the wall.  The only area I am unsure of is if I am accessing the type parameters from the wall correctly.

 

public void WalltoDoor2()
		{
		    Document doc = this.ActiveUIDocument.Document;
		
		    ElementCategoryFilter hostFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
		    ElementCategoryFilter hostedFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);

		    string parameterName = "Type Mark";
			string parameterName2 = "Wall Type";
		    using (Transaction t = new Transaction(doc, "Set hosted parameters"))
		    {
     		    try
	    		{   
     		    	t.Start();
			        foreach (Element host in new FilteredElementCollector(doc).WherePasses(hostFilter))
			        {
			        	if(host !=null)
			        	{
				        	Element hostT=host.Document.GetElement(host.GetTypeId());
				        	Parameter paramHost = hostT.LookupParameter(parameterName);
				        	
				            foreach (Element hosted in new FilteredElementCollector(doc)
							.WherePasses(hostedFilter).OfClass(typeof(FamilyInstance))
							.Cast<FamilyInstance>().Where(q => q.Host.Id == host.Id))
				            {
								if(hosted !=null)
			        			{
				                    hosted.LookupParameter(parameterName2).Set(paramHost.AsString());
								}
				        	}
			        	}
			        }
			        t.Commit();
			    }
     		    catch(Exception)
			    {
			    }
			}
		    
		}
2 REPLIES 2
Message 2 of 3
stever66
in reply to: will.wydock

Using the Built In parameter checker, it looks like the Type Mark is called "ALL_MODEL_TYPE_MARK" for a wall.

 

Try using:

 

 hostT.LookupParameter("ALL_MODEL_TYPE_MARK");

Message 3 of 3
jeremytammik
in reply to: will.wydock

Dear Wwydock,

 

Thank you for your query and very many thanks to Steve for answering your question.

 

I'll just jump in and add two further suggestions to clean up your code:

 

  • Use `using` for transactions.
  • Don't catch all exceptions.

 

Encapsulating a transaction in a `using` statement automagically disposes of it and rolls back if needed:

 

https://thebuildingcoder.typepad.com/blog/2012/04/using-using-automagically-disposes-and-rolls-back....

 

Never catch all exceptions, only the ones that you really can handle:

 

https://thebuildingcoder.typepad.com/blog/2017/05/prompt-cancel-throws-exception-in-revit-2018.html#...

 

Are you really ready to handle the exceptions 'computer on fire', 'building collapsed', and 'fire!'?

 

If you catch all exceptions, you are preventing the really competent instances from even seeing them.

 

Cutting the phone lines to the fire brigade and police, so to speak.

 

You may be endangering your computer and your valued person.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



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

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

Post to forums  

Autodesk Design & Make Report