Message 1 of 8
Rebar selected column
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello forum.
I'm trying to code a program in order to rebar a selected column from the user using "Create From Curves", but i found a problem, when I execute the code an error message was shown :
"Référence d'objet n'est pas définie a une instance d'un objet"
The RebarBarType argument was extracted from a selected rebar
Source Code :
try
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document; ;
//select the column
Reference reff = uidoc.Selection.PickObject(ObjectType.Element);
ElementId idd = reff.ElementId;
FamilyInstance P1 = doc.GetElement(idd) as FamilyInstance;
//select the rebar
Reference reff2 = uidoc.Selection.PickObject(ObjectType.Element);
ElementId idd2 = reff2.ElementId;
Rebar P2 = doc.GetElement(idd2) as Rebar;
//get the rebar bar type
RebarBarType RT = P2.Document.GetElement(P2.GetTypeId()) as RebarBarType;
using (Transaction trns = new Transaction(doc,"Rebar"))
{
trns.Start();
LocationPoint location = P1.Location as LocationPoint;
XYZ origin = location.Point;
XYZ normal = new XYZ(1, 0, 0);
XYZ rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 2);
Line rebarLine = Line.CreateBound(origin, rebarLineEnd);
IList<Curve> curves = new List<Curve>();
curves.Add(rebarLine);
Rebar rebar = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, RT, null, null,
P1, normal, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);
trns.Commit();
}
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
TaskDialog.Show("error",message);
return Result.Failed;
}
But i can't locate the source of the problem
Thank you.