Insert/import Point Cloud in Family Editor

Dear All

I would like to share how insert/import Point Cloud in Family Editor.

  • the script must run inside family editor

  • you need Python3 and install Open3d python package

"""
This code write by Ramiz Mohareb
enramiz@yahoo.com
Important! This code will only work with Dynamo versions
that are able to run cPython3 and have the following additional 
python packages installed.

Packages required:
numpy

"""

import random
import numpy as np
import clr
import open3d

#libraries used
import numpy as np
import open3d as o3d

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import matplotlib.pyplot as plt


filepath=IN[0]


import numpy as np
import open3d as o3d


filepath=IN[0]
segment_models={}
segments={}
inliers={}
inlier_cloud={}

Outt=[]
Outt2=[]
Outt3=[]
dec_meshL=[]
max_plane_idx=1
point_cloud= np.loadtxt(filepath,skiprows=1)



#Format to open3d usable objects
pcd = o3d.geometry.PointCloud()

pcd.points = o3d.utility.Vector3dVector(point_cloud[:,:3])
#pcd.colors = o3d.utility.Vector3dVector(point_cloud[:,3:6]/255)
#pcd.normals = o3d.utility.Vector3dVector(point_cloud[:,6:9])


source=pcd.voxel_down_sample(voxel_size=0.01)


OUT =source

"""
This code write by Ramiz Mohareb
enramiz@yahoo.com
Important! This code will only work with Dynamo versions
that are able to run cPython3 and have the following additional 
python packages installed.

Packages required:
numpy

"""

import random
import numpy as np
import clr
import open3d
import copy
#libraries used
import numpy as np
import open3d as o3d

import trimesh

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import matplotlib.pyplot as plt




source = IN[0]




OUT =np.asarray(source.points).tolist()

#This code write by Ramiz Mohareb
# enramiz@yahoo.com
# Enable Python support and load DesignScript library
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import clr 
clr.AddReference('RevitAPIUI') 

import clr
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = doc.Application
 
X=IN[0]
Y=IN[1]
Z=IN[2] 

t = Transaction(doc, 'create a single reference point')
 
t.Start()
 
#define x, y, and z variables
j=0
for  item in X:
		x=X[j]
		y=Y[j]
		z=Z[j]
		myXYZ = XYZ(x,y,z)	
		
		p = doc.FamilyCreate.NewReferencePoint(myXYZ)
		#AdaptiveComponentFamilyUtils.MakeAdaptivePoint(doc, p.Id, AdaptivePointType.PlacementPoint)
		#p.CoordinatePlaneVisibility = CoordinatePlaneVisibility.Always

		j=j+1		
 
#declare a XYZ variable 
#use XYZ to define a reference point
 
t.Commit()
 
# Place your code below this line

# Assign your output to the OUT variable.
OUT = 0

Convert point cloud to Ref point family.dyn (28.2 KB)

9 Likes

Hi, Thx for sharing
How to you import Open3D into Dynamo ?

Hi Sona

can you follow the below post to setup any Paython3 packedge

Hi @RMohareb,

I have the same issue, I am not sure how to install the Open3D?

Thank you,

@chuongmep show how to install open3d

1 Like

Dear @RMohareb,

something went wrong when i tried to use the script. There might be a very simple solution to this, but as I am not familiar in Python I am stuck.
I would be grateful if you could modify the code based on this.
Below is the attached warning message.



Hi @m.nagykovacs
Can you send the your *.pts file to check
I think the problem n the pts file format

Hi @RMohareb,

I can’t attach .pts format file here. How could I share the file with you?

1 Like

Can you import pts file to recap the re expot it again to pts file and test. I think the problem in the pts file. Also you need to down size the pts file. You can use recap for down size.

I re-exported the file as you said and it looks like solved the problem, but there is still some issue.

@Marci
Are you run the script in tne adaptive family?

I ran it in door family template.

It work only in adaptive family template

Ohh, I got it. Thanks for the help.

1 Like

I wrote this app as a workaround PTS Import | AutoCAD | Autodesk App Store to get PTS into the Family editor. So is there still no other way except going though DWG/DXF to get points into a regular Family (not adaptive Family) for tracing?

I wonder where the numbers in the code block that are connected to x,yz are coming from? Do they depend on the point cloud? and why you used them?
image

It just to transform the point cloud l. You ca ignore it if you don’t need to transform

1 Like

If I ignored them but I have to keep the nodes of x,y,y? or delete the whole block of Transform?
sorry, I am still new in Python and Dynamo

You can delete it and input the x y direct to the python. If you confuse don’t delete it and add the value equal zero