Level reference

Level reference

Joris.vd.Meulen
Collaborator Collaborator
3,384 Views
5 Replies
Message 1 of 6

Level reference

Joris.vd.Meulen
Collaborator
Collaborator

Guys,

 

getting the reference (for dimensioning) of elements I used 

item.get_Geometry(opt) --> getting the faces --> getting the reference ... and used that in ReferenceArray. which works fine.

 

I tried doing the same with a level. But get_Geometry gives me an empty list ... how so? 

love python coding
0 Likes
Accepted solutions (1)
3,385 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

Similar to grids and reference planes grids are their own reference.

 

Create New Reference with grid as the argument in the constructor.

 

Below assumes you are in elevation or section.

 

    Public Function TObj13(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _
                 ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result

        Dim IntApp As UIApplication = commandData.Application
        Dim UIDoc As UIDocument = IntApp.ActiveUIDocument
        If UIDoc Is Nothing Then Return Result.Cancelled Else 
        Dim IntDoc As Document = UIDoc.Document


        Dim FEC As New FilteredElementCollector(IntDoc, IntDoc.ActiveView.Id)
        Dim ECF As New ElementClassFilter(GetType(Level))
        Dim IDS As IList(Of ElementId) = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElementIds

        Dim Rs As IEnumerable(Of Reference)
        Rs = From x As ElementId In IDS
             Let El As Element = IntDoc.GetElement(x)
             Let R As Reference = New Reference(El)
             Select R

        Dim RArr As New ReferenceArray()
        For Each item As Reference In Rs
            RArr.Append(item)
        Next

        Using Tx As New Transaction(IntDoc, "Add dimensions to levels")
            If Tx.Start = TransactionStatus.Started Then
                IntDoc.Create.NewDimension(IntDoc.ActiveView, Line.CreateBound(XYZ.Zero, XYZ.BasisZ), RArr)
                Tx.Commit()
            End If
        End Using

        Return Result.Succeeded
    End Function

 

Message 3 of 6

Joris.vd.Meulen
Collaborator
Collaborator

Ok, makes sense @RPTHOMAS108,

 

However, why doesn't the level class show me those properties?

 

For as much as I can understand the coding you mentioned (doing my coding in Python) ... you are using levels which you input as a new reference. But I can't get the reference at all ... or at least ... I don't get how it's done. 

 

http://www.revitapidocs.com/2018.1/577e5d4e-a558-118c-9dea-3b810b061775.htm

 

sigh I'm puzzled.

 

love python coding
0 Likes
Message 4 of 6

RPTHOMAS108
Mentor
Mentor

I don't know what you mean when you ask why the level class does not show the properties?

 

Below is a conversion to Python but I can't say for sure it works since I'm not familiar with the language.

 

import clr

class one(object):
	def TObj14(self, commandData, message, elements):
		IntApp = commandData.Application
		UIDoc = IntApp.ActiveUIDocument
		if UIDoc is None:
			return Result.Cancelled
		IntDoc = UIDoc.Document
		FEC = FilteredElementCollector(IntDoc, IntDoc.ActiveView.Id)
		ECF = ElementClassFilter(clr.GetClrType(Level))
		IDS = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElements
		RArr = ReferenceArray()
		enumerator = IDS.GetEnumerator()
		while enumerator.MoveNext():
			item = enumerator.Current
			RArr.Append(Reference(item))
		Tx = Transaction(IntDoc, "Add dimensions to levels")
		if Tx.Start == TransactionStatus.Started:
			IntDoc.Create.NewDimension(IntDoc.ActiveView, Line.CreateBound(XYZ.Zero, XYZ.BasisZ), RArr)
			Tx.Commit()
		return Result.Succeeded
0 Likes
Message 5 of 6

Joris.vd.Meulen
Collaborator
Collaborator

Hmm, no worries, it's me who doesn't understand it, and therefor it's hard to explain Man Very Happy

 

So my input is a list of levels.

 

That list of levels goes through a loop function to get each level and do something with it... in my case: somehow getting the Reference of it, so I can use it for dimensioning-function.  A bit like: https://forums.autodesk.com/t5/revit-api-forum/how-to-revit-2016-api-create-dimension-between-grid/t... but the get_geometry returns 'null' ... 

 

If you read that url (last reply) @RPTHOMAS108, do you better understand what I need, and how my startingpoint is?

love python coding
0 Likes
Message 6 of 6

Joris.vd.Meulen
Collaborator
Collaborator

Omg, that brainfart I just had.

 

okay. I finally got the thing you mentioned. Levels / Grids are references of itself. 

 

So (python style) ... putting it as easy as

Reference(level)

was enough to get the required Reference ....

 

pffff... 

 

ok. thanks @RPTHOMAS108 for showing me the way!

love python coding
0 Likes