def join_s(x,y):
		try:
			JoinGeometryUtils.JoinGeometry(doc,x,y)
			JoinGeometryUtils.SwitchJoinOrder(doc,x,y)
			results = 1
		except:
			results = 0
		return results
	def join(x,y):
		try:
			JoinGeometryUtils.JoinGeometry(doc,x,y)
			results = 1
		except:
			results = 0
		return results
Example #3
0
 def join_elements(self, elements_1, elements_2):
     "Присоединяет геометрию элементов"
     result = set()
     rebar_cat = Category.GetCategory(self.doc,
                                      BuiltInCategory.OST_Rebar).Name
     elements_1 = [
         i for i in elements_1 if i.element.Category.Name != rebar_cat
     ]
     elements_2 = [
         i for i in elements_2 if i.element.Category.Name != rebar_cat
     ]
     for element_1 in elements_1:
         for element_2 in elements_2:
             try:
                 res = BooleanOperationsUtils.ExecuteBooleanOperation(
                     element_2.union_solid, element_1.union_solid,
                     BooleanOperationsType.Difference)
                 if res.Volume < element_2.union_solid.Volume:
                     result.add(element_1)
                     try:
                         if not JoinGeometryUtils.AreElementsJoined(
                                 self.doc, element_2.element,
                                 element_1.element):
                             JoinGeometryUtils.JoinGeometry(
                                 self.doc, element_2.element,
                                 element_1.element)
                         if not JoinGeometryUtils.IsCuttingElementInJoin(
                                 self.doc, element_2.element,
                                 element_1.element):
                             JoinGeometryUtils.SwitchJoinOrder(
                                 self.doc, element_2.element,
                                 element_1.element)
                     except:
                         # echo("Ошибка в объединении {} с {}".format(element_1, element_2))
                         pass
             except InvalidOperationException:
                 result.add(element_1)
     return result
Example #4
0
def unjoin(pairs):
    # print(pairs)

    # rng = range(len(selection))
    # checked_pairs = []
    # joined_pairs = []
    c = 0

    # for x in rng:
    #     for y in rng:
    #         if x == y:
    #             continue
    #         _p = sorted([x,y])
    #         _t = (_p[0],_p[1])
    #         if _t in checked_pairs:
    #             continue

    #         checked_pairs.append(_t)
    #         eid1 = selection[_p[0]]
    #         eid2 = selection[_p[1]]
    #         e1,e2 = doc.GetElement(eid1),doc.GetElement(eid2)
    #         joined = JoinGeometryUtils.AreElementsJoined(doc,e1,e2)
    #         if joined:
    #             joined_pairs.append((e1,e2))

    if len(pairs) > 0:
        t = Transaction(doc)
        t.Start("UnjoinSelected")
        for p in pairs:
            e1 = doc.GetElement(ElementId(p[0]))
            e2 = doc.GetElement(ElementId(p[1]))
            joined = JoinGeometryUtils.AreElementsJoined(doc, e1, e2)
            if joined:

                JoinGeometryUtils.UnjoinGeometry(doc, e1, e2)
                c += 1
        t.Commit()
    TaskDialog.Show("R", "%d пар элементов разъединены" % c)
Example #5
0
def multijoin(fam1, fam2, selected=False):
    fam1 = fam1.lower()
    fam2 = fam2.lower()
    with rpw.db.Transaction("join {} and {}".format(fam1, fam2).upper()):
        elements1 = get_elements(fam1, selected)
        for e1 in elements1.get_elements():
            bb = e1.BoundingBox[doc.ActiveView]
            outline = Outline(bb.Min, bb.Max)
            bbfilter = BoundingBoxIntersectsFilter(outline)
            elements2 = get_elements(fam2, selected)
            elements2.WherePasses(bbfilter)
            for e2 in elements2:
                try:
                    JoinGeometryUtils.JoinGeometry(doc, e1, e2)
                except Autodesk.Revit.Exceptions.ArgumentException:
                    pass
Example #6
0
def join_walls(collector):
    if collector:
        f_list = []
        for element in collector:
            group = []
            element_box = element.get_BoundingBox(None)
            if element_box:
                outline = Outline(element_box.Min, element_box.Max)
                bbfilter = BoundingBoxIntersectsFilter(outline)
                wall_col = FilteredElementCollector(doc).OfClass(Wall).WherePasses(bbfilter).ToElements()
                group.append(element)
                wall_host = element.Host
                for wall in wall_col:
                    group.append(wall)
                    try:
                        JoinGeometryUtils.JoinGeometry(doc, wall, wall_host)
                    except Exception:
                        pass
                f_list.append(group)
        return f_list
                'Материал несущих конструкций').AsValueString()) or
        (doc.GetElement(i.GetTypeId()).LookupParameter('м') and 'теплитель' in
         doc.GetElement(i.GetTypeId()).LookupParameter('м').AsValueString())
    ]

    for elem in walls + floors + generic + roofs:
        minpoint = elem.get_BoundingBox(doc.ActiveView).Min
        maxpoint = elem.get_BoundingBox(doc.ActiveView).Max
        els = FilteredElementCollector(doc).OfCategory(
            BuiltInCategory.OST_StructuralFraming).WherePasses(
                BoundingBoxIntersectsFilter(Outline(
                    minpoint,
                    maxpoint))).WhereElementIsNotElementType().ToElements()
        if res == "Соединить":
            for el in els:
                if not JoinGeometryUtils.AreElementsJoined(doc, el, elem):
                    JoinGeometryUtils.JoinGeometry(doc, el, elem)
        elif res == "Отменить соединение":
            for el in els:
                if JoinGeometryUtils.AreElementsJoined(doc, el, elem):
                    JoinGeometryUtils.UnjoinGeometry(doc, el, elem)

else:
    if len(sel) == 1:
        target = sel[0]
        cutting_ids = uidoc.Selection.PickObjects(
            ObjectType.Element,
            'Выберите элементы, которые будут вырезаны из целевого')
        cutting_els = [doc.GetElement(elid.ElementId) for elid in cutting_ids]
        for el in cutting_els:
            if SolidSolidCutUtils.CanElementCutElement(target, el):
Example #8
0
#         return 'New name'

# def test():
#     FORM.exEvent.Raise()

# handler = execute_rebar_set()
# exEvent = ExternalEvent.Create(handler)

# but_cancel.AddFunction(FORM.Close)
# but_create.AddFunction(test)
# FORM.Create(exEvent)
# coding: utf8
"""Выносим вид на лист"""
from Autodesk.Revit.DB import JoinGeometryUtils, Transaction

doc = __revit__.ActiveUIDocument.Document
echo(doc)

selection = [
    doc.GetElement(elId)
    for elId in __revit__.ActiveUIDocument.Selection.GetElementIds()
]

with Transaction(doc, "test") as t:
    t.Start()
    el1 = JoinGeometryUtils.GetJoinedElements(doc, selection[0])
    echo(el1)
    # el2 = selection[1]
    # JoinGeometryUtils.SwitchJoinOrder(doc, el1, el2)
    t.Commit()
	#endregion
	#region main итерации, что-то можно заменить на генераторы списков для 
	TransactionManager.Instance.EnsureInTransaction(doc)
	for i1 in items1:	
		geomSolid = get_geometys(i1)
		if geomSolid != None:
			for ost in catIdlist:
				elems = FilteredElementCollector(doc,i_list_ids).OfCategoryId(ost).WhereElementIsNotElementType()
				elems_solid_filter = []
				elems_solid_filter.append(elems.WherePasses(ElementIntersectsSolidFilter(geomSolid)).ToElements())
				els_sol_fil_flat = flatten_List(elems_solid_filter)
				for els in els_sol_fil_flat:
					if els.Id.ToString() == i1.Id.ToString():
						pass
					else:
						if JoinGeometryUtils.AreElementsJoined(doc,els,i1):
							pass
						else:
							results += join(els,i1)
	TransactionManager.Instance.ForceCloseTransaction()
	#endregion
else:
	results = 0
	#region разделение геометрии
	items1 = flatten_List(elements)
	TransactionManager.Instance.EnsureInTransaction(doc)
	for i in items1:
		test = JoinGeometryUtils.GetJoinedElements(doc, i)
		if test:
			for t in test:
				JoinGeometryUtils.UnjoinGeometry(doc,i,doc.GetElement(t))
Example #10
0
output = pyrevit.output.get_output()
tab = ' '
# input ---------------------
cate = []
sel_warning = ()
outprint = script.get_output()
path = 'C:\\Users\\loum\\Documents\\Pyscripts\\ClashScripts\\'
# t = Transaction(doc, 'Correct Lines')
# t.Start()
if revit.doc.IsWorkshared:
    warnings = doc.GetWarnings()
# select selected warnings
    for warning in warnings:
        selection = []
        elementId = warning.GetFailingElements()
        additionalId = warning.GetAdditionalElements()
        text = warning.GetDescriptionText()
        t = Transaction(doc, 'Unjoin Elements (STVTools)')

        if 'joined but do not intersect' in text:
            print('Found Warning')
            for e in elementId:
                print(doc.GetElement(e))
                for a in additionalId:
                    print(doc.GetElement(a))
                    t.Start()
                    JoinGeometryUtils.UnjoinGeometry(doc, doc.GetElement(e), doc.GetElement(a))
                    t.Commit()
                    print('Success')

Example #11
0
def UnjoinElement(element):
    from Autodesk.Revit.DB import JoinGeometryUtils
    joined = JoinGeometryUtils.GetJoinedElements(doc, element)
    for e in joined:
        secondElement = doc.GetElement(e)
        JoinGeometryUtils.UnjoinGeometry(doc, element, secondElement)
Example #12
0
checked_pairs = []
joined_pairs = []
c = 0

for x in rng:
    for y in rng:
        if x == y:
            continue
        _p = sorted([x,y])
        _t = (_p[0],_p[1])
        if _t in checked_pairs:
            continue

        checked_pairs.append(_t)
        eid1 = selected_ids[_p[0]]
        eid2 = selected_ids[_p[1]]
        e1,e2 = doc.GetElement(eid1),doc.GetElement(eid2)
        joined = JoinGeometryUtils.AreElementsJoined(doc,e1,e2)
        if joined:
            joined_pairs.append((e1,e2))

if len(joined_pairs) > 0:
    t = Transaction(doc)
    t.Start(__title__)
    for p in joined_pairs:
        JoinGeometryUtils.UnjoinGeometry(doc,p[0],p[1])
        c+=1
    t.Commit()

TaskDialog.Show(__title__,"%d pairs of elements unjoined" % c)
Example #13
0
            bbA.Min.Z, bbA.Max.Z, bbB.Min.Z, bbB.Max.Z)


output = []

for a in listA:
    bbA = a.get_BoundingBox(None)
    if not bbA is None:
        for b in listB:
            bbB = b.get_BoundingBox(None)
            if not bbB is None:
                if bbIntersect(bbA, bbB):
                    output.append([a, b])

c = 0

if len(selected_ids) > 0:
    t = Transaction(doc)
    t.Start(__title__)
    for x in selected_ids:
        for y in selected_ids:
            try:
                JoinGeometryUtils.JoinGeometry(doc, doc.GetElement(x),
                                               doc.GetElement(y))
                c += 1
            except:
                pass
    t.Commit()

TaskDialog.Show(__title__, "%d pairs of elements unjoined" % c)
Example #14
0
        elements1 = get_elements(fam1, selected)
        for e1 in elements1.elements:
            bb = e1.BoundingBox[doc.ActiveView]
            outline = Outline(bb.Min, bb.Max)
            bbfilter = BoundingBoxIntersectsFilter(outline)
            elements2 = get_elements(fam2, selected)
            elements2.WherePasses(bbfilter)
            for e2 in elements2:
                try:
                    JoinGeometryUtils.JoinGeometry(doc, e1, e2)
                except Autodesk.Revit.Exceptions.ArgumentException:
                    pass


components = [Label('Host Element ID:'),
            TextBox('host_id'),
            Label('Element IDs to be joined (comma separated):'),
            TextBox('joined_ids'),
            Button('Join')]

ff = FlexForm("Join by IDs", components)
ff.show()

if ff.values and ff.values['host_id']:
    host_id = ff.values['host_id']
    host_element = rpw.db.Element.from_int(int(host_id)).unwrap()
    with rpw.db.Transaction('Join IDs {} with {}'.format(ff.values['joined_ids'], host_id)):
        for eid in ff.values['joined_ids'].split(','):
            joined_element = rpw.db.Element.from_int(int(eid)).unwrap()
            JoinGeometryUtils.JoinGeometry(doc, host_element, joined_element)
Example #15
0
            for e in elementId:
                lines.append(doc.GetElement(e))
        elif 'Wall is slightly off axis' in text or 'Curve-Based Family is slightly off axis' in text:
            for e in elementId:
                walls.append(doc.GetElement(e))
        allLines.append(lines)
        allWalls.append(walls)

i = 0
for line in allLines:
    t = Transaction(doc, 'Correct Lines')
    t.Start()
    for l in line:
        #if l.Category.Name == '<Sketch>':
        off_line = l.GeometryCurve
        joined = JoinGeometryUtils.GetJoinedElements(doc, l)
        for j in joined:
            print(j)
        sketchPlane = l.SketchPlane
        correct_line = Warnings.CorrectLineXY(off_line, 0.08)
        print(correct_line)
        try:
            try:
                l.SetSketchPlaneAndCurve(sketchPlane, correct_line)
            except:
                l.SetGeometryCurve(correct_line, True)
        except:
            print('Curve Set Error')
        '''
            if joined:
                for j in joined: