Message 1 of 5
Create Dimmension for Rebar
Not applicable
04-05-2018
10:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I'm trying to create Dimmension for rebar using API. My code:
FilteredElementCollector rcollector = new FilteredElementCollector(doc,doc.ActiveView.Id).WhereElementIsNotElementType();
//get rebar, vertical on current view
IList<Element> rebsonview =rcollector.OfCategory(BuiltInCategory.OST_Rebar).ToElements();
var vertRebar = rebsonview.FirstOrDefault(x => ((x as Rebar).GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves).First() as Line).Direction.IsAlmostEqualTo(doc.ActiveView.UpDirection.Normalize()) || ((x as Rebar).GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves).First() as Line).Direction.IsAlmostEqualTo(doc.ActiveView.UpDirection.Negate().Normalize()));
ReferenceArray secRefarr = new ReferenceArray();
//Get geomerty for rebar, in Coarse detail level geometry will be just a Line
Options ropt = new Options();
ropt.ComputeReferences = true;
ropt.View = doc.ActiveView;
ropt.IncludeNonVisibleObjects = false;
GeometryElement rebg = vertRebar.get_Geometry(ropt);
//get References for end points of rebars Line
secRefarr.Append((rebg.First() as Line).GetEndPointReference(0));
secRefarr.Append((rebg.First() as Line).GetEndPointReference(1));
//Create Line for Dimmension
XYZ dimmPoint = (rebg.First() as Line).GetEndPoint(0).Add(doc.ActiveView.RightDirection.Negate().Multiply(5));
Line dmmline = Line.CreateUnbound(dimmPoint2,((vertRebar as Rebar).GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves).First() as Line).Direction);
using (Transaction TR = new Transaction(doc,"Dimm"))
{
TR.Start();
doc.Create.NewDimension(doc.ActiveView,dmmline2,secRefarr);
TR.Commit();
}as a result it creates zerro Dimmension, references to end point hasn't Global point (Global point = null). I tryed to create dimm from UI? its creating correct, but references hasn't global point too.
On the screenshot on the left side is dimmension created by code and on the right side dimmension crated using user interface