<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Obtaining References from edges in Python in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7356104#M56268</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm (trying) to put together a Python routine that will automatically create dimensions on a square face of a generic model. i.e. the user select the face and dimensions appear...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm writing Python code using Dynamo.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've got some of the code working, obtaining the edges from a user selected 3D face, this returns the 4 edges (which are Edge class objects), it should simply be a case of obtaining the edge's reference that can be used to create the dimensions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Edge class has a Property which should return a reference to the edge - but when I run the code, it returns Null - and I can't see why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; # Dynamo
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
selobject		= UnwrapElement(IN[0])	# Object to select

#Get user to pick a face
selob = uidoc.Selection.PickObject(Selection.ObjectType.PointOnElement, "Pick something now")

#Get Id of element thats picked
selobid = selob.ElementId

#Get element thats picked
getob = doc.GetElement(selobid)

#Get face thats picked
getface = getob.GetGeometryObjectFromReference(selob)

#Get edges of face (returns a list the first object is the list of edges)
edgeloops = getface.EdgeLoops

#Select the first edge
dimedge1 = edgeloops[0][0]

#Select the third edge (the one opposite the first)
dimedge2 = edgeloops[0][2]

#Obtain a reference of the first edge
edgeref1 = dimedge1.Reference

#Obtain a reference of the thord edge
edgeref2 = dimedge2.Reference

#Assign your output to the OUT variable.
OUT = [selob, selobid, getob, getface, edgeloops, dimedge1, dimedge2, edgeref1, edgeref2]&lt;/PRE&gt;
&lt;P&gt;If you execute it you'll see that edgeref1 and edgeref2 variables both return Null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Sep 2017 19:45:29 GMT</pubDate>
    <dc:creator>Kevin.Bell</dc:creator>
    <dc:date>2017-09-05T19:45:29Z</dc:date>
    <item>
      <title>Obtaining References from edges in Python</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7356104#M56268</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm (trying) to put together a Python routine that will automatically create dimensions on a square face of a generic model. i.e. the user select the face and dimensions appear...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm writing Python code using Dynamo.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've got some of the code working, obtaining the edges from a user selected 3D face, this returns the 4 edges (which are Edge class objects), it should simply be a case of obtaining the edge's reference that can be used to create the dimensions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Edge class has a Property which should return a reference to the edge - but when I run the code, it returns Null - and I can't see why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; # Dynamo
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
selobject		= UnwrapElement(IN[0])	# Object to select

#Get user to pick a face
selob = uidoc.Selection.PickObject(Selection.ObjectType.PointOnElement, "Pick something now")

#Get Id of element thats picked
selobid = selob.ElementId

#Get element thats picked
getob = doc.GetElement(selobid)

#Get face thats picked
getface = getob.GetGeometryObjectFromReference(selob)

#Get edges of face (returns a list the first object is the list of edges)
edgeloops = getface.EdgeLoops

#Select the first edge
dimedge1 = edgeloops[0][0]

#Select the third edge (the one opposite the first)
dimedge2 = edgeloops[0][2]

#Obtain a reference of the first edge
edgeref1 = dimedge1.Reference

#Obtain a reference of the thord edge
edgeref2 = dimedge2.Reference

#Assign your output to the OUT variable.
OUT = [selob, selobid, getob, getface, edgeloops, dimedge1, dimedge2, edgeref1, edgeref2]&lt;/PRE&gt;
&lt;P&gt;If you execute it you'll see that edgeref1 and edgeref2 variables both return Null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 19:45:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7356104#M56268</guid>
      <dc:creator>Kevin.Bell</dc:creator>
      <dc:date>2017-09-05T19:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining References from edges in Python</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7372490#M56269</link>
      <description>&lt;P&gt;Hi, Kevin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found solution for your problem. The main idea is to get geometry with ComputeReference = True and find appropriate face by reference&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, I don't know Python too much, so I've created an addin in C#. You may get it from &lt;A href="https://github.com/CADBIMDeveloper/PutRevitDimensionsToSquareFaces" target="_blank"&gt;https://github.com/CADBIMDeveloper/PutRevitDimensionsToSquareFaces&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 08:01:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7372490#M56269</guid>
      <dc:creator>aignatovich</dc:creator>
      <dc:date>2017-09-12T08:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining References from edges in Python</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7372776#M56270</link>
      <description>&lt;P&gt;Hi again!&lt;BR /&gt;&lt;BR /&gt;I've fixed the code in the repository, there were a lot of tricks with revit references to make this work as expected with families, sorry, I've tested it only with floors at the first time, now it works with family instances too&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 10:11:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7372776#M56270</guid>
      <dc:creator>aignatovich</dc:creator>
      <dc:date>2017-09-12T10:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining References from edges in Python</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7374554#M56271</link>
      <description>&lt;P&gt;Hi&amp;nbsp;aignatovich, I really appreciate you doing some work on this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't look at the code at the moment as am out of the office, but will check it out soon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ComputeReference = True is not something I've come across, I'll have to read up on that.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 20:03:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7374554#M56271</guid>
      <dc:creator>Kevin.Bell</dc:creator>
      <dc:date>2017-09-12T20:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining References from edges in Python</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7376186#M56272</link>
      <description>&lt;P&gt;Hi again!&lt;BR /&gt;&lt;BR /&gt;There is another simpler solution, if you use Revit 2018 and can prepare your family for dimensioning. You can add reference planes, xLeft, xRight, yTop, yBottom:&lt;/P&gt;&lt;PRE&gt;def CreateDimension(instance, refNames, direction):
	references = ReferenceArray()
	
	for x in refNames:
		references.Append(instance.GetReferenceByName(x))
	
	origin = instance.Location.Point
	
	transform = instance.GetTotalTransform()
	transform.Origin = XYZ.Zero
	
	dimensionDirection = transform.OfPoint(direction)
	
	dimensionLine = Line.CreateUnbound(origin, dimensionDirection)
	
	doc.Create.NewDimension(doc.ActiveView, dimensionLine, references)

famInst = selection[0]

tx = Transaction(doc, "create dimensions")
tx.Start()

CreateDimension(famInst, ["xLeft", "xRight"], XYZ.BasisX)
CreateDimension(famInst, ["yBottom", "yTop"], XYZ.BasisY)

tx.Commit()&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 06:59:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/obtaining-references-from-edges-in-python/m-p/7376186#M56272</guid>
      <dc:creator>aignatovich</dc:creator>
      <dc:date>2017-09-13T06:59:28Z</dc:date>
    </item>
  </channel>
</rss>

