Visualizing Points in different color

I am trying to visualize a few points based on some filtering. In order to do that, I want to change the color of a few points based on my classification. But I couldn’t find any node that helps me to change the color of points and visualize them in Revit active UI.

This is the script I am working on:

demo:
image

I want to change the colors of this points on my own, and view them in revit ui. Can anyone please help me regarding this?

As a guideline:

  • Dynamo can only do to Revit what the Revit API can do.
  • The Revit API can only do some of what the Revit User Interface can do.
  • Therefore if the Revit UI can’t do something, Dynamo can’t either.

So before attempting to modify the color of points in Dynamo, how would you modify the points in the Revit UI? I’m not a point cloud expert, but I don’t see any way to modify the color of individual points.

1 Like

But, we are getting a sort of visualization of the points returned by sastrugi’s node. Is there any way I can do that? the color of the points can remain same, I just need to see which points are being returned by my function. Since Sastrugi’s node already returns and shows these points as blue dots, and function takes these nodes as input, and the output of my function is a subset of the points given by sastrugi’s node, I cannot visualize the result of my own function. I was thinking if I could visualize my function’s points in a different color rather than blue, then, it would be great. Nonetheless, thank you so much for your input. Really appreciate it.

Ah!

So the points which you see are the Dynamo geometry preview.

I haven’t looked the code over in detail but I would guess that Sastrugi works by gathering a subset of Cloud Point objects from the point cloud instance, converting each to an XYZ which is the class used for both Vectors and geometric points in the Revit API, and then using the ToPoint method to convert to a Dynamo Point. As Dynamo geometry displays a preview in Revit, you can see the points in Revit just like you can see them in the Dynamo geometry window. However the Revit preview geometry cannot have any modifiers applied to it; the color can only be changed in it’s entirety by changing the material which you can see in the Revit materials pallet.

If you want to display in color, you’d have to either look at implementing one of the methods here, none of which are easily implementing in a Dynamo context.

1 Like

@taukirazam ,

just to illustrate…

KR

Andreas

1 Like

Thank you for this, @Draxl_Andreas. It will surely assist me to debug. But I was hoping to get the outputs in Revit UI. Still, thanks for this. It helps too.

Thank you for the explanation @jacob.small. For now, let me see how those methods are used there.

1 Like

Hi,

it all depends on the end goal, but one solution would be to use Analysis Visualization Framework (AVF)

an example by coloring the points by Z values

test avf points


import clr
import sys
import math
import System
from System.Collections.Generic import List

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Analysis import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument

def createSphere(center):
	radius = 0.35 # decimal feet
	frame = Frame(center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ)
	arc = Arc.Create(  center - radius * XYZ.BasisZ, center + radius * XYZ.BasisZ, center + radius * XYZ.BasisX )
	line = Line.CreateBound(arc.GetEndPoint( 1 ), arc.GetEndPoint( 0 ) )  
	halfCircle = CurveLoop()
	halfCircle.Append( arc )
	halfCircle.Append( line )
	sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, List[CurveLoop]([halfCircle ]) , 0, 2 * math.pi)
	return sphere

def create_AVF(view):
	filterP = System.Predicate[System.Object](lambda x : x.Name == "Paint_Preview")
	analysisDisplayStyle = List[Element](FilteredElementCollector(doc).OfClass(AnalysisDisplayStyle).ToElements()).Find(filterP)
	if view.AnalysisDisplayStyleId == ElementId.InvalidElementId or analysisDisplayStyle is None :
		coloredSurfaceSettings = AnalysisDisplayColoredSurfaceSettings()
		coloredSurfaceSettings.ShowGridLines = False
		colorSettings = AnalysisDisplayColorSettings()
		legendSettings = AnalysisDisplayLegendSettings()
		legendSettings.ShowLegend = True
		analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle( doc, "Color by Z Values", coloredSurfaceSettings, colorSettings, legendSettings )
		view.AnalysisDisplayStyleId  = analysisDisplayStyle.Id
	return view
	
lstDS_point = IN[0]
view = UnwrapElement(IN[1])
clear = IN[2]
TransactionManager.Instance.EnsureInTransaction(doc)

if clear:
	sfm = SpatialFieldManager.GetSpatialFieldManager(view) 
	if sfm is not None:
		sfm.Clear()
else:
	create_AVF(view)
	sfm = SpatialFieldManager.GetSpatialFieldManager(view) 
	if sfm is None:
		sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1)		
	sfm.Clear() 
	resultSchema = AnalysisResultSchema("Schema Name" , "Color by Z Values")
	schemaIndex = sfm.RegisterResult(resultSchema)
	
	for ds_pt in lstDS_point:
		value_interval = ds_pt.Z 
		sphere = createSphere(ds_pt.ToXyz())
		for face in sphere.Faces:
			idx = sfm.AddSpatialFieldPrimitive(face, Transform.Identity)
			uvPts = List[UV]()
			bb = face.GetBoundingBox()
			uvPts.Add(bb.Min)
			pnts = FieldDomainPointsByUV(uvPts)
			#   
			doubleList = List[System.Double]([value_interval])
			vals = FieldValues(List[ValueAtPoint]([ValueAtPoint(doubleList)]))
			sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, schemaIndex)

TransactionManager.Instance.TransactionTaskDone()

OUT = sfm
5 Likes