# Modul 2 add an output

**URL:** <https://forum.dynamobim.com/t/modul-2-add-an-output/6547>\
**Category:** Developers\
**Created:** [October 5, 2016, 9:16am UTC](https://forum.dynamobim.com/t/modul-2-add-an-output/6547 "2016-10-05T09:16:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arno\_De\_Lange](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/arno_de_lange/32/35178_2.png) [@Arno\_De\_Lange](https://forum.dynamobim.com/u/Arno_De_Lange)\
**Post date:** [October 5, 2016, 9:16am UTC](https://forum.dynamobim.com/t/modul-2-add-an-output/6547/1 "2016-10-05T09:16:31Z")

</div>

I’m struggling with the python from [http://learndynamo.com/mod2/](http://learndynamo.com/mod2/)

I don’t know much python and i can’t figure it out.  
As an output i also want the created elevations, so that i can set some parameters after it is created.  
Can somebody tell me what i need to change.

thank you

> ```
> #Copyright(c) 2016 www.Learndynamo.com 
> #Please contact at jeremy@learndynamo.com
> 
> ```

> ```
> import clr
> clr.AddReference('RevitAPI')
> clr.AddReference("RevitServices")
> clr.AddReference("RevitNodes")
> import RevitServices
> import Revit
> import Autodesk
> from Autodesk.Revit.DB import *
> from math import *
> 
> ```

> ```
> clr.ImportExtensions(Revit.GeometryConversion)
> 
> ```

> ```
> from RevitServices.Persistence import DocumentManager
> from RevitServices.Transactions import TransactionManager
> 
> ```

> ```
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> ```

> ```
> toggle = IN[0]
> points = UnwrapElement(IN[1])
> modelPoints = UnwrapElement(IN[2])
> cropCurves = UnwrapElement(IN[3])
> viewType = UnwrapElement(IN[4])
> 
> ```

> ```
> lst = []
> 
> ```

> ```
> #Get Family View Type
> vft = 0
> collector = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
> 
> ```

> ```
> #eleViews = []
> for i in collector:
> if i.ViewFamily == ViewFamily.Elevation:        
> vft = i.Id
> break
> 
> ```

> ```
> if toggle == True:
> 
> ```

> ```
> TransactionManager.Instance.EnsureInTransaction(doc)
>  
> for ind, point in enumerate(points):
> 
> ```

> ```
> #Retrieve the mid point of model lines and get X,Y.        
> modelMP = modelPoints[ind].ToXyz()
> modelMPX = modelMP.X
> modelMPY = modelMP.Y
>       
> #Retrieve individual lines of crop window.        
> cropLines = cropCurves[ind]
> l1 = cropLines[0].ToRevitType()
> l2 = cropLines[1].ToRevitType()
> l3 = cropLines[2].ToRevitType()
> l4 = cropLines[3].ToRevitType()
>                     
> # Create a line in the z-Axis for elevation marker to rotate around.            
> elevationPT = point.ToXyz()
> elptRotate = XYZ(elevationPT.X, elevationPT.Y, elevationPT.Z+100)
> ln = Line.CreateBound(elevationPT, elptRotate)
> 
> ```

> ```
> #Calculate the angle between Model Mid Point and Elevation Point.
> elevationPTY = elevationPT.Y
> elevationPTX = elevationPT.X                            
> combY = elevationPTY-modelMPY
> combX = elevationPTX-modelMPX            
> ang = atan2(combY, combX)
> 
> ```

> ```
> #Create elevation marker and elevation in position 0.
> eleMarker = ElevationMarker.CreateElevationMarker(doc, viewType.Id, elevationPT, 100)
> ele = eleMarker.CreateElevation(doc, doc.ActiveView.Id , 0)
>       
> #Rotate elevation marker towars model line.
> ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, ang)
>       
> #  
> crManager = ele.GetCropRegionShapeManager()
> #crShape = crManager.GetCropRegionShape()
> 
> ```

> ```
> newCurveLoop = []
> newCurveLoop.Add(l1)
> newCurveLoop.Add(l2)
> newCurveLoop.Add(l3)
> newCurveLoop.Add(l4)
>            
> cLoop = CurveLoop.Create(newCurveLoop)
> 
> ```

> ```
> try:            
> crManager.SetCropRegionShape(cLoop)
> lst.append("Elevation Created")
>        
> except:
> pass
> lst.append("Missed Elevation")
> 
> ```

> ```
> TransactionManager.Instance.TransactionTaskDone()
>   
> OUT = lst
>     
> else:
> 
> ```

> ```
> OUT = "Set toggle to TRUE"
> 
> ```

---

<div class="post-metadata">

**Author:** ![Steven](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/steven/32/112504_2.png) [@Steven](https://forum.dynamobim.com/u/Steven)\
**Post date:** [January 4, 2018, 10:27pm UTC](https://forum.dynamobim.com/t/modul-2-add-an-output/6547/2 "2018-01-04T22:27:47Z")

</div>

I too am trying to figure this out. I know it has to do with lines 88-95.  
I have been playing around with it for some time and I cannot get it to say “Elevation Created”. I know the problem has something to do with the curves I am feeding it but not sure. I would like to remove the SetCropRegionShape from the code and use View.SetCropBoxCurves [Shown in this post for more control.](https://forum.dynamobim.com/t/elevation-view-crop-region-adjust-z-values/16962)

Thanks for any help you can provide,

I added the code in one block if that more helpful.

```
#Copyright(c) 2016 www.Learndynamo.com 
#Please contact at jeremy@learndynamo.com

import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
clr.AddReference("RevitNodes")
import RevitServices
import Revit
import Autodesk
from Autodesk.Revit.DB import *
from math import *

clr.ImportExtensions(Revit.GeometryConversion)

from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

toggle = IN[0]
points = UnwrapElement(IN[1])
modelPoints = UnwrapElement(IN[2])
cropCurves = UnwrapElement(IN[3])
viewType = UnwrapElement(IN[4])

lst = []

#Get Family View Type
vft = 0
collector = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()

#eleViews = []
for i in collector:
	if i.ViewFamily == ViewFamily.Elevation:		
		vft = i.Id
		break
 
if toggle == True:
	
	TransactionManager.Instance.EnsureInTransaction(doc)
	
	for ind, point in enumerate(points):
	
		#Retrieve the mid point of model lines and get X,Y.		
		modelMP = modelPoints[ind].ToXyz()
		modelMPX = modelMP.X
		modelMPY = modelMP.Y
		
		#Retrieve individual lines of crop window.		
		cropLines = cropCurves[ind]
		l1 = cropLines[0].ToRevitType()
		l2 = cropLines[1].ToRevitType()
		l3 = cropLines[2].ToRevitType()
		l4 = cropLines[3].ToRevitType()
					
		# Create a line in the z-Axis for elevation marker to rotate around.			
		elevationPT = point.ToXyz()
		elptRotate = XYZ(elevationPT.X, elevationPT.Y, elevationPT.Z+100)
		ln = Line.CreateBound(elevationPT, elptRotate)

		#Calculate the angle between Model Mid Point and Elevation Point.
		elevationPTY = elevationPT.Y
		elevationPTX = elevationPT.X							
		combY = elevationPTY-modelMPY
		combX = elevationPTX-modelMPX			
		ang = atan2(combY, combX)

		#Create elevation marker and elevation in position 0.
		eleMarker = ElevationMarker.CreateElevationMarker(doc, viewType.Id, elevationPT, 100)
		ele = eleMarker.CreateElevation(doc, doc.ActiveView.Id , 0)
		
		#Rotate elevation marker towars model line.
		ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, ang)
		
		#	
		crManager = ele.GetCropRegionShapeManager()
		#crShape = crManager.GetCropRegionShape()

		newCurveLoop = []
		newCurveLoop.Add(l1)
		newCurveLoop.Add(l2)
		newCurveLoop.Add(l3)
		newCurveLoop.Add(l4)
			
		cLoop = CurveLoop.Create(newCurveLoop)

		try:			
			crManager.SetCropRegionShape(cLoop)
			lst.append("Elevation Created")
		
		except:
			pass
			lst.append("Missed Elevation")

	TransactionManager.Instance.TransactionTaskDone()
	
	OUT = lst
	
else:

	OUT = "Set toggle to TRUE"
```

---

<div class="post-metadata">

**Author:** ![vanman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanman/32/20881_2.png) [@vanman](https://forum.dynamobim.com/u/vanman)\
**Post date:** [October 11, 2018, 2:00am UTC](https://forum.dynamobim.com/t/modul-2-add-an-output/6547/3 "2018-10-11T02:00:56Z")

</div>

Did anyone manage to code in the out elements of the created elevations to set crop box curves after and change parameters?

---

<div class="post-metadata">

**Author:** ![vanman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanman/32/20881_2.png) [@vanman](https://forum.dynamobim.com/u/vanman)\
**Post date:** [October 11, 2018, 4:02am UTC](https://forum.dynamobim.com/t/modul-2-add-an-output/6547/4 "2018-10-11T04:02:39Z")

</div>

Found this in the comments, someone modified the code to have an elevations created output list

```
toggle = IN[0]
points = UnwrapElement(IN[1])
modelPoints = UnwrapElement(IN[2])
cropCurves = UnwrapElement(IN[3])
viewType = UnwrapElement(IN[4])
 
lst = []
viewid = []
output = []
 
#Get Family View Type
vft = 0
collector = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
 
#eleViews = []
for i in collector:
    if i.ViewFamily == ViewFamily.Elevation:       
        vft = i.Id
        break
 
if toggle == True:
   
    TransactionManager.Instance.EnsureInTransaction(doc)
   
    for ind, point in enumerate(points):
   
        #Retrieve the mid point of model lines and get X,Y.    
        modelMP = modelPoints[ind].ToXyz()
        modelMPX = modelMP.X
        modelMPY = modelMP.Y
       
        #Retrieve individual lines of crop window.     
        cropLines = cropCurves[ind]
        l1 = cropLines[0].ToRevitType()
        l2 = cropLines[1].ToRevitType()
        l3 = cropLines[2].ToRevitType()
        l4 = cropLines[3].ToRevitType()
                   
        # Create a line in the z-Axis for elevation marker to rotate around.           
        elevationPT = point.ToXyz()
        elptRotate = XYZ(elevationPT.X, elevationPT.Y, elevationPT.Z+100)
        ln = Line.CreateBound(elevationPT, elptRotate)
 
        #Calculate the angle between Model Mid Point and Elevation Point.
        elevationPTY = elevationPT.Y
        elevationPTX = elevationPT.X                           
        combY = elevationPTY-modelMPY
        combX = elevationPTX-modelMPX          
        ang = atan2(combY, combX)
 
        #Create elevation marker and elevation in position 0.
        eleMarker = ElevationMarker.CreateElevationMarker(doc, viewType.Id, elevationPT, 100)
        ele = eleMarker.CreateElevation(doc, doc.ActiveView.Id , 0)
        viewid.append(ele)
       
        #Rotate elevation marker towars model line.
        ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, ang)
       
        #  
        crManager = ele.GetCropRegionShapeManager()
        #crShape = crManager.GetCropRegionShape()
 
        newCurveLoop = []
        newCurveLoop.Add(l1)
        newCurveLoop.Add(l2)
        newCurveLoop.Add(l3)
        newCurveLoop.Add(l4)
           
        cLoop = CurveLoop.Create(newCurveLoop)
 
        try:           
            crManager.SetCropRegionShape(cLoop)
            lst.append("Elevation Created")
       
        except:
            pass
            lst.append("Missed Elevation")
 
    TransactionManager.Instance.TransactionTaskDone()
   
    output.append([lst,viewid])
   
    OUT = output
   
   
else:
 
    OUT = "Set Run Gate to TRUE"
```

---

<div class="post-metadata">

**Author:** ![vanman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanman/32/20881_2.png) [@vanman](https://forum.dynamobim.com/u/vanman)\
**Post date:** [October 11, 2018, 4:18am UTC](https://forum.dynamobim.com/t/modul-2-add-an-output/6547/5 "2018-10-11T04:18:55Z")

</div>

some more reading to fix missed elevation… SetCropRegionShape() method (line 59) has been replaced with SetCropShape() for 2017 Revit
