<Workspace Version="1.0.0.1180" X="810.727656814964" Y="793.761389414343" zoom="0.983159836482478" Name="Home" Description="" RunType="Manual" RunPeriod="1000" HasRunWithoutCrash="True">
  <NamespaceResolutionMap>
    <ClassMap partialName="SectionView.ToString" resolvedName="Revit.Elements.Views.SectionView" assemblyName="RevitNodes.dll" />
    <ClassMap partialName="View.ViewType" resolvedName="Revit.Elements.Views.View" assemblyName="RevitNodes.dll" />
  </NamespaceResolutionMap>
  <Elements>
    <PythonNodeModels.PythonNode guid="e100d6a1-9efa-487a-96f5-86cc69ab1b5c" type="PythonNodeModels.PythonNode" nickname="Python Script" x="2679.24680888238" y="-347.803663856523" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" inputcount="7">
      <Script>#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

views = UnwrapElement(IN[0])
toggle = IN[1]
cat = UnwrapElement(IN[2])
leader = IN[3]
leaderX = IN[4]
linePara = IN[5]
tagType = UnwrapElement(IN[6])

lst = []
if toggle == True:
	for view in views:			
		vt = view.ViewType.ToString()
		if vt != "FloorPlan":	
			lst.append("Wrong View Plan Type")
			
		else:		
			collector = FilteredElementCollector(doc,view.Id).OfCategoryId(cat.Id).ToElements()
			
			for i in collector:				
				if doc.GetElement(i.LevelId).Name == view.get_Parameter(BuiltInParameter.PLAN_VIEW_LEVEL).AsString():
												
					TransactionManager.Instance.EnsureInTransaction(doc)	
					
					bb = i.get_BoundingBox(view)
					bbM = bb.Max
					bbMi = bb.Min			
					pt = XYZ((bbM.X+bbMi.X)/2 , (bbM.Y+bbMi.Y)/2 , (bbM.Z+bbMi.Z)/2)
				
					tag = doc.Create.NewTag(view, i, leader, TagMode.TM_ADDBY_CATEGORY,TagOrientation.Horizontal, pt)
					tag.ChangeTypeId(tagType.Id)
					tag
					
					if i.Location.ToString() == "Autodesk.Revit.DB.LocationPoint":									
						locP = i.Location
						locRot = locP.Rotation + pi/2
					
						x = leaderX * cos(locRot)
						y = leaderX * sin(locRot)						
						newp = XYZ(x, y, 0)
						
						ElementTransformUtils.MoveElement(doc,tag.Id, newp)
						lst.append("%s Tag Created" % cat.Name)
					
					elif i.Location.ToString() == "Autodesk.Revit.DB.LocationCurve":															
						Cur = i.Location.Curve
						pt = Cur.Evaluate(linePara, True)
														
						if leader == True:					
							lineDir = Cur.Direction
							norm = XYZ.BasisZ.CrossProduct(lineDir).Normalize()					
							trans = norm.Multiply(leaderX)
							
							p1 = Cur.GetEndPoint(0).Add(trans)
							p2 = Cur.GetEndPoint(1).Add(trans)
							ln = Line.CreateBound(p1, p2)
							
							movePt = ln.Evaluate(linePara, True)
							tag.TagHeadPosition = movePt
					
							lst.append("%s Tag Created" % cat.Name)
						else:							
							tag.TagHeadPosition = pt
							lst.append("%s Tag Created" % cat.Name)
					
					TransactionManager.Instance.TransactionTaskDone()			
	OUT = lst
else:
	pass
	
	OUT = "Set toggle to TRUE"

	
</Script>
    </PythonNodeModels.PythonNode>
    <PythonNodeModels.PythonNode guid="7e3a8ce4-1e9f-49a0-91c1-013035d9a547" type="PythonNodeModels.PythonNode" nickname="Python Script" x="2943.97486306993" y="81.7696538777449" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" inputcount="4">
      <Script>#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 RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

views = UnwrapElement(IN[0])
toggle = IN[1]
cat = UnwrapElement(IN[2])
tagType = UnwrapElement(IN[3])

lst = []

if toggle == True:

	for view in views:
			
		vt = view.ViewType.ToString()
		if vt == "FloorPlan":
		
			coll = FilteredElementCollector(doc,view.Id).OfCategoryId(tagType.Id).ToElements()
			
			for i in coll:
				TransactionManager.Instance.EnsureInTransaction(doc)	
	
				eleId = i.TaggedLocalElementId
				ele = doc.GetElement(eleId)
				
				if ele.Category.Name == cat.Name:
					doc.Delete(i.Id)
					lst.append("%s Tag Deleted" % ele.Category.Name)
				
				TransactionManager.Instance.TransactionTaskDone()
	OUT = lst
else:
	OUT = "Set toggle to TRUE"

	
</Script>
    </PythonNodeModels.PythonNode>
    <CoreNodeModels.Watch guid="f73cf924-2c4b-4efc-8fc1-ad7cbd646eac" type="CoreNodeModels.Watch" nickname="Watch" x="3090.27332159055" y="80.0304473397158" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" />
    <DSRevitNodesUI.Categories guid="7333d99a-e312-4ae5-9f77-12436b6e6bab" type="DSRevitNodesUI.Categories" nickname="Categories" x="2687.19217072535" y="182.045378348879" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false" index="144:DoorTags" />
    <CoreNodeModels.Input.BoolSelector guid="fab66edc-7afb-44f0-bfb8-b526bef2f1f7" type="CoreNodeModels.Input.BoolSelector" nickname="Boolean" x="2715.46035658838" y="113.145191919843" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
      <System.Boolean>False</System.Boolean>
    </CoreNodeModels.Input.BoolSelector>
    <CoreNodeModels.Input.BoolSelector guid="010da85a-918c-4760-ad60-d47f7e9ced0b" type="CoreNodeModels.Input.BoolSelector" nickname="Boolean" x="-529.032115040985" y="-256.589496657516" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
      <System.Boolean>True</System.Boolean>
    </CoreNodeModels.Input.BoolSelector>
    <PythonNodeModels.PythonNode guid="d71d4197-7fd9-41f3-be4b-da0e9d9fa16f" type="PythonNodeModels.PythonNode" nickname="Python Script" x="-246.04859090438" y="-258.185305151714" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="true" inputcount="1">
      <Script>#Copyright(c) 2016 www.Learndynamo.com 
#Please contact at jeremy@learndynamo.com

import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitNodes")

import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

toggle = IN[0]
out = []
lst = []
geometry = []
intersections = []

if toggle == True:

	sepCollector = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_RoomSeparationLines).ToElements()
	wallCollector = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Walls).ToElements()

	for wall in wallCollector:
		opt = Options()
		opt.ComputeReferences = True
		opt.DetailLevel = ViewDetailLevel.Fine
		geo = wall.get_Geometry(opt)
		geometry.append(geo)

	geometry = [item for sublist in geometry for item in sublist]

	for j in sepCollector:
		for g in geometry:
			try:
				opts = SolidCurveIntersectionOptions()
				inter = g.IntersectWithCurve(j.GeometryCurve, opts)
				if inter.SegmentCount &gt; 0:
					opts2 = SolidCurveIntersectionOptions()
					opts2.ResultType = SolidCurveIntersectionMode.CurveSegmentsOutside
					inter2 = g.IntersectWithCurve(j.GeometryCurve, opts2)
					if inter2.SegmentCount &gt; 0:
						intersections.append(inter2.GetCurveSegment(0).ToProtoType() )
						TransactionManager.Instance.EnsureInTransaction(doc)
						j.SetGeometryCurve(inter2.GetCurveSegment(0), True)
						lst.append("Line Reset.")
						TransactionManager.Instance.TransactionTaskDone()
					else:
						TransactionManager.Instance.EnsureInTransaction(doc)
						doc.Delete(j.Id)
						lst.append("Line Deleted.")
    					TransactionManager.Instance.TransactionTaskDone()
			except:
				pass
	OUT = True, lst	
	
else:
	OUT = "Set toggle to True."
			</Script>
    </PythonNodeModels.PythonNode>
    <CoreNodeModels.Watch guid="9a8dc174-3125-4b9e-94ba-64500f06aa46" type="CoreNodeModels.Watch" nickname="Watch" x="2852.77969152193" y="-345.792136185044" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" />
    <PythonNodeModels.PythonNode guid="9b720f4d-3561-4858-9483-df44da9413a9" type="PythonNodeModels.PythonNode" nickname="Python Script" x="390.571461565596" y="-262.958079108329" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="true" inputcount="1">
      <Script>#Copyright(c) 2016 www.Learndynamo.com 
#Please contact at jeremy@learndynamo.com

import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import itertools

doc = DocumentManager.Instance.CurrentDBDocument

toggle = IN[0]
out = []
geometry = []
intersections = []

if toggle == True:
	sepCollector = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_RoomSeparationLines).ToElements()

	for i, j in itertools.combinations(sepCollector, 2):
		try:
			ic = i.GeometryCurve
			jc = j.GeometryCurve
			if ic.Intersect(jc) == SetComparisonResult.Equal:
				iEnd1 = ic.GetEndPoint(0).ToPoint()
				iEnd2 = ic.GetEndPoint(1).ToPoint()
				jEnd1 = jc.GetEndPoint(0).ToPoint()
				jEnd2 = jc.GetEndPoint(1).ToPoint()
				ipap1 = jc.ToProtoType().ParameterAtPoint(iEnd1)
				ipap2 = jc.ToProtoType().ParameterAtPoint(iEnd2)
				jpap1 = ic.ToProtoType().ParameterAtPoint(jEnd1)
				jpap2 = ic.ToProtoType().ParameterAtPoint(jEnd2)
			
				#If True, line jc inside curve ic
				if (ipap1 &lt; 0 or ipap1 &gt; 1) and (ipap2 &lt; 0 or ipap2 &gt; 1):

					TransactionManager.Instance.EnsureInTransaction(doc)	
					doc.Delete(j.Id)
					out.append("Line Deleted.")
					TransactionManager.Instance.TransactionTaskDone()
				
				#If True, line ic inside curve jc		
				elif (ipap1 &gt; 0 and ipap1 &lt; 1) and (ipap2 &gt; 0 and ipap2 &lt; 1):
			
					TransactionManager.Instance.EnsureInTransaction(doc)	
					doc.Delete(i.Id)
					out.append("Line Deleted.")
					TransactionManager.Instance.TransactionTaskDone()
				
				#Lines overlap,move end points
				else:
					if (ipap1 &gt;= 0 and ipap1 &lt;= 1):
						iinpt = iEnd1
					else:
						ioutpt = iEnd1					
					if (ipap2 &gt;= 0 and ipap2 &lt;= 1):
						iinpt = iEnd2
					else:
						ioutpt = iEnd2					
					if (jpap1 &gt;= 0 and jpap1 &lt;= 1):
						jinpt = jEnd1
					else:
						joutpt = jEnd1					
					if (jpap2 &gt;= 0 and jpap2 &lt;= 1):
						jinpt = jEnd2	
					else:
						joutpt = jEnd2
					
					newi = Line.CreateBound(iinpt.ToXyz(), ioutpt.ToXyz())
					newj = Line.CreateBound(iinpt.ToXyz(), joutpt.ToXyz())
				
					TransactionManager.Instance.EnsureInTransaction(doc)
					i.SetGeometryCurve(newi, True)
					j.SetGeometryCurve(newj, True)
					TransactionManager.Instance.TransactionTaskDone()
					out.append("Line Reset.")		
		except:
			pass
	OUT = out		
		
else:
	OUT = "Set to true"
	
</Script>
    </PythonNodeModels.PythonNode>
    <Dynamo.Graph.Nodes.ZeroTouch.DSFunction guid="a1afb83b-35c6-4839-ac57-80a625952498" type="Dynamo.Graph.Nodes.ZeroTouch.DSFunction" nickname="Transaction.End" x="152.628804054528" y="-262.170413464437" isVisible="true" isUpstreamVisible="true" lacing="Shortest" isSelectedInput="False" IsFrozen="false" isPinned="false" assembly="RevitNodes.dll" function="Revit.Transaction.Transaction.End@var" />
    <Dynamo.Graph.Nodes.ZeroTouch.DSFunction guid="d200577f-5a45-4dd7-8d76-1c443c8ac282" type="Dynamo.Graph.Nodes.ZeroTouch.DSFunction" nickname="List.FirstItem" x="8.04466900335336" y="-262.077056697426" isVisible="true" isUpstreamVisible="true" lacing="Shortest" isSelectedInput="False" IsFrozen="false" isPinned="false" assembly="DSCoreNodes.dll" function="DSCore.List.FirstItem@var[]..[]" />
  </Elements>
  <Connectors>
    <Dynamo.Graph.Connectors.ConnectorModel start="e100d6a1-9efa-487a-96f5-86cc69ab1b5c" start_index="0" end="9a8dc174-3125-4b9e-94ba-64500f06aa46" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="7e3a8ce4-1e9f-49a0-91c1-013035d9a547" start_index="0" end="f73cf924-2c4b-4efc-8fc1-ad7cbd646eac" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="7333d99a-e312-4ae5-9f77-12436b6e6bab" start_index="0" end="7e3a8ce4-1e9f-49a0-91c1-013035d9a547" end_index="3" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="fab66edc-7afb-44f0-bfb8-b526bef2f1f7" start_index="0" end="7e3a8ce4-1e9f-49a0-91c1-013035d9a547" end_index="1" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="010da85a-918c-4760-ad60-d47f7e9ced0b" start_index="0" end="d71d4197-7fd9-41f3-be4b-da0e9d9fa16f" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="d71d4197-7fd9-41f3-be4b-da0e9d9fa16f" start_index="0" end="d200577f-5a45-4dd7-8d76-1c443c8ac282" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="a1afb83b-35c6-4839-ac57-80a625952498" start_index="0" end="9b720f4d-3561-4858-9483-df44da9413a9" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="d200577f-5a45-4dd7-8d76-1c443c8ac282" start_index="0" end="a1afb83b-35c6-4839-ac57-80a625952498" end_index="0" portType="0" />
  </Connectors>
  <Notes>
    <Dynamo.Graph.Notes.NoteModel guid="796c2100-c358-465e-8b33-d650538f4dd5" text="Delete Tags" x="2961.86927572552" y="45.4674020467999" />
    <Dynamo.Graph.Notes.NoteModel guid="04e43fe6-3ef1-49a5-9310-30001bcfdf57" text="Reset Toggle" x="2743.48807195741" y="74.2476457680939" />
    <Dynamo.Graph.Notes.NoteModel guid="fc85b4bc-9a25-472e-aff9-ce5d29d6c6a7" text="LearnDynamo - Module 5&#xD;&#xA;Clean Separation Lines&#xD;&#xA;&#xD;&#xA;--------------------------------------&#xD;&#xA;&#xD;&#xA;Revit Version - 2016&#xD;&#xA;&#xD;&#xA;Dynamo Version 1.0&#xD;&#xA;&#xD;&#xA;Script Version 1.0" x="-529.892913515826" y="-519.428601347194" />
    <Dynamo.Graph.Notes.NoteModel guid="27cf76a7-efe6-4bb4-9c4d-074d66ab53ed" text="Create Tags" x="2698.97971533341" y="-384.242169535216" />
    <Dynamo.Graph.Notes.NoteModel guid="2917c440-6c2f-46bb-b7c5-0b72c5ae6160" text="Clean Wall/Separation Lines" x="-268.216501885558" y="-298.822401083576" />
    <Dynamo.Graph.Notes.NoteModel guid="9859226e-6af3-4add-935c-32283eb0bb26" text="Clean Separation/Separation Lines" x="353.802520933743" y="-299.732613449131" />
    <Dynamo.Graph.Notes.NoteModel guid="bf4ec322-9c06-48fa-a89d-344711c06cdc" text="Set True to Clean" x="-520.622137249902" y="-293.568878980861" />
  </Notes>
  <Annotations>
    <Dynamo.Graph.Annotations.AnnotationModel guid="2e84d9aa-5eb9-4e7a-98aa-507cf4575c55" annotationText="Delete Tags Input" left="2677.19217072535" top="44.2476457680939" width="184" height="230.797732580785" fontSize="14" InitialTop="74.2476457680939" InitialHeight="230.797732580785" TextblockHeight="20" backgrouund="#FFA4E1FF">
      <Models ModelGuid="7333d99a-e312-4ae5-9f77-12436b6e6bab" />
      <Models ModelGuid="fab66edc-7afb-44f0-bfb8-b526bef2f1f7" />
      <Models ModelGuid="04e43fe6-3ef1-49a5-9310-30001bcfdf57" />
    </Dynamo.Graph.Annotations.AnnotationModel>
  </Annotations>
  <Presets />
  <Cameras>
    <Camera Name="Background Preview" eyeX="-14346.6657086483" eyeY="27741.7043444153" eyeZ="-1069.53075068303" lookX="4303.53107594592" lookY="-22341.1146804733" lookZ="-5094.45887840823" upX="0.564406087837228" upY="0.484809657591786" upZ="-0.668135849832082" />
  </Cameras>
</Workspace>