|
| 1 | +""" |
| 2 | +Linked DWG PolyLine Redraw and Dimension Example |
| 3 | +
|
| 4 | +Redraws polylines in a given layer (LAYER_NAME) in a linked DWG instance |
| 5 | +and adds Dimensions to these segments |
| 6 | +
|
| 7 | +TESTED REVIT API: 2017 |
| 8 | +
|
| 9 | +Author: Frederic Beaupere | github.com/hdm-dt-fb |
| 10 | +
|
| 11 | +This file is shared on www.revitapidocs.com |
| 12 | +For more information visit http://github.com/gtalarico/revitapidocs |
| 13 | +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md |
| 14 | +""" |
| 15 | + |
| 16 | +from rpw import revit, db, ui, DB |
| 17 | + |
| 18 | +LAYER_NAME = 'A-FLOR-OTLN' # "ENTER_DWG_LAYER_NAME_HERE" |
| 19 | + |
| 20 | +selection = ui.Selection().get_elements(wrapped=False) |
| 21 | +dwg_link_instances = [l for l in selection if isinstance(l, DB.ImportInstance)] |
| 22 | + |
| 23 | +if not dwg_link_instances: |
| 24 | + ui.forms.Alert("please select a linked dwg", exit=True) |
| 25 | + |
| 26 | +active_view = revit.doc.ActiveView |
| 27 | +geo_opt = DB.Options() |
| 28 | +geo_opt.ComputeReferences = True |
| 29 | +geo_opt.IncludeNonVisibleObjects = True |
| 30 | +geo_opt.View = active_view |
| 31 | + |
| 32 | +geometry = dwg_link_instances[0].get_Geometry(geo_opt) |
| 33 | + |
| 34 | +with db.Transaction("redraw dim_help layer dwg polylines"): |
| 35 | + for geo_inst in geometry: |
| 36 | + geo_elem = geo_inst.GetInstanceGeometry() |
| 37 | + for polyline in geo_elem: |
| 38 | + element = revit.doc.GetElement(polyline.GraphicsStyleId) |
| 39 | + if not element: |
| 40 | + continue |
| 41 | + |
| 42 | + is_target_layer = element.GraphicsStyleCategory.Name == LAYER_NAME |
| 43 | + is_polyline = polyline.GetType().Name == "PolyLine" |
| 44 | + if is_polyline and is_target_layer: |
| 45 | + |
| 46 | + begin = None |
| 47 | + for pts in polyline.GetCoordinates(): |
| 48 | + if not begin: |
| 49 | + begin = pts |
| 50 | + continue |
| 51 | + end = pts |
| 52 | + line = DB.Line.CreateBound(begin, end) |
| 53 | + det_line = doc.Create.NewDetailCurve(active_view, line) |
| 54 | + line_refs = DB.ReferenceArray() |
| 55 | + geo_curve = det_line.GeometryCurve |
| 56 | + line_refs.Append(geo_curve.GetEndPointReference(0)) |
| 57 | + line_refs.Append(geo_curve.GetEndPointReference(1)) |
| 58 | + dim = doc.Create.NewDimension(active_view, |
| 59 | + det_line.GeometryCurve, |
| 60 | + line_refs) |
| 61 | + begin = pts |
0 commit comments