- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi forum. I have been a few days trying to create dimensions for legends components with no succes.
The objetive is, create dimensions for legend components of width and height if its a reference available in the legend component. I satisfy that condition by intersecting BoundingBox of Legend Component and Geometry of the Symbol. In this code, the legends its created. I get his id and can see it with Revit LookUp (where indicates that the dimensions belongs to the proper legend view). But still the dimension is not being showed.
I have also consulted this posts: https://forums.autodesk.com/t5/revit-api-forum/created-dimension-not-showing-in-document/td-p/738043... https://forums.autodesk.com/t5/revit-api-forum/dimension-a-legend-component/td-p/8673305 which make me understand that I had to use GetSymbolGeometry instead that GetInstanceGeometry (and aply the translation transform) that but the legend component still now shows. Also consulted and tried what this post https://forums.autodesk.com/t5/revit-api-forum/copy-dimensions-from-a-view-to-another/m-p/7226217 expose but not getting any result either.
The code is:
public void CreateDimension()
{
UIDocument uidoc = this.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = this.ActiveUIDocument.Document;
ElementId Id = new ElementId(532709); //This is de Id of the legend component. Just put yourself if you want to try.
Element element = doc.GetElement(Id);
ReferenceArray RA = new ReferenceArray();
BoundingBoxXYZ BB = element.get_BoundingBox(doc.ActiveView);
XYZ TopL = new XYZ(BB.Min.X, BB.Max.Y, 0);
XYZ BotL = new XYZ(BB.Min.X, BB.Min.Y, 0);
XYZ TopR = new XYZ(BB.Max.X, BB.Max.Y, 0);
XYZ BotR = new XYZ(BB.Max.X, BB.Min.Y, 0);
Curve VerticalLeft= Line.CreateBound(TopL, BotL) as Curve;
Curve VerticalRight = Line.CreateBound(TopR, BotR) as Curve;
Curve HorizontalSupe = Line.CreateBound(TopL, TopR) as Curve;
Curve HorizontalInfe = Line.CreateBound(BotL, BotR) as Curve;
List<Curve> Curvas = new List<Curve>{VerticalIzq, VerticalDer, HorizontalSupe, HorizontalInfe}; //List of curves to intersect with symbol geometry later
List<XYZ> Puntos = new List<XYZ>(); //To get XYZs for line for dimension
List<Edge> edges = new List<Edge>();
Options options = new Options{ComputeReferences = true, IncludeNonVisibleObjects = false};
var geoEle = element.get_Geometry(options);
foreach (Curve curve in Curvas)
{
foreach (var item in geoEle)
{
GeometryInstance geometryInstance = item as GeometryInstance;
if (geometryInstance != null)
{
GeometryElement geometryElement = geometryInstance.GetSymbolGeometry();
BoundingBoxXYZ BBS = geometryElement.GetBoundingBox();
XYZ MinBB = new XYZ(BBS.Min.X, BBS.Min.Y, 0);
XYZ Move = new XYZ(AbajoIzq.X - MinBB.X, AbajoIzq.Y - MinBB.Y, 0);
Transform Transformacion = Transform.CreateTranslation(Move);
GeometryElement TgeometryElement = geometryElement.GetTransformed(Transformacion);
foreach (GeometryObject geoObject in TgeometryElement)
{
if (geoObject is Solid)
{
Solid solid = geoObject as Solid;
if (!solid.Edges.IsEmpty)
{
foreach (Edge edge in solid.Edges)
{
try //Put this try/catch to avoid "curve is to short" error.
{
Line line1 = edge.AsCurve() as Line;
XYZ Inicio = new XYZ(line1.GetEndPoint(0).X, line1.GetEndPoint(0).Y, 0);
XYZ Fin = new XYZ(line1.GetEndPoint(1).X, line1.GetEndPoint(1).Y, 0);
Line line = Line.CreateBound(Inicio,Fin);
SetComparisonResult src=curve.Intersect(line);
string SRCs = SRC.ToString(); //Check what type of intersection there it is
if (SRCs == "Equal" || SRCs == "Subset" || SRCs == "Superset")
{
RA.Append(edge.Reference);
XYZ Punto = new XYZ((edge.AsCurve().GetEndPoint(0).X + edge.AsCurve().GetEndPoint(1).X)/2,(edge.AsCurve().GetEndPoint(0).Y +
edge.AsCurve().GetEndPoint(1).Y)/2,0); //Get the mid point of the edge reference to use it as line for the dimension.
Puntos.Add(Punto);
goto Fin1;
}
}
catch{}
}
}
}
}
}
}
TaskDialog.Show("Hello", "No references found for " + curve.ToString());
goto Fin2;
Fin1:;
}
Line LineaDimension = Line.CreateBound(Puntos[0],Puntos[1]);
using (Transaction t = new Transaction(doc, "family test"))
{
t.Start();
Dimension dim = doc.Create.NewDimension(doc.ActiveView, LineaDimension, RA);
TaskDialog.Show("HOLA", dim.Id.ToString());
doc.Regenerate();
t.Commit();
}
Fin2:;
}
Maybe I have some typo erros cause I have translated some of the code to be more readable by you. But the rest of the code (the intersection part and that stuff) is working ok as the dimensions is being created but not showed. I cant figure out any more whats happening so if you have any idea about this... Thanks!
Solved! Go to Solution.