
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to highlight a point, which is represented by a class XYZ. So far, I am highlighting a point by creating a sphere around it.
So, in my project I need to highlighting nodes on a line, nodes are represented by XYZ class. So, at some point, I will have to highlight hundreds of nodes with different color, and creating a sphere around a node is too time consuming, is there a better way to highlight a point in Revit API.
below is my method to highlight a point XYZ, where I am creating a sphere around it.
public void CreateSphereDirectShape(Document doc, XYZ center, Color color)
{
/*// delete current sphere
if (Class1.startPointID != null)
{
using (Transaction t = new Transaction(doc, "Delete sphere direct shape"))
{
t.Start();
doc.Delete(Class1.startPointID);
Class1.startPointID = null;
t.Commit();
}
}*/
List<Curve> profile = new List<Curve>();
// first create sphere with 2' radius
double radius = 0.05;
XYZ profile00 = center;
XYZ profilePlus = center + new XYZ(0, radius, 0);
XYZ profileMinus = center - new XYZ(0, radius, 0);
profile.Add(Line.CreateBound(profilePlus, profileMinus));
profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0)));
CurveLoop curveLoop = CurveLoop.Create(profile);
SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);
Frame frame = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY);
if (Frame.CanDefineRevitGeometry(frame) == true)
{
Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options);
using (Transaction t = new Transaction(doc, "Create sphere direct shape"))
{
t.Start();
// create direct shape and assign the sphere shape
DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
Class1.startPointID = ds.Id;
ds.ApplicationId = "Application id";
ds.ApplicationDataId = "Geometry object id";
ds.SetShape(new GeometryObject[] { sphere });
// change sphere color
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetProjectionLineColor(color);
ogs.SetSurfaceTransparency(50);
doc.ActiveView.SetElementOverrides(ds.Id, ogs);
t.Commit();
}
}
}
Solved! Go to Solution.