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: 

GetEndPointReference null from analytical curve

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
GeomGym
733 Views, 3 Replies

GetEndPointReference null from analytical curve

Hi,

 

In Revit 2014, I can't successfully get a point reference so I can create a boundary condition.  A null is returned and I'm not sure why (after the transaction finishes, I can manually create a boundary condition).

 

Sample code to reproduce this is below.

 

Thanks,

 

Jon

 

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class ImportIFCGeomGym : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{

Document doc = commandData.Application.ActiveUIDocument.Document;
Transaction trn = new Transaction(doc, "ggTest");
trn.Start();
int cat = (int)BuiltInCategory.OST_StructuralFraming;
FamilySymbol fs = null;
FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol));
foreach (FamilySymbol f in fec)
{
if (f != null & f.Category.Id.IntegerValue == cat)
{
fs = f;
break;
}
}
Level lvl = null;
fec = new FilteredElementCollector(doc).OfClass(typeof(Level));
foreach (Level l in fec)
{
if (l != null)
{
lvl = l;
break;
}
}
Line line = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 3, 0));
FamilyInstance fi = doc.Create.NewFamilyInstance(line, fs, lvl, StructuralType.Beam);
doc.Regenerate();
AnalyticalModel am = fi.GetAnalyticalModel();
if (am != null)
{
if (am.IsSingleCurve())
{
Autodesk.Revit.DB.Curve c = am.GetCurve();
if (c.GetEndPointReference(0) == null)
System.Windows.Forms.MessageBox.Show("Null REference!");
}
}
trn.Commit();
return Result.Succeeded;
}
}

3 REPLIES 3
Message 2 of 4
Scott_Wilson
in reply to: GeomGym

I've not played with the analytical model before, but looking at the API reference I think this is what you need to do:

 

if (am.IsSingleCurve())
{
Autodesk.Revit.DB.Curve c = am.GetCurve();

 

AnalyticalModelSelector ams = new AnalyticalModelSelector(c, AnalyticalCurveSelector.StartPoint);

 

Reference startRef = am.GetReference(ams);


if (startRef == null)
System.Windows.Forms.MessageBox.Show("Null REference!");
}

 

I've not tested this, but it's something to try.

 

Could just be that Revit doesn't fully develop the analytical model until the transaction is commited, there's a few things that a Regenerate() just can't fix 😞

Message 3 of 4
GeomGym
in reply to: Scott_Wilson

Hi Scott,

Thanks for the answer, this seems to work well. I'd be interested to know where you found this in the documentation (and how). I did search for a while but didn't turn up anything like this.

Thanks again,

Jon
Message 4 of 4
Scott_Wilson
in reply to: GeomGym

I'm just lucky I guess Smiley LOL

 

What I normally do if I need to do something new with the API (and google has failed me...) is just go to the relevant class definitions in visual studio and browse through the members. If I need more clarification I look it up in the API reference. If that doesn't help I just start messing with code while stepping through with the debugger to see what's actually going on. I have a good diagnostics and rapid prototyping framework which has evolved over time that handles all the boring stuff and lets me get right at the problem quickly.

 

Anyway, I'm glad to be of assistance. The main reason I get on here and try to solve problems is that it I love a good puzzle and it gets me looking into parts of the API that I havn't seen before.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community