- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
Recently I try to make a UpdaterRegistry that would make a proper connection with Valves, I start wit trying to make a FamilyInstance between Pipe and FamilyInstance(PipeAccesssory), but i observe few problems:
1) for some reason Execute run twice for one pipe created
2) I can create instance between valve and pipe, but I can't connect valve to new instance. There is no error message, I can't catch any exception. On end only appear message that it fail.
3) I can move created pipe with pop up alert and i can move a Instance but I can't connect anything.
I try different things but in this point, when I rarely get error message it can be dificult
Here is code:
Main
[Transaction(TransactionMode.Manual)] public class Command : IExternalCommand { 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; // Register the ElementUpdater1 try { UpdaterRegistry.UnregisterUpdater(new ElementUpdater1(uiapp.ActiveAddInId).GetUpdaterId()); if (true) { ElementUpdater1 updater1 = new ElementUpdater1(uiapp.ActiveAddInId); pipesrun(updater1); } } catch { ElementUpdater1 updater1 = new ElementUpdater1(uiapp.ActiveAddInId); pipesrun(updater1); } return Result.Succeeded; } public void pipesrun(ElementUpdater1 updater1) { UpdaterRegistry.RegisterUpdater(updater1); ElementCategoryFilter catFilter = new ElementCategoryFilter(Autodesk.Revit.DB.BuiltInCategory.OST_PipeCurves); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeElementAddition()); } }
//Updater
public class ElementUpdater1 : IUpdater { private AddInId mAddinId; private UpdaterId mUpdaterId; public ElementUpdater1(AddInId id) { mAddinId = id; mUpdaterId = new UpdaterId(mAddinId, new Guid("69c641d9-c838-42bb-983f-d30b8d01d4bb")); } #region IUpdater Members public void Execute(UpdaterData data) { Document doc = data.GetDocument(); ICollection<ElementId> addedIds = data.GetAddedElementIds(); foreach (ElementId id in addedIds) { Element element = doc.GetElement(id); try { List<ValveData> valveDataList = Detect_Element.DetectIfPipeIsConnected(element); Valve_Manage_Test.Detect_Element.makes(doc, valveDataList); } catch (Exception e) { TaskDialog.Show("Error", e.InnerException.Message + e.HResult + e.Data.ToString() + e.Message); } } } public string GetAdditionalInformation() { return "ElementUpdater1"; } public ChangePriority GetChangePriority() { return Autodesk.Revit.DB.ChangePriority.MEPSystems; } public UpdaterId GetUpdaterId() { return mUpdaterId; } public string GetUpdaterName() { return "ElementUpdater1"; } #endregion }
and to a metod that create
public static void makes(Document document, List<ValveData> vdList) { ElementManager EM = new ElementManager(document); LevelManager LM = new LevelManager(document); Family family = EM.find.FamilyFind("M_Połączenie - ogólne"); FamilySymbol familySymbol = EM.find.SymbolFind(family.GetFamilySymbolIds().FirstOrDefault().IntegerValue); try { //using (Transaction transaction = new Transaction(document)) { // transaction.Start("addingfamily"); foreach (ValveData valveData in vdList) { FamilyInstance fi = document.Create.NewFamilyInstance(valveData.valveConnector.Origin, familySymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); foreach (Connector cfi in fi.MEPModel.ConnectorManager.Connectors) { if (cfi.CoordinateSystem.BasisZ.IsAlmostEqualTo(-valveData.valveConnector.CoordinateSystem.BasisZ, 0.001)) { XYZ move = valveData.valveConnector.Origin - cfi.Origin; fi.Location.Move(move); //cfi.ConnectTo(valveData.valveConnector); } } foreach (Connector cfi in fi.MEPModel.ConnectorManager.Connectors) { if (cfi.CoordinateSystem.BasisZ.IsAlmostEqualTo(-valveData.pipeConnector.CoordinateSystem.BasisZ, 0.001)) { valveData.pipeConnector.Origin = cfi.Origin; //valveData.pipeConnector.ConnectTo(cfi); } } } //transaction.Commit(); } } catch(Exception e) { TaskDialog.Show("Error", e.Message); } return; }
I try to make it in first place by the app.DocumentChanged event but I get the same thing that was mention in this post
https://forums.autodesk.com/t5/revit-api-forum/documentchanged-event-and-additional-editing/td-p/687...
___________________________________________________________________________________________
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Solved! Go to Solution.