SHARE
TWEET

Untitled

a guest Jun 15th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import clr
  2.  
  3. # Import DocumentManager and TransactionManager
  4. clr.AddReference("RevitServices")
  5. import RevitServices
  6. from RevitServices.Persistence import DocumentManager
  7. from RevitServices.Transactions import TransactionManager
  8.  
  9. doc = DocumentManager.Instance.CurrentDBDocument
  10.  
  11. # Import RevitAPI
  12. clr.AddReference("RevitAPI")
  13. import Autodesk
  14. from Autodesk.Revit.DB import *
  15.  
  16. #math module
  17. import math
  18.  
  19. #import system
  20. import sys
  21. pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
  22. sys.path.append(pyt_path)
  23. import System
  24.  
  25. #instance or list
  26. if isinstance(IN[0],list):
  27.     views = UnwrapElement(IN[0])
  28.     horAngles = IN[1]
  29.     vertAngles = IN[2]
  30. else :
  31.     views = [UnwrapElement(IN[0])]
  32.     horAngles = [IN[1]]
  33.     vertAngles = [IN[2]]
  34.  
  35. #out
  36. out = []
  37.  
  38. try :
  39.     for view, horAngle, vertAngle in zip(views, horAngles, vertAngles) :
  40.         # is perspective check
  41.         try : Pers = view.IsPerspective
  42.         except : out.append("View is not a perspective view"); Pers = False
  43.        
  44.         #Launch
  45.         if Pers == True :
  46.            
  47.             Zmax = -0.1
  48.                
  49.             #max point coordinates : closest to viewer
  50.             Xmax = -Zmax*math.tan(math.radians(horAngle/2))
  51.             Ymax = -Zmax*math.tan(math.radians(vertAngle/2))
  52.             CalcPointMax = XYZ(Xmax, Ymax, Zmax)
  53.            
  54.            
  55.             #min point coordinates
  56.             Xmin = -Xmax
  57.             Ymin = -Ymax
  58.             Zmin = Zmax*1000
  59.             CalcPointMin = XYZ(Xmin, Ymin, Zmin)
  60.            
  61.             #Create Bounding Box to apply to view
  62.             NewCrop = BoundingBoxXYZ()
  63.             NewCrop.Min = CalcPointMin
  64.             NewCrop.Max = CalcPointMax
  65.            
  66.             #Start transaction
  67.             TransactionManager.Instance.EnsureInTransaction(doc)
  68.            
  69.             # Set Cropbox active
  70.             if view.CropBoxActive == False :
  71.                 view.CropBoxActive = True
  72.            
  73.             #Apply Cropbox settings to put
  74.             view.CropBox = NewCrop
  75.            
  76.             #Transaction end
  77.             TransactionManager.Instance.ForceCloseTransaction()
  78.            
  79.             out.append("Success")
  80.     OUT = out
  81.    
  82. except:
  83.     # if error accurs anywhere in the process catch it
  84.     import traceback
  85.     errorReport = traceback.format_exc()
  86.     OUT = errorReport
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top