Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Result Execute error CS0161, not all code paths return values

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
jw.vanasselt
287 Views, 3 Replies

Result Execute error CS0161, not all code paths return values

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

 

Labels (3)
3 REPLIES 3
Message 2 of 4
jw.vanasselt
in reply to: jw.vanasselt

Post can be deleted, line 70 was on wrong position.

Message 3 of 4
jw.vanasselt
in reply to: jw.vanasselt

Post can be deleted, line 70 was on wrong position.
Message 4 of 4

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.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community