/// <summary> /// constructor /// </summary> /// <param name="app"> /// the active revit application /// </param> /// <param name="doc"> /// the family document which will have parameters added in /// </param> public FamilyParameterAssigner(Autodesk.Revit.ApplicationServices.Application app, Document doc) { m_app = app; m_manager = doc.FamilyManager; m_familyParams = new Dictionary<string, FamilyParam>(); m_assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); m_paramLoaded = false; }
/// <summary> /// implementation of validate parameters, get all family types and parameters, /// use the function FamilyType.HasValue() to make sure if the parameter needs to /// validate. Then along to the storage type to validate the parameters. /// </summary> /// <returns>error information list</returns> public static List<string> ValidateParameters(FamilyManager familyManager) { List<string> errorInfo = new List<string>(); // go though all parameters foreach (FamilyType type in familyManager.Types) { bool right = true; foreach (FamilyParameter para in familyManager.Parameters) { try { if (type.HasValue(para)) { switch (para.StorageType) { case StorageType.Double: if (!(type.AsDouble(para) is double)) right = false; break; case StorageType.ElementId: try { Autodesk.Revit.DB.ElementId elemId=type.AsElementId(para); } catch { right = false; } break; case StorageType.Integer: if (!(type.AsInteger(para) is int)) right = false; break; case StorageType.String: if (!(type.AsString(para) is string)) right = false; break; default: break; } } } // output the parameters which failed during validating. catch { errorInfo.Add("Family Type:" + type.Name + " Family Parameter:" + para.Definition.Name + " validating failed!"); } if (!right) { errorInfo.Add("Family Type:" + type.Name + " Family Parameter:" + para.Definition.Name + " validating failed!"); } } } return errorInfo; }
public ParameterBinding(Document doc, string groupName, string paramName) { _doc = doc; _app = doc.Application; _manager = doc.FamilyManager; _groupName = groupName; _paramName = paramName; if (LoadSharedParameterFromFile(out _doesExist) && _doesExist) { bool result = AddSharedParameter(); } }
public void addMaterials(Extrusion pSolid) { // We assume Material type "Glass" exists. Template "Metric Column.rft" include "Glass", // which in fact is the only interesting one to see the effect. // In practice, you will want to include in your template. // // To Do: For the exersize, create it with more appropriate ones in UI, then use the name here. // // (1) get the materials id that we are intersted in (e.g., "Glass") // Material pMat = findElement(typeof(Material), "Glass") as Material; if (pMat != null) { ElementId idMat = pMat.Id; // (2a) this add a material to the solid base. but then, we cannot change it for each column. // //pSolid.Parameter("Material").Set(idMat) // (2b) add a parameter for material finish // // this time we use instance parameter so that we can change it at instance level. // FamilyManager pFamilyMgr = _doc.FamilyManager; FamilyParameter famParamFinish = pFamilyMgr.AddParameter("ColumnFinish", BuiltInParameterGroup.PG_MATERIALS, ParameterType.Material, true); // (2b.1) associate material parameter to the family parameter we just added // // // 'Autodesk.Revit.DB.Element.get_Parameter(string)' is obsolete in Revit 2015 //Parameter paramMat = pSolid.get_Parameter("Material"); /// Updated for Revit 2015 /// Parameter paramMat = pSolid.LookupParameter("Material"); pFamilyMgr.AssociateElementParameterToFamilyParameter(paramMat, famParamFinish); // (2b.2) for our convenience, let's add another type with Glass finish // addType("Glass", 600.0, 600.0); pFamilyMgr.Set(famParamFinish, idMat); } }
/// <summary> /// Add type parameters to the family /// </summary> /// <param name="DWGFileName">Name of imported dwg file</param> private void AddParameters(string DWGFileName) { // Get the family manager FamilyManager familyMgr = m_doc.FamilyManager; // Add parameter 1: DWGFileName familyMgr.NewType("DWGFamilyCreation"); FamilyParameter paraFileName = familyMgr.AddParameter("DWGFileName", new ForgeTypeId(), SpecTypeId.String.Text, false); familyMgr.Set(paraFileName, DWGFileName); // Add parameter 2: ImportTime String time = DateTime.Now.ToString("yyyy-MM-dd"); FamilyParameter paraImportTime = familyMgr.AddParameter("ImportTime", new ForgeTypeId(), SpecTypeId.String.Text, false); familyMgr.Set(paraImportTime, time); }
private void SetNewValueParam(Document doc, List <ChangeMaterialModel> listModel) { FamilyManager FM = doc.FamilyManager; foreach (var model in listModel) { if (model.new_material != null) { try { FM.CurrentType = model.familyType; FM.Set(model.fmParam, model.new_material.Id); } catch { } } } }
/// <summary> /// Add type parameters to the family /// </summary> /// <param name="DWGFileName">Name of imported dwg file</param> private void AddParameters(string DWGFileName) { // Get the family manager FamilyManager familyMgr = m_doc.FamilyManager; // Add parameter 1: DWGFileName familyMgr.NewType("DWGFamilyCreation"); FamilyParameter paraFileName = familyMgr.AddParameter("DWGFileName", Autodesk.Revit.DB.BuiltInParameterGroup.INVALID, Autodesk.Revit.DB.ParameterType.Text, false); familyMgr.Set(paraFileName, DWGFileName); // Add parameter 2: ImportTime String time = DateTime.Now.ToString("yyyy-MM-dd"); FamilyParameter paraImportTime = familyMgr.AddParameter("ImportTime", Autodesk.Revit.DB.BuiltInParameterGroup.INVALID, Autodesk.Revit.DB.ParameterType.Text, false); familyMgr.Set(paraImportTime, time); }
internal bool ProcessFamily() { if (!Doc.IsFamilyDocument) { return(false); } FamilyManager famMgr = Doc.FamilyManager; FamilyTypeSet famTypes = famMgr.Types; FamilyTypeSetIterator famTypeItor = famTypes.ForwardIterator(); famTypeItor.Reset(); while (famTypeItor.MoveNext()) { FamilyType famType = famTypeItor.Current as FamilyType; logMsgDbLn2("fam type", famType.Name); } FamilyParameterSet famParas = famMgr.Parameters; FamilyParameterSetIterator famParaItor = famParas.ForwardIterator(); famParaItor.Reset(); while (famParaItor.MoveNext()) { FamilyParameter famPara = famParaItor.Current as FamilyParameter; logMsgDbLn2("fam para", famPara.Definition.Name + " :: " + famPara.Definition.ParameterGroup.ToString() + " :: " + famPara.Definition.ParameterType.ToString()); } famMgr.AddParameter("ASI", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true); // using (SubTransaction st = new SubTransaction(_doc)) // { // st.Start(); // famMgr.AddParameter("ASI", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true); // st.Commit(); // } return(true); }
public void AddParametersToFamily(Document doc, Autodesk.Revit.ApplicationServices.Application app) { Dictionary <string, BuiltInParameterGroup> builtInParameterGroupDictionary = new SharedParametersLibrary(doc, app).BuiltInParameterGroupDictionary(doc); SortedList <string, Category> parameterCategoryList = new SharedParametersLibrary(doc, app).ParameterCategoryList(doc); selectedGroup = GroupParameterUnderComboBox.SelectedItem; string selectedGroupName = selectedGroup.ToString(); definitionGroup = GroupSelectComboBox.SelectedItem; string definitionGroupName = definitionGroup.ToString(); BuiltInParameterGroup builtInParameterGroup = builtInParameterGroupDictionary[selectedGroupName]; SortedList <string, ExternalDefinition> sharedParameterList = new SharedParametersLibrary(doc, app).GetSharedParameterList(definitionGroupName); FamilyManager familyManager = doc.FamilyManager; using (Transaction tx = new Transaction(doc)) { tx.Start("Add Selected Shared Parameters"); foreach (string selectedParameter in ParameterList.SelectedItems) { if ((sharedParameterList.ContainsKey(selectedParameter)) && (TypeCheck.Checked)) { ExternalDefinition externalDefinition = new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList); familyManager.AddParameter(externalDefinition, builtInParameterGroup, false); } else if ((sharedParameterList.ContainsKey(selectedParameter)) && (InstanceCheck.Checked)) { ExternalDefinition externalDefinition = new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList); familyManager.AddParameter(externalDefinition, builtInParameterGroup, true); } else { } } tx.Commit(); } }
public static bool ParamIsExists(Document famDoc, SharedParameterContainer paramContainer) { FamilyManager fMan = famDoc.FamilyManager; foreach (FamilyParameter fparam in fMan.Parameters) { if (!fparam.IsShared) { continue; } Guid guid1 = fparam.GUID; Guid guid2 = paramContainer.guid; bool check = guid1.Equals(guid2); if (check) { return(true); } } return(false); }
private FamilyParameter DoesParameterExistInFile(string parameterNameStr, Autodesk.Revit.DB.Document targetDoc) { FamilyManager mgr = null; mgr = targetDoc.FamilyManager; // Catch ex As Exception // End Try JerkHub.Ptr2Debug.AddToDebug(("Testing if Parameter exists : " + parameterNameStr)); foreach (FamilyParameter oneParameter in mgr.Parameters) { if ((oneParameter.Definition.Name.ToLower() == parameterNameStr.ToLower())) { JerkHub.Ptr2Debug.AddToDebug(("Result : " + true.ToString())); return(oneParameter); } } JerkHub.Ptr2Debug.AddToDebug(("Result : " + false.ToString())); return(null); }
/// <summary> /// constructor of DoubleHungWinCreation /// </summary> /// <param name="para">WizardParameter</param> /// <param name="commandData">ExternalCommandData</param> public DoubleHungWinCreation(WizardParameter para, ExternalCommandData commandData) : base(para) { m_application = commandData.Application; m_document = commandData.Application.ActiveUIDocument.Document; m_familyManager = m_document.FamilyManager; CollectTemplateInfo(); para.Validator = new ValidateWindowParameter(m_wallHeight, m_wallWidth); switch (m_document.DisplayUnitSystem) { case Autodesk.Revit.DB.DisplayUnit.METRIC: para.Validator.IsMetric = true; break; case Autodesk.Revit.DB.DisplayUnit.IMPERIAL: para.Validator.IsMetric = false; break; } para.PathName = Path.GetDirectoryName(para.PathName) + "Double Hung.rfa"; CreateCommon(); }
protected override void onProcess(int familiesUpdateCount) { _mutation_buttons_selectedGO = FamilyManager.getFamily(new AllOfComponents(typeof(Button)), new AnyOfTags("mutation_button_selected")); _mutation_buttonsGO = FamilyManager.getFamily(new AllOfComponents(typeof(Button)), new AnyOfTags("mutation_button")); Level l = env.GetComponent <Level>(); foreach (GameObject go in _mutation_buttonsGO) { foreach (String s in l.components) { BonusAndMalus bn = go.GetComponent <BonusAndMalus>(); if (bn.name == s) { GameObjectManager.setGameObjectTag(go, "mutation_button_selected"); Button bt = go.GetComponent <Button>(); switchColorButton(bt); } } } foreach (GameObject go in _mutation_buttons_selectedGO) { bool selected = false; foreach (String s in l.components) { BonusAndMalus bn = go.GetComponent <BonusAndMalus>(); if (bn.name == s) { selected = true; break; } } if (!selected) { GameObjectManager.setGameObjectTag(go, "mutation_button"); Button bt = go.GetComponent <Button>(); switchColorButton(bt); } } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; if (!doc.IsFamilyDocument) { message = "Please run this command in a family document."; return(Result.Failed); } else { bool isShared; string guid; FamilyManager mgr = doc.FamilyManager; foreach (FamilyParameter fp in mgr.Parameters) { // Using GetFamilyParamGuid method, // internally accessing m_Parameter: isShared = GetFamilyParamGuid(fp, out guid); // Using extension method, internally // accessing getParameter: if (fp.IsShared()) { Guid giud2 = fp.GUID; } } return(Result.Succeeded); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; FamilyManager famMgr = doc.FamilyManager; DefinitionFile defFile = app.OpenSharedParameterFile( ); DefinitionGroups defGrps = defFile.Groups; foreach (DefinitionGroup defGrp in defGrps) { var externalDef = from ExternalDefinition extDef in defGrp.Definitions select extDef; foreach (ExternalDefinition extDef in externalDef) { using (Transaction tx = new Transaction(doc)) { tx.Start("New Param"); FamilyParameter famParam = famMgr.AddParameter(extDef, BuiltInParameterGroup.PG_GENERAL, false); tx.Commit( ); } } } //Main //Reference pickedObj = uidoc.Selection.PickObject(ObjectType.Element); //ElementId eleid = pickedObj.ElementId; //Element ele = doc.GetElement(eleid); return(Result.Succeeded); }
protected override void onProcess(int familiesUpdateCount) { _mutation_buttonsGO = FamilyManager.getFamily(new AllOfComponents(typeof(Button)), new AnyOfTags("mutation_button")); _mutation_buttons_selectedGO = FamilyManager.getFamily(new AllOfComponents(typeof(Button)), new AnyOfTags("mutation_button_selected")); foreach (GameObject mutGO in _mutation_buttonsGO) { Button bt = mutGO.GetComponent <Button>(); if (bt.interactable) { var colors = bt.colors; colors.normalColor = new Color32(24, 82, 99, 255); bt.colors = colors; } else { var colors = bt.colors; colors.disabledColor = new Color32(24, 82, 99, 140); bt.colors = colors; } } foreach (GameObject mutGO in _mutation_buttons_selectedGO) { Button bt = mutGO.GetComponent <Button>(); if (bt.interactable) { var colors = bt.colors; colors.normalColor = new Color32(102, 233, 216, 255); bt.colors = colors; } else { var colors = bt.colors; colors.disabledColor = new Color32(102, 233, 216, 140); bt.colors = colors; } } }
/// <summary> /// Add a new family parameter with a given name. /// </summary> /// <param name="parameterName">The name of the new family parameter.</param> /// <param name="parameterGroup">The name of the group to which the family parameter belongs.</param> /// <param name="parameterType">The name of the type of new family parameter.</param> /// <param name="isInstance">Indicates if the new family parameter is instance or type (true if parameter should be instance).</param> /// <returns>The new family parameter.</returns> public Elements.FamilyParameter AddParameter(string parameterName, string parameterGroup, string parameterType, bool isInstance) { // parse parameter type Autodesk.Revit.DB.ParameterType type; if (!System.Enum.TryParse <Autodesk.Revit.DB.ParameterType>(parameterType, out type)) { throw new System.Exception(Properties.Resources.ParameterTypeNotFound); } // parse parameter group Autodesk.Revit.DB.BuiltInParameterGroup group; if (!System.Enum.TryParse <Autodesk.Revit.DB.BuiltInParameterGroup>(parameterGroup, out group)) { throw new System.Exception(Properties.Resources.ParameterTypeNotFound); } TransactionManager.Instance.EnsureInTransaction(this.InternalDocument); var famParameter = FamilyManager.AddParameter(parameterName, group, type, isInstance); TransactionManager.Instance.TransactionTaskDone(); return(new Elements.FamilyParameter(famParameter)); }
public FamilySymbol CreatNewSymbol(Document doc, Family doorfamily, int doorwidth, int doorheight, string str) { Document familydoc = doc.EditFamily(doorfamily); FamilyManager familymanager = familydoc.FamilyManager; string symbolname = str; using (Transaction creatnewsymbol = new Transaction(familydoc)) { creatnewsymbol.Start("新建族类型"); FamilyType familytype = familymanager.NewType(symbolname); FamilyParameter para_width = familymanager.get_Parameter(BuiltInParameter.DOOR_WIDTH); FamilyParameter para_height = familymanager.get_Parameter(BuiltInParameter.GENERIC_HEIGHT); familymanager.Set(para_width, doorwidth / 304.8); familymanager.Set(para_height, doorheight / 304.8); creatnewsymbol.Commit(); } LoadOptions loadoptions = new LoadOptions(); doorfamily = familydoc.LoadFamily(doc, loadoptions); FamilySymbol newsymbol = null; using (Transaction activesymbol = new Transaction(doc)) { activesymbol.Start("激活族类型"); ISet <ElementId> idstmp = doorfamily.GetFamilySymbolIds(); foreach (ElementId id in idstmp) { FamilySymbol symbol = doc.GetElement(id) as FamilySymbol; if (symbol.Name.Equals(symbolname)) { symbol.Activate(); newsymbol = symbol; } } activesymbol.Commit(); } return(newsymbol); }
// ====================================== // (3.1) add parameters // ====================================== void addParameters() { FamilyManager mgr = _doc.FamilyManager; // API parameter group for Dimension is PG_GEOMETRY: // FamilyParameter paramTw = mgr.AddParameter( "Tw", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, false); FamilyParameter paramTd = mgr.AddParameter( "Td", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, false); // set initial values: // double tw = mmToFeet(150.0); double td = mmToFeet(150.0); mgr.Set(paramTw, tw); mgr.Set(paramTd, td); }
public ParametersInFamily(Document familyDoc) { FamilyManager fMan = familyDoc.FamilyManager; foreach (FamilyParameter fParam in fMan.Parameters) { if (!fParam.IsShared) { continue; } string name = fParam.Definition.Name; bool isInstance = fParam.IsInstance; InternalDefinition def = fParam.Definition as InternalDefinition; Guid guid = fParam.GUID; BuiltInParameterGroup paramGroup = fParam.Definition.ParameterGroup; SharedParameterContainer paramContainer = new SharedParameterContainer(name, guid, paramGroup, isInstance, def); parameters.Add(paramContainer); } }
void modifyFamilyParamValue() { FamilyManager mgr = _doc.FamilyManager; FamilyParameter[] a = new FamilyParameter[] { mgr.get_Parameter("Width"), mgr.get_Parameter("Depth") }; foreach (FamilyType t in mgr.Types) { mgr.CurrentType = t; foreach (FamilyParameter fp in a) { if (t.HasValue(fp)) { double x = (double)t.AsDouble(fp); mgr.Set(fp, 2.0 * x); } } } }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { GameObject nextLvl = dest.First(); TotalScore ts = FamilyManager.getFamily(new AllOfComponents(typeof(TotalScore))).First().GetComponent <TotalScore>(); foreach (GameObject go in structures) { Destroyed d = go.GetComponent <Destroyed> (); if (d.destroyed == false && d.transform.position.y < nextLvl.GetComponent <DestroyedStruct> ().destroyed_treshold) { d.destroyed = true; nextLvl.GetComponent <DestroyedStruct> ().nb_destroyed_struct++; } } if (FamilyManager.getFamily(new AllOfComponents(typeof(Collect))).Count == 0) { //NIVEAU TERMINE : affichage d'un message if (nextLvl.GetComponent <DestroyedStruct> ().nb_destroyed_struct > 0) { nextLvl.GetComponent <DestroyedStruct> ().ended_lvl = true; nextLvl.AddComponent <ChangeLevelAndNotDestroyed> (); } if (nextLvl.GetComponent <DestroyedStruct> ().ended_lvl == false) { ts.score_total += 50; // bonus si on a effectué le nombre de tir minimum // 100 - (différence entre min et nb tir)*20 ; int score = 100 - (Mathf.Abs(nextLvl.GetComponent <DestroyedStruct> ().nb_shoot - nextLvl.GetComponent <DestroyedStruct> ().nb_min_shoot)) * 20; score = (score < 0) ? 0 : score; ts.score_total += score; nextLvl.GetComponent <DestroyedStruct> ().ended_lvl = true; GameObject winText = GameObject.FindGameObjectWithTag("win"); winText.GetComponent <Canvas>().sortingOrder = 2; nextLvl.AddComponent <ChangeLevelAndNotDestroyed> (); } } }
// Start is called before the first frame update protected void Awake() { if (familyManager == null) { familyManager = FindObjectOfType <FamilyManager>(); } if (myCanvas == null) { myCanvas = GetComponentInChildren <Canvas>(); } if (textBox == null) { textBox = GetComponentInChildren <TextMeshProUGUI>(); } if (myTimer == null) { myTimer = GetComponentInChildren <CountdownTimer>(); } PopulateTextBox(); textBox.gameObject.SetActive(false); myTimer.gameObject.SetActive(false); }
/// <summary> /// Non-working sample code for /// http://forums.autodesk.com/t5/revit-api/family-types-amp-shared-parameter-values/m-p/6218767 /// </summary> void SetFamilyParameterValueFails( Document doc, string paramNameToAmend) { FamilyManager mgr = doc.FamilyManager; FamilyTypeSet familyTypes = mgr.Types; FamilyTypeSetIterator familyTypeItor = familyTypes.ForwardIterator(); familyTypeItor.Reset(); while (familyTypeItor.MoveNext()) { FamilyParameter familyParam = mgr.get_Parameter(paramNameToAmend); if (familyParam != null) { FamilyType familyType = familyTypeItor.Current as FamilyType; Debug.Print(familyType.Name); mgr.Set(familyParam, 2); } } }
/// <summary> /// constructor of FixedWinCreation /// </summary> /// <param name="para">WizardParameter</param> /// <param name="commandData">ExternalCommandData</param> public FixedWinCreation(WizardParameter para, CreateWindowData commandData) : base(para) { m_application = commandData.Application; m_document = commandData.Document; m_familyManager = m_document.FamilyManager; using (Transaction tran = new Transaction(m_document, "InitializeWindowWizard")) { tran.Start(); CollectTemplateInfo(); para.Validator = new ValidateWindowParameter(m_wallHeight, m_wallWidth); switch (m_document.DisplayUnitSystem) { case Autodesk.Revit.DB.DisplayUnit.METRIC: para.Validator.IsMetric = true; break; case Autodesk.Revit.DB.DisplayUnit.IMPERIAL: para.Validator.IsMetric = false; break; } if (RuntimeValue.RunOnCloud) { para.PathName = "WindowFamily.rfa"; } else { para.PathName = "C:\\Users\\zhongwu\\Documents\\FixedWin.rfa"; } CreateCommon(); tran.Commit(); } }
public void MakeNewFamilyType(Document familyDoc, int D1, int L1) { FamilyManager familyManager = familyDoc.FamilyManager; using (Transaction newFamilyTypeTransaction = new Transaction(familyDoc, "Add Type to Family")) { int changesMade = 0; newFamilyTypeTransaction.Start(); FamilyType newFamilyType = familyManager.NewType("60 X 100"); if (newFamilyType != null) { FamilyParameter familyParam = familyManager.get_Parameter("D 1"); if (null != familyParam) { familyManager.Set(familyParam, D1); changesMade += 1; } familyParam = familyManager.get_Parameter("L 1"); if (null != familyParam) { familyManager.Set(familyParam, L1); changesMade += 1; } } if (2 == changesMade) { newFamilyTypeTransaction.Commit(); } else { newFamilyTypeTransaction.RollBack(); } } }
private List <Material> GetFamilyTypesMaterials(Document doc, Family modifiedFamily) { List <Material> typesMaterials = new List <Material>(); Document familyDoc = doc.EditFamily(modifiedFamily); FamilyManager familyManager = familyDoc.FamilyManager; FamilyTypeSet familyTypes = familyManager.Types; FamilyTypeSetIterator iterator = familyTypes.ForwardIterator(); iterator.Reset(); string types = string.Empty; using (Transaction trans = new Transaction(familyDoc, "MaterialParameter")) { trans.Start(); while (iterator.MoveNext()) { familyManager.CurrentType = iterator.Current as FamilyType; FamilyType type = familyManager.CurrentType; string param = string.Empty; foreach (FamilyParameter parameter in familyManager.Parameters) { if (parameter.Definition.Name.Contains("Mat")) { Material material = doc.GetElement(type.AsElementId(parameter)) as Material; if (material != null) { typesMaterials.Add(material); } } } } trans.Commit(); } return(typesMaterials); }
private void SetDoubleValue(object value, Autodesk.Revit.DB.FamilyParameter familyParameter) { double doubleValue; try { if (Type.GetTypeCode(value.GetType()) == TypeCode.Int64 || Type.GetTypeCode(value.GetType()) == TypeCode.Int32) { doubleValue = Convert.ToDouble(value); } else { doubleValue = (double)value; } } catch (Exception) { throw new InvalidOperationException(string.Format(Properties.Resources.WrongStorageType, familyParameter.StorageType)); } double doubleValueToSet = doubleValue * UnitConverter.DynamoToHostFactor(familyParameter.Definition.GetSpecTypeId()); FamilyManager.Set(familyParameter, doubleValueToSet); }
public void ProduceProfile(ref Document doc, ref List <string> vs, ref List <string> pv) { using (Transaction t = new Transaction(doc, "make profile xn * yn")) { t.Start(); FamilyManager familyManager = doc.FamilyManager; for (int i = 0; i != vs.Count; i++) { FamilyParameter familyParameter = familyManager.get_Parameter(vs[i]); try { familyManager.SetValueString(familyParameter, pv[i]); } catch { familyManager.Set(familyParameter, int.Parse(pv[i])); } } t.Commit(); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document document; document = commandData.Application.ActiveUIDocument.Document; // only a family document can retrieve family manager if (document.IsFamilyDocument) { m_familyManager = document.FamilyManager; List<string> errorMessages = ValidateParameters(m_familyManager); using(MessageForm msgForm = new MessageForm(errorMessages.ToArray())) { msgForm.StartPosition = FormStartPosition.CenterParent; msgForm.ShowDialog(); return Autodesk.Revit.UI.Result.Succeeded; } } else { message = "please make sure you have opened a family document!"; return Autodesk.Revit.UI.Result.Failed; } }
public static void Add_SP_To_Families(List <string> full_files_name, List <string> parm_to_add, bool instance) { Document doc; //Application app; //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1"; // loop through all files in the directory // TaskDialog.Show("Revit","Hey"); foreach (string filename in full_files_name) { doc = CachedApp.OpenDocumentFile(filename); try { if (doc.IsFamilyDocument) { Transaction trans = new Transaction(doc, "Add Param"); using (trans) { FamilyManager fm = doc.FamilyManager; DefinitionFile deFile = CachedApp.OpenSharedParameterFile(); DefinitionGroups myGroups = deFile.Groups; foreach (string s in parm_to_add) { foreach (DefinitionGroup myGroup in myGroups) { // DefinitionGroup myGroup = myGroups.get_Item("New len"); trans.Start(); Definitions myDefinitions = myGroup.Definitions; //TaskDialog.Show("Revit",s); ExternalDefinition eDef = myDefinitions.get_Item(s) as ExternalDefinition; if (eDef != null) { fm.AddParameter(eDef, eDef.ParameterGroup, instance); } //TaskDialog.Show("Revit","Hey"); trans.Commit(); // if(eDef != null) break; } } } // doc.SaveAs(filename); doc.Close(true); //int tmp = Form1.progressBar1.Maximum; // int c = tmp/Globals.full_files_name_variables.Count; //Form1.progressBar1.Increment(c); } } catch (Autodesk.Revit.Exceptions.ArgumentNullException ae) { TaskDialog.Show("Revit", ae.ToString()); //trans.Commit(); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FamilyContextException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FileAccessException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FileNotFoundException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.ApplicationException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (SystemException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } } }
public static void Remove_Parameter(List <string> full_files_name, List <string> parm_to_add) { // UIDocument uidoc = this.ActiveUIDocument; // Document CachedDoc = uidoc.Document; Document doc; //Application app; //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1"; // loop through all files in the directory foreach (string filename in full_files_name) { doc = CachedApp.OpenDocumentFile(filename); try { if (doc.IsFamilyDocument) { FamilyManager fm = doc.FamilyManager; Transaction trans = new Transaction(doc, "Remove Param"); using (trans) { //ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName"); foreach (string s in parm_to_add) { trans.Start(); FamilyParameter fp = RawConvertSetToList <FamilyParameter>(fm.Parameters). FirstOrDefault(e => e.Definition.Name.Equals(s, StringComparison.CurrentCultureIgnoreCase)); // TaskDialog.Show("Revit","Shared Parameter !!"); if (fp == null) { throw new Exception("Invalid ParameterName Input!"); } fm.RemoveParameter(fp); trans.Commit(); } // doc.SaveAs(filename); doc.Close(true); } } } catch (Autodesk.Revit.Exceptions.ArgumentNullException ae) { TaskDialog.Show("Revit", ae.ToString()); //trans.Commit(); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FamilyContextException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FileAccessException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FileNotFoundException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.ApplicationException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (SystemException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } } //TaskDialog.Show("Iam","Here"); }
// public void Rename_Shared_Parameters(string p_name,string new_name) // { //// UIDocument uidoc = this.ActiveUIDocument; //// Document CachedDoc = uidoc.Document; // Document doc; // //Application app; // string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1"; // // // loop through all files in the directory // // foreach (string filename in System.IO.Directory.GetFiles(folder)) // { // try // { // doc = Application.OpenDocumentFile(filename); // if (doc.IsFamilyDocument) // { // // Transaction trans = new Transaction(doc, "Remove Param"); // trans.Start(); // using(trans) // { // //ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName"); // FamilyManager fm = doc.FamilyManager; // FamilyParameter fp = RawConvertSetToList<FamilyParameter>(fm.Parameters). // FirstOrDefault(e => e.Definition.Name.Equals(p_name, StringComparison.CurrentCultureIgnoreCase)); // if (fp == null) throw new Exception("Invalid ParameterName Input!"); // if(fp.IsShared) // { // ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), p_name); //// Guid guid = extdef.GUID; //// ParameterType type = extdef.ParameterType; //// string group_name = extdef.ParameterGroup.ToString(); // // //Create_SP(new_name,type,group_name); // //// fm.ReplaceParameter(fp,"temp_test",BuiltInParameterGroup.PG_TEXT,true); //// FamilyParameter new_fp = RawConvertSetToList<FamilyParameter>(fm.Parameters). //// FirstOrDefault(e => e.Definition.Name.Equals("temp_test", StringComparison.CurrentCultureIgnoreCase)); //// ExternalDefinition new_extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), new_name); //// fm.ReplaceParameter(new_fp,new_extdef,new_extdef.ParameterGroup,true); // } // trans.Commit(); // // doc.SaveAs(filename); // doc.Close(true); // } // } // // } // catch (Autodesk.Revit.Exceptions.ArgumentNullException ae) // { // TaskDialog.Show("Revit",ae.ToString()); // // return; // } // catch (Autodesk.Revit.Exceptions.FamilyContextException ae) // { // TaskDialog.Show("Revit",ae.ToString()); // // return; // } // catch (Autodesk.Revit.Exceptions.FileAccessException ae) // { // TaskDialog.Show("Revit",ae.ToString()); // // return; // } // catch (Autodesk.Revit.Exceptions.FileNotFoundException ae) // { // TaskDialog.Show("Revit",ae.ToString()); // // return; // } // catch (Autodesk.Revit.Exceptions.ApplicationException ae) // { // TaskDialog.Show("Revit",ae.ToString()); // return; // } // catch (SystemException ae) // { // TaskDialog.Show("Revit",ae.ToString()); // //return; // } // } // // //TaskDialog.Show("Iam","Here"); // // } /* public static string GetParameterValue(FamilyParameter p) * { * switch(p.StorageType) * { * case StorageType.Double: * return p.AsValueString(); * case StorageType.ElementId: * return p.AsElementId().IntegerValue.ToString(); * case StorageType.Integer: * return p.AsValueString(); * case StorageType.None: * return p.AsValueString(); * case StorageType.String: * return p.AsString(); * default: * return ""; * * } * }*/ public static void Rename_Family_Parameters(List <string> full_files_name) { // UIDocument uidoc = this.ActiveUIDocument; // Document CachedDoc = uidoc.Document; Document doc; //Application app; //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1"; // loop through all files in the directory foreach (string filename in full_files_name) { doc = CachedApp.OpenDocumentFile(filename); try { if (doc.IsFamilyDocument) { Transaction trans = new Transaction(doc, "Rename Param"); using (trans) { //string s = Globals.new_name_for_rename; trans.Start(); FamilyManager fm = doc.FamilyManager; FamilyParameter fp = RawConvertSetToList <FamilyParameter>(fm.Parameters). FirstOrDefault(e => e.Definition.Name.Equals(Globals.parm_to_Replace, StringComparison.CurrentCultureIgnoreCase)); // TaskDialog.Show("Revit","Shared Parameter !!"); trans.Commit(); if (fp.IsShared) { // TaskDialog.Show("Revit",fm.Types.Size.ToString()); // Element e = FilteredElementCollector(doc).OfClass(fm.CurrentType); // Parameter p = fm.Parameter(fp.Definition); // if (fp == null) throw new Exception("Invalid ParameterName Input!"); // string tmp = "Parameter name: "+ fp.Definition.Name + "\n" +"Is Shared!"; //TaskDialog.Show("Warrning",tmp); ExternalDefinition edf; // if(!Globals.all_SP_variables.Contains(fp.Definition.Name)) edf = Create_SP(Globals.new_name_for_rename, Globals.new_type, Globals.new_group); trans.Start(); fm.AddParameter(edf, edf.ParameterGroup, Globals.instance_or_not); // fm.Parameter(edf.Name).Set(fp.ToString()); FamilyParameter fp_tmp = fm.get_Parameter(Globals.new_name_for_rename); foreach (FamilyType t in fm.Types) { if (t.HasValue(fp)) { //TaskDialog.Show("R","Here"); fm.CurrentType = t; if (fp_tmp.StorageType == StorageType.Double) { fm.Set(fp_tmp, t.AsDouble(fp).Value); } else if (fp_tmp.StorageType == StorageType.Integer) { fm.Set(fp_tmp, t.AsInteger(fp).Value); } else if (fp_tmp.StorageType == StorageType.ElementId) { fm.Set(fp_tmp, t.AsElementId(fp).IntegerValue); } else if (fp_tmp.StorageType == StorageType.String) { fm.Set(fp_tmp, t.AsString(fp)); } } // TaskDialog.Show("R",); } //fm.Types trans.Commit(); trans.Start(); fm.RemoveParameter(fp); trans.Commit(); // string k = "Parameter name: "+ edf.Name + "\n" +"Is Shared!"; // TaskDialog.Show("Warrning",k); // fm.AddParameter(); // rename_in_shared_parm_file(fp.Definition.Name,Globals.new_name_for_rename); //doc.Close(false); continue; } // if (fp == null) throw new Exception("Invalid ParameterName Input!"); // fm.RenameParameter(fp,new_name); // Test(); trans.Commit(); //ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName"); // FamilyManager fm = doc.FamilyManager; // FamilyParameter fp = RawConvertSetToList<FamilyParameter>(fm.Parameters). // FirstOrDefault(e => e.Definition.Name.Equals(p_name, StringComparison.CurrentCultureIgnoreCase)); // if (fp == null) throw new Exception("Invalid ParameterName Input!"); // fm.RenameParameter(fp,new_name); // trans.Commit(); // doc.SaveAs(filename); doc.Close(true); } } } catch (Autodesk.Revit.Exceptions.ArgumentNullException ae) { TaskDialog.Show("Revit", ae.ToString()); //trans.Commit(); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FamilyContextException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FileAccessException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.FileNotFoundException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (Autodesk.Revit.Exceptions.ApplicationException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } catch (SystemException ae) { TaskDialog.Show("Revit", ae.ToString()); doc.Close(false); // return; } } //TaskDialog.Show("Iam","Here"); }
public void ConvertSharedParameterToFamilyParameter(ExternalDefinition extDef, FamilyManager famMan, bool instance, string type, object value) { FamilyParameter fp = famMan.AddParameter(extDef, extDef.ParameterGroup, instance); if (value != null) { RawSetFamilyParameterValue(famMan, type, fp, value); } }
Stream(ArrayList data, FamilyManager famManager) { data.Add(new Snoop.Data.ClassSeparator(typeof(FamilyManager))); data.Add(new Snoop.Data.Object("Current type", famManager.CurrentType)); data.Add(new Snoop.Data.Enumerable("Parameters", famManager.Parameters)); data.Add(new Snoop.Data.Enumerable("Types", famManager.Types)); }
public void CaptureImage( FamilyManager.CoreViewController.OnCaptureComplete onCaptureComplete ) { Parent.BeginPictureCapture( onCaptureComplete ); }
/// <summary> /// constructor of DoubleHungWinCreation /// </summary> /// <param name="para">WizardParameter</param> /// <param name="commandData">ExternalCommandData</param> public DoubleHungWinCreation(WizardParameter para, ExternalCommandData commandData) : base(para) { m_application = commandData.Application; m_document = commandData.Application.ActiveUIDocument.Document; m_familyManager = m_document.FamilyManager; CollectTemplateInfo(); para.Validator = new ValidateWindowParameter(m_wallHeight, m_wallWidth); switch (m_document.DisplayUnitSystem) { case Autodesk.Revit.DB.DisplayUnit.METRIC: para.Validator.IsMetric = true; break; case Autodesk.Revit.DB.DisplayUnit.IMPERIAL: para.Validator.IsMetric = false; break; } para.PathName = Path.GetDirectoryName(para.PathName) + "Double Hung.rfa"; CreateCommon(); }
public ParameterAssigner(Autodesk.Revit.ApplicationServices.Application app, Document doc) { m_app = app; m_manager = doc.FamilyManager; }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document document; string assemblyPath; document = commandData.Application.ActiveUIDocument.Document; assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); m_logFileName = assemblyPath + "\\RegenerationLog.txt"; //only a family document can retrieve family manager if (document.IsFamilyDocument) { m_familyManager = document.FamilyManager; //create regeneration log file StreamWriter writer = File.CreateText(m_logFileName); writer.WriteLine("Family Type Result"); writer.WriteLine("-------------------------"); writer.Close(); using(MessageForm msgForm=new MessageForm()) { msgForm.StartPosition = FormStartPosition.Manual; CheckTypeRegeneration(msgForm); return Autodesk.Revit.UI.Result.Succeeded; } } else { message = "please make sure you have opened a family document!"; return Autodesk.Revit.UI.Result.Failed; } }