Cropview shapes not matching in plan during export to DWG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning,
in an attempt to overcome the limitation in Revit to export view in sheet in world coordinates, we have explored the idea to export the view in the sheets separately and then relink them within AutoCAD.
The biggest issue we are facing at the moment is that the cropshapes are not matching the coordinates and the location in plan.
When we split the view in multiple crop regions we end up to have multiple crop views, each of them provides a curve loop and with that the 4 corners of the crop itself.
This info is available within the API using the ViewGetCropRegionShapeManager. I thought that this will somehow match in dimension and location the position in plan when the view is not cropped so we can recreate a layout in AutoCAD and match these dimensions, but that is not the case.
Now this is a problem, because there is no way we can find a relatoin between the shapes (and TBH the point don't make sent as well).
@jeremytammik do you have any idea or solution to this problem? Anyone else in the forum that has solved this issue before? Are these information even accessible through the APIs?
The Enhanced DWG Export is not a solution either, if someone thinks to provide that as suggestion.
Here the code in Python/Dynamo just to test the functionality
dwgExportOptions = DWGExportOptions.GetPredefinedOptions(doc, dwgExportName);
viewsToExport = []
loops = []
shapes = []
for sheet in sheets:
s = {}
data = []
viewports = sheet.GetAllViewports()
for viewport in viewports:
d = {}
v = doc.GetElement(viewport)
exportWC = v.LookupParameter(paramName).AsInteger()
if (exportWC == 1):
view = doc.GetElement(v.ViewId)
viewsToExport.Add(view.Id)
viewName = view.Name
viewOrigin = XYZToPoint(view.Origin, du)
viewScale = view.Scale
viewCropBoxMin = XYZToPoint(view.CropBox.Min, du)
viewCropBoxMax = XYZToPoint(view.CropBox.Max, du)
viewCropBoxMin[0] = viewCropBoxMin[0] + east
viewCropBoxMin[1] = viewCropBoxMin[1] + north
viewCropBoxMax[0] = viewCropBoxMax[0] + east
viewCropBoxMax[1] = viewCropBoxMax[1] + north
viewCropBoxLoops = view.GetCropRegionShapeManager().GetCropShape()
viewAnnotationCropBoxLoops = view.GetCropRegionShapeManager().GetAnnotationCropShape()
splitRegions = view.GetCropRegionShapeManager().NumberOfSplitRegions
shapes = []
loop = []
viewCropBoxOrigin = []
for curveLoop in viewCropBoxLoops:
shape = []
for curve in curveLoop:
curveOrigin = XYZToPoint(curve.Origin, du)
loop.Add([curveOrigin[0], curveOrigin[1]])
#shapes.Add([curveOrigin[0], curveOrigin[1]])
shape.Add([curveOrigin[0]+east, curveOrigin[1]+north])
p1X = shape[0][0]
p1Y = shape[0][1]
p2X = shape[2][0]
p2Y = shape[2][1]
loops.Add(loop)
viewCropBoxOrigin.Add([(p1X + p2X)/2 , (p1Y + p2Y)/2])
shapes.Add(shape)
rX = view.CropBox.Transform.BasisY.X
rY = view.CropBox.Transform.BasisY.Y
viewCropboxRotation = math.degrees(math.atan2(rX, rY))
viewportBoxCenter = XYZToPoint(v.GetBoxCenter(), duMM)
viewportBoxOutlineMinimumPoint = XYZToPoint(v.GetBoxOutline().MinimumPoint, duMM)
viewportBoxOutlineMaximumPoint = XYZToPoint(v.GetBoxOutline().MaximumPoint, duMM)
d["viewUnit"] = du.ToString()
d["viewName"] = viewName
d["viewOrigin"] = viewOrigin
d["viewRotationUp"] = math.degrees(math.atan2(view.UpDirection.Y, view.UpDirection.X))
d["viewScale"] = viewScale
d["viewBoundingBox"] = [viewCropBoxMin, viewCropBoxMax]
d["viewportBoxCenter"] = viewportBoxCenter
d["viewportBoxOutlineMinimumPoint"] = viewportBoxOutlineMinimumPoint
d["viewportBoxOutlineMaximumPoint"] = viewportBoxOutlineMaximumPoint
d["viewCropbox"] = shapes
d["viewCropboxTopAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().TopAnnotationCropOffset, du)
d["viewCropboxBottomAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().BottomAnnotationCropOffset, du)
d["viewCropboxLeftAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().LeftAnnotationCropOffset, du)
d["viewCropboxRightAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().RightAnnotationCropOffset, du)
d["viewCropboxOrigin"] = viewCropBoxOrigin
d["viewCropboxRotation"] = viewCropboxRotation
d["splitRegionsNumber"] = splitRegions
if splitRegions > 1:
TransactionManager.Instance.EnsureInTransaction(doc)
tempView = view.Duplicate(ViewDuplicateOption.WithDetailing)
csm = doc.GetElement(tempView).GetCropRegionShapeManager()
csm.RemoveSplit()
TransactionManager.Instance.TransactionTaskDone()
export = doc.Export(dirPath, viewName, List[ElementId]([tempView]), dwgExportOptions)
else:
export = doc.Export(dirPath, viewName, List[ElementId]([view.Id]), dwgExportOptions)
data.Add(d)
else:
continue
s["sheetName"] = sheet.Name
s["viewUnit"] = du.ToString()
s["sheetNumber"] = sheet.SheetNumber
s["data"] = data
export = doc.Export(dirPath, sheet.Name, List[ElementId]([sheet.Id]), dwgExportOptions)
output.Add(s)
#Declaration section#
import sys
import clr
import math
clr.AddReference('System')
from System.Collections.Generic import List
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.Creation import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#Convert a Revit internal point
def XYZToPoint(pt, du):
x = UnitUtils.ConvertFromInternalUnits(pt.X, du)
y = UnitUtils.ConvertFromInternalUnits(pt.Y, du)
#z = UnitUtils.ConvertFromInternalUnits(pt.Z, du)
return [x, y]
#Access the active document#
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Get the length display unit for the active project
du = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits
duMM = DisplayUnitType.DUT_MILLIMETERS
pbp = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ProjectBasePoint).WhereElementIsNotElementType().FirstElementId()
east = UnitUtils.ConvertFromInternalUnits(doc.GetElement(pbp).get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble(), du)
north = UnitUtils.ConvertFromInternalUnits(doc.GetElement(pbp).get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble(), du)
#Start a transaction on the active document#
#TransactionManager.Instance.EnsureInTransaction(doc)
#Insert here your code#
dirPath = IN[0]
paramName = IN[1]
dwgExportName = IN[2]
sheets = UnwrapElement(IN[3])
output = []
dwgExportOptions = DWGExportOptions.GetPredefinedOptions(doc, dwgExportName);
viewsToExport = []
loops = []
shapes = []
for sheet in sheets:
s = {}
data = []
viewports = sheet.GetAllViewports()
for viewport in viewports:
d = {}
v = doc.GetElement(viewport)
exportWC = v.LookupParameter(paramName).AsInteger()
if (exportWC == 1😞
view = doc.GetElement(v.ViewId)
viewsToExport.Add(view.Id)
viewName = view.Name
viewOrigin = XYZToPoint(view.Origin, du)
viewScale = view.Scale
viewCropBoxMin = XYZToPoint(view.CropBox.Min, du)
viewCropBoxMax = XYZToPoint(view.CropBox.Max, du)
viewCropBoxMin[0] = viewCropBoxMin[0] + east
viewCropBoxMin[1] = viewCropBoxMin[1] + north
viewCropBoxMax[0] = viewCropBoxMax[0] + east
viewCropBoxMax[1] = viewCropBoxMax[1] + north
viewCropBoxLoops = view.GetCropRegionShapeManager().GetCropShape()
viewAnnotationCropBoxLoops = view.GetCropRegionShapeManager().GetAnnotationCropShape()
splitRegions = view.GetCropRegionShapeManager().NumberOfSplitRegions
shapes = []
loop = []
viewCropBoxOrigin = []
for curveLoop in viewCropBoxLoops:
shape = []
for curve in curveLoop:
curveOrigin = XYZToPoint(curve.Origin, du)
loop.Add([curveOrigin[0], curveOrigin[1]])
#shapes.Add([curveOrigin[0], curveOrigin[1]])
shape.Add([curveOrigin[0]+east, curveOrigin[1]+north])
p1X = shape[0][0]
p1Y = shape[0][1]
p2X = shape[2][0]
p2Y = shape[2][1]
loops.Add(loop)
viewCropBoxOrigin.Add([(p1X + p2X)/2 , (p1Y + p2Y)/2])
shapes.Add(shape)
rX = view.CropBox.Transform.BasisY.X
rY = view.CropBox.Transform.BasisY.Y
viewCropboxRotation = math.degrees(math.atan2(rX, rY))
viewportBoxCenter = XYZToPoint(v.GetBoxCenter(), duMM)
viewportBoxOutlineMinimumPoint = XYZToPoint(v.GetBoxOutline().MinimumPoint, duMM)
viewportBoxOutlineMaximumPoint = XYZToPoint(v.GetBoxOutline().MaximumPoint, duMM)
d["viewUnit"] = du.ToString()
d["viewName"] = viewName
d["viewOrigin"] = viewOrigin
d["viewRotationUp"] = math.degrees(math.atan2(view.UpDirection.Y, view.UpDirection.X))
d["viewScale"] = viewScale
d["viewBoundingBox"] = [viewCropBoxMin, viewCropBoxMax]
d["viewportBoxCenter"] = viewportBoxCenter
d["viewportBoxOutlineMinimumPoint"] = viewportBoxOutlineMinimumPoint
d["viewportBoxOutlineMaximumPoint"] = viewportBoxOutlineMaximumPoint
d["viewCropbox"] = shapes
d["viewCropboxTopAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().TopAnnotationCropOffset, du)
d["viewCropboxBottomAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().BottomAnnotationCropOffset, du)
d["viewCropboxLeftAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().LeftAnnotationCropOffset, du)
d["viewCropboxRightAnnotationOffset"] = UnitUtils.ConvertFromInternalUnits(view.GetCropRegionShapeManager().RightAnnotationCropOffset, du)
d["viewCropboxOrigin"] = viewCropBoxOrigin
d["viewCropboxRotation"] = viewCropboxRotation
d["splitRegionsNumber"] = splitRegions
if splitRegions > 1:
TransactionManager.Instance.EnsureInTransaction(doc)
tempView = view.Duplicate(ViewDuplicateOption.WithDetailing)
csm = doc.GetElement(tempView).GetCropRegionShapeManager()
csm.RemoveSplit()
TransactionManager.Instance.TransactionTaskDone()
export = doc.Export(dirPath, viewName, List[ElementId]([tempView]), dwgExportOptions)
else:
export = doc.Export(dirPath, viewName, List[ElementId]([view.Id]), dwgExportOptions)
data.Add(d)
else:
continue
s["sheetName"] = sheet.Name
s["viewUnit"] = du.ToString()
s["sheetNumber"] = sheet.SheetNumber
s["data"] = data
export = doc.Export(dirPath, sheet.Name, List[ElementId]([sheet.Id]), dwgExportOptions)
output.Add(s)
#Dispose the active transaction
#TransactionManager.Instance.TransactionTaskDone()
#List outputs#
OUT = output, loops
Thanks!