Reference lines driven by reference points in Revit Family Adaptive

Reference lines driven by reference points in Revit Family Adaptive

Davide_Barbiero2DLH4
Observer Observer
233 Views
2 Replies
Message 1 of 3

Reference lines driven by reference points in Revit Family Adaptive

Davide_Barbiero2DLH4
Observer
Observer

Hi, I’m working on a GH script with Rhino.Inside to create some driving axis inside a Revit Adaptive Family. Those axis have to be Revit Reference Lines, that are driven by Revit Reference Points Adaptive. I was able to create those points with the code, but I can not figure out how to create the lines with the code so that they are connected with the points and driven by them.

Davide_Barbiero2DLH4_0-1737470283906.png

Basically what I want to achieve with Python or C#, is to create branches in order to have couples of points (start, end points), and then to create a Revit Reference Lines from that input list. Below an example of the reference line.

Davide_Barbiero2DLH4_1-1737470333857.png

 

0 Likes
234 Views
2 Replies
Replies (2)
Message 2 of 3

Davide_Barbiero2DLH4
Observer
Observer

Attached you can find the Python code block.

0 Likes
Message 3 of 3

Davide_Barbiero2DLH4
Observer
Observer

Below is another code with C# that I've tried but it is not working:

 

#r "C:\Program Files\Autodesk\Revit 2023\RevitAPI.dll"
#r "C:\Program Files\Autodesk\Revit 2023\RevitAPIUI.dll"

using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

public class CreateReferenceLines : IExternalCommand
{
    // Input: Branched list of reference points (provided via Rhino Inside Revit)
    public List<List<ReferencePoint>> ReferencePointBranches { get; set; }

    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIApplication uiApp = commandData.Application;
        Document doc = uiApp.ActiveUIDocument.Document;

        // Validate input
        if (ReferencePointBranches == null || ReferencePointBranches.Count == 0)
        {
            message = "No reference points provided.";
            return Result.Failed;
        }

        foreach (var branch in ReferencePointBranches)
        {
            if (branch.Count != 2)
            {
                message = "Each branch must contain exactly 2 ReferencePoints.";
                return Result.Failed;
            }
        }

        using (Transaction t = new Transaction(doc, "Create Reference Lines"))
        {
            t.Start();

            try
            {
                // Iterate over branches and create reference lines
                foreach (var branch in ReferencePointBranches)
                {
                    ReferencePoint point1 = branch[0];
                    ReferencePoint point2 = branch[1];

                    CreateReferenceLine(doc, point1, point2);
                }

                t.Commit();
                TaskDialog.Show("Success", "Reference lines created successfully.");
            }
            catch (Exception ex)
            {
                t.RollBack();
                TaskDialog.Show("Error", $"An error occurred: {ex.Message}");
                return Result.Failed;
            }
        }

        return Result.Succeeded;
    }

    /// <summary>
    /// Creates a reference line between two reference points.
    /// </summary>
    private void CreateReferenceLine(Document doc, ReferencePoint point1, ReferencePoint point2)
    {
        // Create a ReferencePointArray
        ReferencePointArray referencePointArray = new ReferencePointArray();
        referencePointArray.Append(point1);
        referencePointArray.Append(point2);

        // Create the reference line
        CurveByPoints curve = doc.FamilyCreate.NewCurveByPoints(referencePointArray);
        curve.IsReferenceLine = true; // Mark the curve as a reference line
    }
}
0 Likes