Create Dimmension for Rebar

Create Dimmension for Rebar

Anonymous
Not applicable
929 Views
4 Replies
Message 1 of 5

Create Dimmension for Rebar

Anonymous
Not applicable

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

0 Likes
930 Views
4 Replies
Replies (4)
Message 2 of 5

aignatovich
Advisor
Advisor

Hi!

 

Are you sure that first line from rebar geometry is vertical line in desired view? You filter rebars in the view by their centerline direction, but maybe your rebar geometry has other lines?

0 Likes
Message 3 of 5

Anonymous
Not applicable

Yes, I'm sure. I tested several variants and for Coarse detail view and simple shape of rebar Geometry Element of rebar has only one Geometry Object type of Line

0 Likes
Message 4 of 5

Anonymous
Not applicable

And I suspect, that this situation is true for all Line based system elements (Pipes, Conduits, Cabel trays). So we are loking for solution to create dimmensions programmatically not only for Rebars, but for all Line based elements (although I suppose that for example for ducts we can do it by iterating faces or connectors)

0 Likes
Message 5 of 5

zhong_wu
Autodesk Support
Autodesk Support
Your code seems good for me, just want to check if you are still suffering from the problem?

John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes