Hi all,
I just started to create one of my first scripts but I have an error on the Execute row.
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows.Markup;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Reference = Autodesk.Revit.DB.Reference;
namespace MyRevitCommands
{
[Transaction(TransactionMode.Manual)]
public class PipeBreak : 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;
// Select a pipe
Reference[] references = (Reference[])uidoc.Selection.PickObjects(ObjectType.Element, "Select pipes");
foreach (Reference reference in references)
{
Pipe pipe = doc.GetElement(reference) as Pipe;
Line line = (pipe.Location as LocationCurve).Curve as Line;
double length = line.Length;
XYZ midPoint = line.Evaluate(0.5, true);
using (Transaction tr = new Transaction(doc))
{
tr.Start("Opdelen leiding");
// Breek de leiding op het midpoint, geeft element id terug
ElementId newPipeId = PlumbingUtils.BreakCurve(doc, pipe.Id, midPoint);
// pipe ophalen vanaf het id als een pipe
Pipe newPipe = doc.GetElement(newPipeId) as Pipe;
//connector manager oproepen en connector van de pipe ophalen
foreach (Connector connector in pipe.ConnectorManager.Connectors)
{
//Punt connector is orginele connector punt
XYZ connectorOriginPoint = connector.Origin;
//Connectorset aanmaken
ConnectorSet newPipeConnectorSet = newPipe.ConnectorManager.Connectors;
foreach (Connector newConnector in newPipeConnectorSet)
{
if (newConnector.Origin.DistanceTo(connectorOriginPoint) < 0.01)
{
try
{
doc.Create.NewUnionFitting(connector, newConnector);
}
catch { }
break;
}
}
}
tr.Commit();
return Result.Succeeded;
}
}
}
}
}
I guess it's in the reference line:
Reference[] references = (Reference[])uidoc.Selection.PickObjects(ObjectType.Element, "Select pipes");
When I use the PickObject-Method it works fine, but it doesnt work with the PickObjects-Method
Can someone help me?
Kind Regards,
Jan Willem
Solved! Go to Solution.
Solved by jw.vanasselt. Go to Solution.
Thank you for letting us know the problem is resolved. Unfortunately, I do not know how to delete the post. I'll just mark it as solved by your fix.
Can't find what you're looking for? Ask the community or share your knowledge.