Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66666

SetTangentLock in ProfileSketch

$
0
0

Hi,

 

just want to share some code (maybe a bit messy, but it works). I couldn't find anything on the web that explains this. I want to set the tangency toggle in a profile sketch (image attached). Here the code to find the right line, arcs, ElementIds .....

 

ICollection<ElementId> delIds = null;
List<ElementId> enmIDs = new List<ElementId>();

using (SubTransaction delTrans = new SubTransaction(famdoc))
{
    try
    {
        delTrans.Start();
        delIds = famdoc.Delete(extrusions[0].Id);
        delTrans.RollBack();
    }
    catch (Exception ex)
    {
        System.Windows.MessageBox.Show(ex.ToString());
    }
}

// Get the model lines in the profile and use the end points for reference the sketch dimensions
// diameter
List<ModelArc> mArcsR1 = new List<ModelArc>();
List<ModelArc> mArcsR2 = new List<ModelArc>();
List<ModelLine> mLines = new List<ModelLine>();

foreach (ElementId id in delIds)
{
    enmIDs.Add(id);
}

for (int i = 0; i < enmIDs.Count; i++)
{
    Element ele = famdoc.GetElement(enmIDs[i]);
    if (ele is ModelArc)
    {
        ModelArc ma = ele as ModelArc;
        Curve c = ma.GeometryCurve;
        Arc a = c as Arc;

        if (Math.Round(r1, 6) == Math.Round(a.Radius, 6))
        {
            mArcsR1.Add(ma);
        }
        if (Math.Round(r2, 6) == Math.Round(a.Radius, 6))
        {
            mArcsR2.Add(ma);
        }
    }
    if (ele is ModelLine)
    {
        ModelLine ml = ele as ModelLine;
        Element before = null;
        Element after = null;
        ElementId beforeId = null;
        ElementId afterId = null;

        if (i > 0)
        {
            before = famdoc.GetElement(enmIDs[i - 1]);
            beforeId = enmIDs[i - 1];
        }
        else
        {
            before = famdoc.GetElement(enmIDs[enmIDs.Count - 1]);
            beforeId = enmIDs[enmIDs.Count - 1];
        }
        if (i == enmIDs.Count - 1)
        {
            after = famdoc.GetElement(enmIDs[0]);
            afterId = enmIDs[0];
        }
        else
        {
            after = famdoc.GetElement(enmIDs[i + 1]);
            afterId = enmIDs[i + 1];
        }

        if (before is ModelArc && after is ModelArc)
        {
            ml.SetTangentLock(0, beforeId, true);
            ml.SetTangentLock(1, afterId, true);
        }
    }
}

So I have an Extrusion. To get access to all the lines in the Extrusion I delete it and rollback the transaction. After that I loop through the Elements by ElementId and see if I have, when I find a Modelline, a ModelArc before and after that.

 

Hope this helps one day someone.

 

regards

Christian


Viewing all articles
Browse latest Browse all 66666

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>