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; StreamReader reader = new StreamReader(@"C:\Users\user\AppData\Roaming\Autodesk\Revit\Addins\2016\Buffer.txt"); FamilyPath = reader.ReadToEnd(); reader.Close(); Family family = null; // TaskDialog.Show("Family Path", FamilyPath); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfCategory(BuiltInCategory.OST_ElectricalFixtures); collector.OfClass(typeof(FamilySymbol)); //List<string> Symbols = null; //foreach (var item in collector) //{ // if (item.Name != "GFCI" && // item.Name != "Standard" && // item.Name != "Plain") // Symbols.Add(item.Name); //} //foreach (var item in Symbols) //{ // FileWriter(item); //} //TaskDialog.Show("Family symbols", Symbols); FamilySymbol symbol = collector.FirstElement() as FamilySymbol; TaskDialog.Show("Family Path", FamilyPath); using (var trans = new Transaction(doc, "Insert Transaction")) { trans.Start(); if (!doc.LoadFamily(FamilyPath, out family)) { TaskDialog.Show("Loading", "Unable to load " + family); } ISet <ElementId> familySymbolId = family.GetFamilySymbolIds(); foreach (ElementId id in familySymbolId) { symbol = family.Document.GetElement(id) as FamilySymbol; } trans.Commit(); } TaskDialog.Show("Symbol", symbol.Name); uidoc.PromptForFamilyInstancePlacement(symbol); return(Result.Succeeded); }
public void Execute(UIApplication app) { Transaction trans = new Transaction(app.ActiveUIDocument.Document, "Получить выбранные семейства"); trans.Start(); UIDocument uidoc = app.ActiveUIDocument; Autodesk.Revit.DB.Document doc = uidoc.Document; XYZ xYZ = new XYZ(0, 0, 0); //try //{ // doc.Create.NewFamilyInstance(xYZ, familyDto.FamilySymbolDto, uidoc.ActiveView); //} //catch (Exception ex) //{ // TaskDialog.Show(ex.Message.ToString(), ex.Message.ToString()); //} trans.Commit(); try { if (familyDto.FamilySymbolDto == null) { MessageBox.Show("Выбранное семейство отсутствует в проекте", "Ошибка"); } else { uidoc.PromptForFamilyInstancePlacement(familyDto.FamilySymbolDto as FamilySymbol); } } catch { } }
/////////////////////////////////////////////////////////////////////////////////////////// //////////////// Place a named element in the document //////////////////////////////// public void PlaceNamedElement(UIDocument uiDoc, string name) { FamilySymbol symbol = GetElements <FamilySymbol>(uiDoc.Document) .Where(i => i.Name == name) .First(); uiDoc.PromptForFamilyInstancePlacement(symbol); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { //_revit_window // = new JtWindowHandle( // ComponentManager.ApplicationWindow ); // 2018 UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; _revit_window = uiapp.MainWindowHandle; // 2019 FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfCategory(BuiltInCategory.OST_Doors); collector.OfClass(typeof(FamilySymbol)); FamilySymbol symbol = collector.FirstElement() as FamilySymbol; _added_element_ids.Clear(); app.DocumentChanged += new EventHandler <DocumentChangedEventArgs>( OnDocumentChanged); //PromptForFamilyInstancePlacementOptions opt // = new PromptForFamilyInstancePlacementOptions(); try { uidoc.PromptForFamilyInstancePlacement(symbol); } catch (Autodesk.Revit.Exceptions.OperationCanceledException ex) { Debug.Print(ex.Message); } app.DocumentChanged -= new EventHandler <DocumentChangedEventArgs>( OnDocumentChanged); int n = _added_element_ids.Count; TaskDialog.Show( "Place Family Instance", string.Format( "{0} element{1} added.", n, ((1 == n) ? "" : "s"))); return(Result.Succeeded); }
public void Execute(UIDocument document, object data) { ElementId familySymbolId = (ElementId)data; FamilySymbol symbol = document.Document.GetElement(familySymbolId) as FamilySymbol; if (symbol != null) { document.PromptForFamilyInstancePlacement(symbol); } }
public void Execute(UIDocument document, object data) { try { ElementId familySymbolId = (ElementId)data; FamilySymbol symbol = document.Document.GetElement(familySymbolId) as FamilySymbol; if (symbol != null) { document.PromptForFamilyInstancePlacement(symbol); } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { // user canceled the operation } }
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; FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfCategory(BuiltInCategory.OST_GenericAnnotation); collector.OfClass(typeof(FamilySymbol)); FamilySymbol symbol = collector.FirstElement() as FamilySymbol; _added_element_ids.Clear(); app.DocumentChanged += new EventHandler <DocumentChangedEventArgs>( OnDocumentChanged); uidoc.PromptForFamilyInstancePlacement(symbol); app.DocumentChanged -= new EventHandler <DocumentChangedEventArgs>( OnDocumentChanged); int n = _added_element_ids.Count; TaskDialog.Show( "Place Family Instance", string.Format( "{0} D-Note{1} added.", n, ((1 == n) ? "" : "s"))); return(Result.Succeeded); }
/// <summary> /// Place a <paramref name="familySymbol"/> in <paramref name="uiDocument"/>. /// </summary> /// <param name="uiDocument">Specifies the document to place the family symbol in.</param> /// <param name="familySymbol">Specifies the symbol that must be placed.</param> public void PlaceFamilyInstance(UIDocument uiDocument, FamilySymbol familySymbol) { using (var executionBlock = monitoredExecutionContext .MonitorMethod <ElementHelper>(nameof(PlaceFamilyInstance)) .WithParameter(nameof(uiDocument), uiDocument) .WithParameter(nameof(familySymbol), familySymbol) .WithTiming()) { try { uiDocument.PromptForFamilyInstancePlacement(familySymbol); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } catch (Exception exception) { executionBlock.LogException(exception); throw; } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var dfdf = Directory.GetFiles(@"C:\ProgramData\Autodesk\Revit\Addins\2019\FamilyPalette.xml"); UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.DB.Document doc = uidoc.Document; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Selection sel = uiapp.ActiveUIDocument.Selection; ICollection <Autodesk.Revit.DB.ElementId> selectedIds = uidoc.Selection.GetElementIds(); //Reference annotation = sel.PickObject(ObjectType.Element, "Select item"); FamilyInstance elem = doc.GetElement(selectedIds.FirstOrDefault()) as FamilyInstance; //Reference annotation = sel.PickObject(ObjectType.Element, "Select item"); //FamilyInstance elem = doc.GetElement(annotation) as FamilyInstance; FamilySymbol familySymbol = elem.Symbol; PromptForFamilyInstancePlacementOptions promptForFamilyInstancePlacementOptions = new PromptForFamilyInstancePlacementOptions(); try { uidoc.PromptForFamilyInstancePlacement(familySymbol); } catch { } return(Result.Succeeded); }
public void Execute(UIApplication uiappp) { uiapp = uiappp; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; /// TECHNIQUE 06 OF 19 (EE06_PlaceAFamily_OnDoubleClick.cs) ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ PLACING A FAMILY THEN RELEASING THE COMMMAND ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ /// /// Interfaces and ENUM's: /// BuiltInParameter.FAMILY_WORK_PLANE_BASED /// using System.Runtime.InteropServices (namespace) /// /// Demonstrates classes: /// DocumentChangedEventArgs* /// PromptForFamilyInstancePlacementOptions /// SketchPlane /// /// /// Key methods: /// SketchPlane.Create(doc, myLevel.GetPlaneReference()); /// uidoc.PromptForFamilyInstancePlacement(myFamilySymbol); /// SetForegroundWindow( /// keybd_event( /// /// /// * class is actually part of the .NET framework (not Revit API) /// /// /// /// https://github.com/joshnewzealand/Revit-API-Playpen-CSharp /// uidoc.Application.Application.DocumentChanged += new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); PromptForFamilyInstancePlacementOptions myPromptForFamilyInstancePlacementOptions = new PromptForFamilyInstancePlacementOptions(); if (uidoc.ActiveView.SketchPlane.Name != "Level 1") { Level myLevel = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().First() as Level; using (Transaction y = new Transaction(doc, "SetDefaultPlane")) { y.Start(); uidoc.ActiveView.SketchPlane = SketchPlane.Create(doc, myLevel.GetPlaneReference()); y.Commit(); } } myPromptForFamilyInstancePlacementOptions.FaceBasedPlacementType = FaceBasedPlacementType.Default; SetForegroundWindow(uidoc.Application.MainWindowHandle); //this is an excape event try { if (myFamilySymbol.Family.get_Parameter(BuiltInParameter.FAMILY_WORK_PLANE_BASED).AsInteger() == 0) { uidoc.PromptForFamilyInstancePlacement(myFamilySymbol); } else { uidoc.PromptForFamilyInstancePlacement(myFamilySymbol, myPromptForFamilyInstancePlacementOptions); //<-- decided not to use this late in the project } } #region catch and finally catch (Exception ex) { if (ex.Message != "The user aborted the pick operation.") { _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("EE01_Part1_PlaceAFamily" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true); } else { uidoc.Application.Application.DocumentChanged -= new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); } } finally { } #endregion }
public override int Execute(ref ScriptRuntime runtime) { #if (REVIT2013 || REVIT2014) TaskDialog.Show(PyRevitLabsConsts.ProductName, NotSupportedFeatureException.NotSupportedMessage); return(ScriptExecutorResultCodes.NotSupportedFeatureException); #else if (runtime.UIApp != null && runtime.UIApp.ActiveUIDocument != null) { string familySourceFile = runtime.ScriptSourceFile; UIDocument uidoc = runtime.UIApp.ActiveUIDocument; Document doc = uidoc.Document; // find or load family first Family contentFamily = null; // attempt to find previously loaded family Element existingFamily = null; string familyName = Path.GetFileNameWithoutExtension(familySourceFile); var currentFamilies = new FilteredElementCollector(doc).OfClass(typeof(Family)).Where(q => q.Name == familyName); if (currentFamilies.Count() > 0) { existingFamily = currentFamilies.First(); } if (existingFamily != null) { contentFamily = (Family)existingFamily; } // if not found, attemt to load if (contentFamily == null) { try { var txn = new Transaction(doc, "Load pyRevit Content"); txn.Start(); doc.LoadFamily( familySourceFile, new ContentLoaderOptions(), out contentFamily ); txn.Commit(); } catch (Exception loadEx) { var dialog = new TaskDialog(PyRevitLabsConsts.ProductName); dialog.MainInstruction = "Failed loading content."; dialog.ExpandedContent = string.Format("{0}\n{1}", loadEx.Message, loadEx.StackTrace); dialog.Show(); return(ScriptExecutorResultCodes.FailedLoadingContent); } } if (contentFamily == null) { TaskDialog.Show(PyRevitLabsConsts.ProductName, string.Format("Failed finding or loading bundle content at:\n{0}", familySourceFile)); return(ScriptExecutorResultCodes.FailedLoadingContent); } // now ask ui to place an instance ElementId firstSymbolId = contentFamily.GetFamilySymbolIds().First(); if (firstSymbolId != null && firstSymbolId != ElementId.InvalidElementId) { FamilySymbol firstSymbol = (FamilySymbol)doc.GetElement(firstSymbolId); if (firstSymbol != null) { try { var placeOps = new PromptForFamilyInstancePlacementOptions(); uidoc.PromptForFamilyInstancePlacement(firstSymbol, placeOps); return(ScriptExecutorResultCodes.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { // user cancelled placement return(ScriptExecutorResultCodes.Succeeded); } }
/// <summary> /// External command mainline /// </summary> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Confirm App has been initialized Initilize c = new Initilize(); bool success = c.IsAppInitialized(); if (!success) { return(Result.Cancelled); } else { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; Selection selection = uidoc.Selection; //Retrieve the family if it is already present: FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(Family)); Family family = a.FirstOrDefault <Element>(e => e.Name.Equals(FamilyName)) as Family; //Check to make sure the user is on a sheet otherwise cancel View activeView = doc.ActiveView; if (!(activeView is ViewSheet)) { TaskDialog.Show("ERROR!", "You must be on a sheet to place DNotes"); return(Result.Cancelled); } //Get the active sheet number Parameter activeSheetNumber; activeSheetNumber = activeView.get_Parameter(BuiltInParameter.SHEET_NUMBER); string sheet_number = activeSheetNumber.AsString(); //Verify that the family path is valid and load the family if (null == family) { if (!File.Exists(FamilyPath)) { //Utilities.Util.ErrorMsg(string.Format( // "Please ensure that the DNote " // + "family file '{0}' exists in '{1}'.", // FamilyName, _family_folder)); OAToolsUpdater.Updater c2 = new Updater(); bool success2 = c2.getDNoteFile(); if (!success2) { TaskDialog.Show("ERROR!", "Cannot download the DNote .rfa file. ERROR CODE:1777"); return(Result.Failed); } } // It is not present, so load it: using (Transaction tx = new Transaction(doc)) { tx.Start("Load Family"); doc.LoadFamily(FamilyPath, out family); tx.Commit(); } } //Create the symbol var FamilySymbol symbol = null; //Retrieve the symbol id's //This has to happen after the family has been loaded ISet <ElementId> symbolIds = family.GetFamilySymbolIds(); //Loop through the id's, There will only be one, set symbol var foreach (ElementId id in symbolIds) { symbol = doc.GetElement(id) as FamilySymbol; } // Place the family symbol: //Subscribe to document changed event to retrieve family instance elements added by the PromptForFamilyInstancePlacement operation: app.DocumentChanged += new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); _added_element_ids.Clear(); // PromptForFamilyInstancePlacement cannot // be called inside transaction. uidoc.PromptForFamilyInstancePlacement(symbol); app.DocumentChanged -= new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); // Access the newly placed family instances: int n = _added_element_ids.Count(); //Show the form frmCreateDNote form = new frmCreateDNote(sheet_number); form.ShowDialog(); //Get the data from the form string DNoteNumberValue = string.Empty; DNoteNumberValue = frmCreateDNote.DNoteNumberInput; string DNoteSheetValue = string.Empty; DNoteSheetValue = frmCreateDNote.DNoteSheetInput; string DNoteTextValue = string.Empty; DNoteTextValue = frmCreateDNote.DNoteTextInput; using (Transaction tx = new Transaction(doc, "Set Parameter")) { tx.Start("Set Parameters"); //Set the parameters if (0 == symbolIds.Count) { TaskDialog.Show("Error", "No elements selected"); } else { foreach (ElementId id in _added_element_ids) { //Gets the element associated with the ID Element eFromId = doc.GetElement(id); ParameterSet pSet = eFromId.Parameters; foreach (Parameter param in pSet) { if (param.Definition.Name.Contains("Number")) { param.Set(DNoteNumberValue); } if (param.Definition.Name.Contains("Sheet")) { param.Set(DNoteSheetValue); } if (param.Definition.Name.Contains("Text")) { param.Set(DNoteTextValue); } } } } tx.Commit(); } //Construct the message string msg = string.Format("Placed {0} {1} family instance{2}{3}", n, family.Name, Utilities.Util.PluralSuffix(n), Utilities.Util.DotOrColon(n)); string ids = string.Join(", ", _added_element_ids.Select <ElementId, string>(id => id.IntegerValue.ToString())); //Show the message //Util.InfoMsg2(msg, ids); return(Result.Succeeded); } }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; // Retrieve elements from database FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(Family)); Family family = a.FirstOrDefault <Element>(e => e.Name.Equals(Familyname)) as Family; // Filtered element collector is iterable if (null == family) { // It is not present, so check for // the file to load it from: if (!File.Exists(FamilyPath)) { // System.Security.Util.ErrorMsg(string.Format("Please ensure that the sample table " + "family file '{0}' exists in '{1}'.",Familyname, _family_folder)); return(Result.Failed); } // Load family from file: using (Transaction tx = new Transaction(doc)) { tx.Start("Load Family"); doc.LoadFamily(FamilyPath, out family); tx.Commit(); } FamilySymbol symbol; symbol = null; foreach (ElementId eid in family.GetFamilySymbolIds()) { Element element = doc.GetElement(eid); FamilySymbol s = element as FamilySymbol; symbol = s; // Our family only contains one // symbol, so pick it and leave break; } uidoc.PromptForFamilyInstancePlacement(symbol); } //Modify document within a transaction else { foreach (ElementId eleid in family.GetFamilySymbolIds()) { Element ele = doc.GetElement(eleid); FamilySymbol s = ele as FamilySymbol; symbol1 = s; // Our family only contains one // symbol, so pick it and leave break; } uidoc.PromptForFamilyInstancePlacement(symbol1); //Place the family symbol: //PromptForFamilyInstancePlacement cannot //be called inside transaction. } return(Result.Succeeded); }