def convert_rhinopoint_to_xyz(rhinopoint): if isinstance(rhinopoint, list): res = [] rhinopoints = rhinopoint for rhinopoint in rhinopoint: res.append(DB.XYZ(rhinopoint.X, rhinopoint.Y, rhinopoint.Z)) return res else: return DB.XYZ(rhinopoint.X, rhinopoint.Y, rhinopoint.Z)
def main(): """Main function.""" print("Running {fname} version {ver}...".format(fname=__name, ver=__version)) doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument sel = uidoc.Selection ids = sel.GetElementIds() ids = [id for id in ids] elems = [doc.GetElement(id) for id in ids] print(elems) tag = elems[0] if elems else None print(tag) loc = tag.Location trans = db.Transaction(doc) trans.Start("{name} - v{ver}".format(name=__name, ver=__version)) try: tag.LeaderEndCondition = db.LeaderEndCondition.Free end_loc = tag.LeaderEnd tag.LeaderEndCondition = db.LeaderEndCondition.Attached elbow_loc = tag.LeaderElbow head_loc = tag.TagHeadPosition print("loc =", loc) print("end_loc =", end_loc) print("elbow_loc =", elbow_loc) print("head_loc =", head_loc) pos1 = db.XYZ(end_loc.X, head_loc.Y, elbow_loc.Z) pos2 = db.XYZ(head_loc.X, end_loc.Y, elbow_loc.Z) dist1 = elbow_loc.DistanceTo(pos1) dist2 = elbow_loc.DistanceTo(pos2) print("pos1 =", pos1, " dist1 =", dist1) print("pos2 =", pos2, " dist2 =", dist2) if dist1 <= dist2: tag.LeaderElbow = pos1 else: tag.LeaedrElbow = pos2 except: trans.RollBack() else: trans.Commit()
def pipe_location(pipe, elevation): """Returns the intersetion point of the pipe with the elevation.""" # ! Assuming the pipe is vertical for now ! TODO: implement level/pipe intersection curve = pipe.Location.Curve pipe_point = curve.GetEndPoint(0) point = db.XYZ(pipe_point.X, pipe_point.Y, elevation) return point
def preview_rhino_line(rhinoline): if type(rhinoline) == rg.Curve: beam_start_pt, beam_end_pt = rhinoline.PointAtStart, rhinoline.PointAtEnd elif type(rhinoline) == rg.Line: beam_start_pt, beam_end_pt = rhinoline.From, rhinoline.To p0 = DB.XYZ(beam_start_pt.X, beam_start_pt.Y, beam_start_pt.Z) p1 = DB.XYZ(beam_end_pt.X, beam_end_pt.Y, beam_end_pt.Z) p2 = p1 + DB.XYZ(0, 1, 0) revit_line = DB.Line.CreateBound(p0, p2) bmplane = DB.Plane.CreateByThreePoints(p0, p1, p2) with DB.Transaction(revit.doc) as t1: #print revit.doc.Title t1.Start("Create Model Line") skp = DB.SketchPlane.Create(revit.doc, bmplane) #print revit_line #print p0,p1 revit.doc.Create.NewModelCurve(revit_line, skp) t1.Commit()
def main(): source_vp_reference = uidoc.Selection.PickObject( UI.Selection.ObjectType.Element, CustomISelectionFilter(DB.Viewport), "Select Source Viewport") target_vps_reference = uidoc.Selection.PickObjects( UI.Selection.ObjectType.Element, CustomISelectionFilter(DB.Viewport), "Select Target Viewport(s)") source_vp = doc.GetElement(source_vp_reference.ElementId) source_vp_xyz = source_vp.GetBoxCenter() with revit.Transaction("Aign ViewPort - Vertical"): for target_vp_reference in target_vps_reference: target_vp = doc.GetElement(target_vp_reference.ElementId) delta = DB.XYZ(0.0, source_vp_xyz.Y - target_vp.GetBoxCenter().Y, 0.0) target_vp.Location.Move(delta)
def revit_clash_plane_curve(beamline, pipeline): p0 = beamline.GetEndPoint(0) p1 = beamline.GetEndPoint(1) p2 = p1 + DB.XYZ(0, 0, 1) bmplane = DB.Plane.CreateByThreePoints(p0, p1, p2) #project pipe line onto plane pipe_projected_startpoint, dist = bmplane.Project(pipeline.GetEndPoint(0)) pipe_projected_endpoint, dist = bmplane.Project(pipeline.GetEndPoint(1)) #print (pipe_projected_startpoint) #print pipe_projected_endpoint pipe_projected = DB.Line.CreateBound(pipe_projected_startpoint, pipe_projected_endpoint) intpoint = pipe_projected.Intersect(pipeline)
def main(): tempfile = os.path.join(gettempdir(), "ViewPort") try: with open(tempfile, "rf") as fp: source_point = pickle.load(fp) except Exception: message = 'を除外します' ui.forms.Alert(content=message, title="シート以外が選択されました", exit=True) target_vp_reference = uidoc.Selection.PickObject( UI.Selection.ObjectType.Element, CustomISelectionFilter(DB.Viewport), "Select Source Viewport") target_vp = doc.GetElement(target_vp_reference.ElementId) target_vp_xyz = target_vp.GetBoxCenter() with revit.Transaction("Move ViewPort Location"): delta = DB.XYZ((source_point[0] - target_vp_xyz.X), (source_point[1] - target_vp_xyz.Y), (source_point[2] - target_vp_xyz.Z)) target_vp.Location.Move(delta)
rvt_uidoc = __revit__.ActiveUIDocument rvt_doc = __revit__.ActiveUIDocument.Document import Autodesk.Revit.DB as rvt_db #=============================================================================== # Import Excel #=============================================================================== #import clr #clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c') #from Microsoft.Office.Interop import Excel #=============================================================================== # Configuration #=============================================================================== #Overview plan, center OVERVIEWPLAN_CENTER = rvt_db.XYZ(1.656061764, 1.323727996, 0.036311942) LOCATIONPLAN_CENTER = rvt_db.XYZ(3.539872609, 0.685768315, 0.000000000) LEGEND_CENTER = rvt_db.XYZ(3.522094284, 1.583534318, 0.000000000) #=============================================================================== # Imports other #=============================================================================== import sys import csv path_package = r"C:\EclipseGit\ExergyUtilities\ExergyUtilities" sys.path.append(path_package) import utility_revit_api as util_ra #===============================================================================
def copyElement(self): TransactionManager.Instance.EnsureInTransaction(self.doc) elementIdsCollection = db.ElementTransformUtils.CopyElement(self.doc, self.element.Id, db.XYZ(0,0,0)) TransactionManager.Instance.TransactionTaskDone() # new is type of ICollection<ElementId>, that is why have to convert it into list and get first element, # because only one element is copying return self.doc.GetElement(elementIdsCollection[0])
#=============================================================================== import logging logging.basicConfig(level=logging.DEBUG) #=============================================================================== # Import Revit #=============================================================================== rvt_app = __revit__.Application rvt_uidoc = __revit__.ActiveUIDocument rvt_doc = __revit__.ActiveUIDocument.Document import Autodesk.Revit.DB as rvt_db #=============================================================================== # Configuration #=============================================================================== OVERVIEWPLAN_CENTER = rvt_db.XYZ(1.656061764, 1.323727996, 0.036311942) #=============================================================================== # Imports other #=============================================================================== import sys from collections import defaultdict path_package = r"C:\EclipseGit\ExergyUtilities\ExergyUtilities" sys.path.append(path_package) import utility_revit_api as util_ra #=============================================================================== # Definitions #===============================================================================
def copyElement(self): TransactionManager.Instance.EnsureInTransaction(self.doc) element = db.ElementTransformUtils.CopyElement(self.doc, self.element.Id, db.XYZ(0,0,0)) TransactionManager.Instance.TransactionTaskDone() return element
ptArray = [] tempfile = os.path.join(gettempdir(), 'ViewCrop') try: with open(tempfile, 'rb') as fp: #myPoints = [] myPoints = pickle.load(fp) fp.close() except IOError: UI.TaskDialog.Show('pyRevitPlus-', 'Could not find saved viewport crop boundary.\nSave a Viewport Crop first.') sys.exit() else: #pprint(myPoints) for cPoint in myPoints: saved_pt = DB.XYZ(cPoint.X, cPoint.Y, cPoint.Z) ptArray.append(saved_pt) # #print('pyRevitPlus: Proceeding to view') cActiveView = doc.ActiveView cShpMan = cActiveView.GetCropRegionShapeManager() cBoundaryList = cShpMan.GetCropShape() if (ptArray.Count> 4) and not(cShpMan.CanHaveShape): UI.TaskDialog.Show('pyRevitPlus-', 'Unable to set non=rectangular crop to the viewport.') else: newBoundaryList = DB.CurveLoop() #print('pyRevitPlus: Creating new boundary') for idx, value in enumerate(ptArray): pt0 = ptArray[idx-1] pt1 = ptArray[idx]
import rhino_decider from Autodesk.Revit import DB rh_line = rhino_decider.convert_rvtLine_to_RhinoLine( DB.Line.CreateBound(DB.XYZ(0, 0, 0), DB.XYZ(100, 0, 0))) import Rhino.Geometry as rg print rg.Extrusion.Create(rg.LineCurve(rh_line), -5, False)
if not viewlist: forms.alert("Select Views in the Project Browser to place on Sheet", ok=True) sys.exit() if not sheetview: forms.alert("You have to select a Sheet also", ok=True) sys.exit() try: t = DB.Transaction(doc, "test") t.Start() for i in viewlist: viewport = DB.Viewport.Create(doc, sheetview[0].Id, i.Id, DB.XYZ(0, 0, 0)) #vplist.append(viewport) t.Commit() except: t.RollBack() t.Dispose() import traceback print traceback.format_exc() #ToDo: Get Parameter Values from Titleblock: #- SheetIssueDate, DrawnBy # ViewPortTypes, Change ViewPort Type, Retrieve a List of all Types. # validtypes= viewport.GetValidTypes() #returns a List of element id's of all Viewport Types