Beispiel #1
0
def get_dynamo_room_faces(revit_room_geometry):
    rounding = 4
    try:
        room_faces_dyn = \
            tuple(face.ToProtoType()[0] for face in revit_room_geometry.Faces)
    except StandardError:
        scale = util.unit_conversion()
        # try to recreate the faces from the edges
        loops = tuple(loop for face in revit_room_geometry.Faces
                      for loop in face.EdgeLoops)

        # collect all the start and end points
        start_ends = (((e.Evaluate(1), e.Evaluate(0)) if count == 0 else
                       (e.Evaluate(0), e.Evaluate(1))
                       for count, e in enumerate(loop)) for loop in loops)

        # round the values
        points = (((round(pt.X,
                          rounding), round(pt.Y,
                                           rounding), round(pt.Z, rounding))
                   for edge in loop for pt in edge) for loop in start_ends)

        # remove duplicated points
        xyz_unique = (list(collections.OrderedDict.fromkeys(pts))
                      for pts in points)

        room_faces_dyn = []
        for pgroup in xyz_unique:
            try:
                face = Surface.ByPerimeterPoints(
                    Point.ByCoordinates(*p).Scale(scale) for p in pgroup)
            except StandardError:
                # changing the order was not needed for this face
                pgroup[0], pgroup[1] = pgroup[1], pgroup[0]
                face = Surface.ByPerimeterPoints(
                    Point.ByCoordinates(*p).Scale(scale) for p in pgroup)

            room_faces_dyn.append(face)

    return room_faces_dyn
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Point

from itertools import chain

pts = sorted( (p.X, p.Y) for p in IN[0])
elev = IN[1]

def pCrs(o, a, b):
	return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])

pLen = len(pts)
if pLen < 4 : OUT = pts
else:
	lower, upper = [], []
	
	for i in xrange(pLen):
		j = pLen - 1 - i
		while len(lower) >= 2 and pCrs(lower[-2], lower[-1], pts[i]) <= 0.000001:
			lower.pop()
		lower.append(pts[i])
		while len(upper) >= 2 and pCrs(upper[-2], upper[-1], pts[j]) <= 0.000001:
			upper.pop()
		upper.append(pts[j])
	
	lower.pop()
	upper.pop()
	
	OUT = [Point.ByCoordinates(p[0], p[1], elev) for p in chain(lower, upper) ]
Beispiel #3
0
# Copyright(c) 2018, Dimitar Venkov
# @5devene, [email protected]
# www.badmonkeys.net

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import BoundingBox, Point, Mesh


def tolist(x):
    if hasattr(x, '__iter__'): return x
    else: return [x]


meshes = tolist(IN[0])
OUT = []

for m in meshes:
    if isinstance(m, Mesh):
        co = zip(*((v.X, v.Y, v.Z) for v in m.VertexPositions))
    else:
        co = zip(*((v.X, v.Y, v.Z) for v in m.Vertices()))

    OUT.append(
        BoundingBox.ByCorners(Point.ByCoordinates(*map(min, co)),
                              Point.ByCoordinates(*map(max, co))))
"""
just for fun at xMas heres an xMas tree, a yMas tree and a zMas tree !
"""

import clr  # common runtime library allows us to add references

clr.AddReference('ProtoGeometry')  # were going to use a cone for the tree
from Autodesk.DesignScript.Geometry import Cone, Geometry, Point, Plane

clr.AddReference('GeometryColor')  # were going to recolor xyz cones
from Modifiers import GeometryColor

clr.AddReference('DSCoreNodes')
import DSCore  # enable design script in python

ptStart = Point.ByCoordinates(0, 0, 2)  # establish a reference solid
ptEnd = Point.ByCoordinates(0, 0, 10)  # that points up in z axis
radiusStart = 1
radiusEnd = 0.01  # cone needs to have end radius to not be a surface
solidCone = Cone.ByPointsRadii(  # if a surface we cant change color
    ptStart, ptEnd, radiusStart, radiusEnd)

planes = [Plane.YZ(), Plane.XZ(), Plane.XY()]  # Plane.ByOriginNormal
cs = []  # create empty list to store coordinate systems in
for p in planes:  # alternative use CoordinateSystem.ByOriginVector
    cs.append(Plane.ToCoordinateSystem(p))  # transform plane into cs

trees = []  # create empty lists to store grey cones 'trees' in
for s in cs:
    trees.append(Geometry.Transform(solidCone, s))  # transform cone by cs
    k, m = highSearch(pts, pts[i], pts[j], j + 1, it1, k, m)

    highPts.append(pts[k])
    cp, l1 = linDist(pts[i], pts[j], pts[k])
    closePts.append(cp)

    n, _ = highSearch(pts, pts[k], cp, j)
    _, l2a = linDist(pts[k], cp, pts[n])

    q, _ = highSearch(pts, cp, pts[k], m)
    _, l2b = linDist(cp, pts[k], pts[q])

    areas.append(l1 * (l2a + l2b))
    dists.append((l2a, l2b))

ix, _ = min(enumerate(areas), key=itemgetter(1))
d1, d2 = dists[ix]
_a, _b = closePts[ix], highPts[ix]
a = Point.ByCoordinates(_a[0], _a[1], elev)
b = Point.ByCoordinates(_b[0], _b[1], elev)

_v = Vector.ByTwoPoints(a, b)
v = Vector.ByCoordinates(-_v.Y, _v.X, 0).Normalized()
p1 = a.Add(v.Scale(d2))
p2 = a.Subtract(v.Scale(d1))
p3 = b.Subtract(v.Scale(d1))
p4 = b.Add(v.Scale(d2))

OUT = (Rectangle.ByCornerPoints(p1, p2, p3, p4),
       90 - v.AngleAboutAxis(Vector.XAxis(), Vector.ZAxis()),
       [Point.ByCoordinates(p[0], p[1], elev) for p in pts])
Beispiel #6
0
def NewForm_background(s1, name1, cat1, isVoid1, mat1, subcat1):
    try:
        enable_mat = False if mat1 is None else True
        enable_subcat = False if subcat1 is None else True
        if any((c in name1 for c in invalid_chars)):
            raise Exception('Family name contains invalid characters')
        TransactionManager.ForceCloseTransaction(t1)
        famdoc = doc.Application.NewFamilyDocument(fam_path)
        sat_path = '%s%s.sat' % (temp_path, name1)
        if factor != 1:
            s1 = s1.Scale(factor)
        vec1 = Vector.ByTwoPoints(
            BoundingBox.ByGeometry(s1).MinPoint, DynPoint.Origin())
        s1 = s1.Translate(vec1)
        sat1 = Geometry.ExportToSAT(s1, sat_path)
        view_fec = FilteredElementCollector(famdoc).OfClass(View)
        view1 = None
        for v in view_fec:
            if str(v.ViewType) in acceptable_views and not v.IsTemplate:
                view1 = v
                break
        t1.EnsureInTransaction(famdoc)
        satId = famdoc.Import(sat1, satOpt, view1)
        el1 = famdoc.GetElement(satId)
        geom1 = el1.get_Geometry(opt1)
        enum = geom1.GetEnumerator()
        enum.MoveNext()
        geom2 = enum.Current.GetInstanceGeometry()
        enum2 = geom2.GetEnumerator()
        enum2.MoveNext()
        s1 = enum2.Current
        famdoc.Delete(satId)
        System.IO.File.Delete(sat_path)

        save_path = '%s%s.rfa' % (temp_path, name1)
        try:  #set the category
            fam_cat = famdoc.Settings.Categories.get_Item(cat1.Name)
            famdoc.OwnerFamily.FamilyCategory = fam_cat
        except:
            pass
        s2 = FreeFormElement.Create(famdoc, s1)
        if isVoid1:
            void_par = s2.get_Parameter(
                BuiltInParameter.ELEMENT_IS_CUTTING).Set(1)
            void_par2 = famdoc.OwnerFamily.get_Parameter(
                BuiltInParameter.FAMILY_ALLOW_CUT_WITH_VOIDS).Set(1)
        else:  #voids do not have a material values or a sub-cateogry
            if enable_mat:
                try:
                    mat_fec = FilteredElementCollector(famdoc).OfClass(
                        Material)
                    for m in mat_fec:
                        if m.Name == mat1:
                            fam_mat = m
                            break
                    mat_par = s2.get_Parameter(
                        BuiltInParameter.MATERIAL_ID_PARAM).Set(fam_mat.Id)
                except:
                    pass
            if enable_subcat:  #create and assign the sub-category:
                try:
                    current_fam_cat = famdoc.OwnerFamily.FamilyCategory
                    fam_cat_subs = current_fam_cat.SubCategories
                    if fam_cat_subs.Contains(subcat1):
                        new_subcat = fam_cat_subs[subcat1]
                    else:
                        new_subcat = famdoc.Settings.Categories.NewSubcategory(
                            current_fam_cat, subcat1)
                    s2.Subcategory = new_subcat
                except:
                    pass
        TransactionManager.ForceCloseTransaction(t1)
        famdoc.SaveAs(save_path, SaveAsOpt)
        family1 = famdoc.LoadFamily(doc, FamOpt1())
        famdoc.Close(False)
        System.IO.File.Delete(save_path)
        symbols = family1.GetFamilySymbolIds().GetEnumerator()
        symbols.MoveNext()
        symbol1 = doc.GetElement(symbols.Current)
        t1.EnsureInTransaction(doc)
        if not symbol1.IsActive: symbol1.Activate()
        inst1 = doc.Create.NewFamilyInstance(origin, symbol1, str_typ)
        ElementTransformUtils.MoveElement(doc, inst1.Id,
                                          vec1.Reverse().ToXyz())
        TransactionManager.ForceCloseTransaction(t1)
        return inst1.ToDSType(False), family1.ToDSType(False)

    except:
        return traceback.format_exc(), ''
Beispiel #7
0
            centroid.X = X_mean
            centroid.Y = Y_mean

        print('Iteration {}'.format(iteration + 1))

    Centroid_X_values = []
    Centroid_Y_values = []

    for centroidPoint in centroidPoints:
        Centroid_X_values.append(centroidPoint.X)
        Centroid_Y_values.append(centroidPoint.Y)

    return (Centroid_X_values, Centroid_Y_values)

# Final loop to run the K means process
pointXs = []
pointYs = []
outputPoints = []
for point in PointsRaw:
    px, py = DeconstructPoint(point)
    pointXs.append(px)
    pointYs.append(py)

CXs, CYs = K_means(NumberOfsubdivisionClasses, pointXs, pointYs, iterationNumber)

for i in range(len(CXs)):
    point = Point.ByCoordinates(CXs[i], CYs[i], 0)
    outputPoints.append(point)
OUT = outputPoints
Beispiel #8
0
TransactionManager.Instance.EnsureInTransaction(doc)

# loop elements
for e in elems:
    # level elevation - unit millimeter
    elevation = e.Level.Elevation * 304.8
    # get geo-objects of the element
    geoelem = e.GetGeometryObjectFromReference(Reference(e))
    # get enumerator to loop geo-objects
    geoobj = geoelem.GetEnumerator()
    # loop geo-objector
    for obj in geoobj:
        # convert to dynamo type
        room_geometry = obj.ToProtoType()
        # get the centroid of the element
        point = room_geometry.Centroid()
        # create location point with level elevation
        center = pt.ByCoordinates(point.X, point.Y, elevation)
        # current element location
        current = e.Location.Point
        # point convert to revit and minus from current location
        newloc = center.ToXyz() - current
        # move to new location
        e.Location.Move(newloc)

# transaction done
TransactionManager.Instance.TransactionTaskDone()

# output
OUT = elems
Beispiel #9
0
import clr
from itertools import groupby
from operator import itemgetter
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Point


def p2t(p):
    return round(p.X, 4), round(p.Y, 4), round(p.Z, 4)


pts = map(p2t, IN[0])
unique_pts = set(pts)
if not IN[1]:
    same_z = [(i[:2], i[-1]) for i in unique_pts]
    same_z.sort(key=itemgetter(0))
    unique_pts = []
    for k, g in groupby(same_z, itemgetter(0)):
        coord = list(k)
        coord.append(max([i[-1] for i in g]))
        unique_pts.append(coord)
OUT = [Point.ByCoordinates(*i) for i in unique_pts]