Change Design Option in Revit API

Change Design Option in Revit API

Anonymous
Not applicable
3,764 Views
6 Replies
Message 1 of 7

Change Design Option in Revit API

Anonymous
Not applicable

Hi,

 

i need to change the design option dynamically through API. Kindly help me to accomplish this.

 

Thanks and Regards,

Vinoth Kumar.R

0 Likes
Accepted solutions (1)
3,765 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Message 3 of 7

Anonymous
Not applicable

Hi Wilson,

 

Thanks for the reply. I am not able to set one design option as a primary design option because the property IsPrimary which was readonly. Is there any some other ways available to solve this?

 

Thanks and Regards,

Vinoth Kumar.R

0 Likes
Message 4 of 7

Anonymous
Not applicable
He pointed you to a link that states that this functionality is NOT exposed in Revit API. That's your answer right there.
0 Likes
Message 5 of 7

jeremytammik
Autodesk
Autodesk
Accepted solution

Here is a Q & A on this from the Revit API Panel @ AU Las Vegas 2017:

 

http://thebuildingcoder.typepad.com/blog/2017/11/revit-api-panel-au-las-vegas-2017.html

 

Q: Have a requirement to accept design options on the project.

A: Not exposed on the API, but just accept design option is easier, but needs to be on Revit Ideas.

 

Please check for a wish list item for the desired functionality in the Revit Idea Station and vote for it, if found; submit a new one, if not.

 

Here is a very tricky workaround suggestion, if you are willing to hack:

 

http://thebuildingcoder.typepad.com/blog/2015/03/list-and-switch-design-options-using-ui-automation....

 

Cheers,

 

Jeremy

  



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

Message 6 of 7

Anonymous
Not applicable

What about opening the model twice, in the first model we delete all design options sets and then, from the second model we copy all design option geometrical elements to the first model? Would that be equivalent to accepting the design options? 

//PROVIDE A MODEL PATH
String path="c:\\myRevitModel.rvt"

//Open your model a first time
Document doc = commandData.Application.OpenAndActivateDocument(path).Document;

//OPEN THE MODEL TEMPORARILY FOR A SECOND TIME
Document doc_temp = commandData.Application.OpenAndActivateDocument(path).Document;

//FIND ALL GEOMETRICAL ELEMENTS FROM THE PRIMARY DESIGN OPTIONS IN THE TEMPORARY MODEL
FilteredElementCollector finalCollectorTemp = new FilteredElementCollector(doc_temp);
PrimaryDesignOptionMemberFilter filterTemp = new PrimaryDesignOptionMemberFilter(false);
finalCollectorTemp.WherePasses(filterTemp);
finalCollectorTemp.WhereElementIsNotElementType();
finalCollectorTemp.WhereElementIsViewIndependent();
List<ElementId> TempElementsIDsList = new List<ElementId>();
foreach (Element i in finalCollectorTemp)
{
    if ((null != i.Category) && (null != i.get_Geometry(new Options())))
    {
        TempElementsIDsList.Add(i.Id);
    }
}

//SELECTING ALL DESIGN OPTION SETS AND DESIGN OPTIONS
finalCollector = new FilteredElementCollector(doc);
finalCollector.OfCategory(BuiltInCategory.OST_DesignOptions);
finalCollector.UnionWith((new FilteredElementCollector(doc)).OfCategory(BuiltInCategory.OST_DesignOptionSets));
ICollection<ElementId> ElementIDs = finalCollector.ToElementIds();

//DELETING ALL DESIGN OPTION SETS AND DESIGN OPTIONS
using (Transaction tx = new Transaction(doc))
{
    tx.Start("Deleting all design options sets and all design options");
    XYZ translation = new XYZ();
    doc.Delete(ElementIDs);
    tx.Commit();
}

//COPYING THE DESIGN OPTION ELEMENTS TO THE MODEL
ICollection<ElementId> CopiedElementsIDs = null;
using (Transaction tx = new Transaction(doc))
{
  tx.Start("Copying Elements from Temporary Model to Main Model");
  CopyPasteOptions copy_paste_options = new CopyPasteOptions();
  XYZ translation = new XYZ();
  Transform transform = Transform.Identity;
  CopiedElementsIDs = Autodesk.Revit.DB.ElementTransformUtils.CopyElements(
    doc_temp,TempElementsIDsList,doc, transform, copy_paste_options);
  tx.Commit();
}

//CLOSE THE TEMPORARY MODEL
doc_temp.Close(false);

 

0 Likes
Message 7 of 7

Anonymous
Not applicable

@Anonymous, @jeremytammik 

For those who are interested about Design Options, since Accepting Design Options is not yet possible by the Revit API, I am sharing a workaround which is deleting all non-Primary Design Options. I hope this is useful for others.

 

 

public void DeletingAllNonPrimaryDesignOptions(Document doc)
{
	//Selecting All Design Options
	FilteredElementCollector collector = new FilteredElementCollector(doc);
	collector.OfCategory(BuiltInCategory.OST_DesignOptions);

	//Selecting All non-Primary Design Options
	List<ElementId> DesignOptionsNotPrimaryIDs = new List<ElementId>();
	foreach (Element i in collector)
	{
		Autodesk.Revit.DB.DesignOption ii = i as Autodesk.Revit.DB.DesignOption;
		if (ii != null)
		{
			if (ii.IsPrimary != true)
			DesignOptionsNotPrimaryIDs.Add(ii.Id);
		}
	}

	//Deleting All non-Primary Design Options
	using (Transaction tx = new Transaction(doc))
	{
		tx.Start("Deleting all non-primary design options")
		doc.Delete(DesignOptionsNotPrimaryIDs);
		tx.Commit();
	}
}