Draw Space Separation Lines

Draw Space Separation Lines

Anonymous
Not applicable
2,882 Views
11 Replies
Message 1 of 12

Draw Space Separation Lines

Anonymous
Not applicable

Hello everybody!

I am working on a macro to synchronize all Room or Spaces beteween models.

 

It seems quite easy (get element insertion points from the linked model --> create a space in the same point in the current model).
As you know, when the rooms/spaces depend on any space separator line, my tool should also get all the separator lines and replicate them in the current model... Here is the issue.
As per shown in the code below, i have nanaged to create a model line where a space separation is. But, now, I do not know how to convert it to a Space separator line 😞

Has anyone any experience with creating this kind of lines?

any idea is welcome!!

 

		public void repSpaces()
		{
			UIDocument uiDoc = this.ActiveUIDocument;
			Document doc = this.ActiveUIDocument.Document;
			Selection sel = uiDoc.Selection;
			
			
			#region Select the linked model
			//----------------------------------------------------------------------------------------
			Reference r = sel.PickObject(ObjectType.Element, "Select Linked Model");
			Element slctdLnk = doc.GetElement(r);
			//----------------------------------------------------------------------------------------
			//
			//
			#endregion
			#region Collect all Rvt Links
			//----------------------------------------------------------------------------------------
			FilteredElementCollector collector = new FilteredElementCollector(doc);
			IList<Element> elems = collector.OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(typeof(RevitLinkType)).ToElements();			
			//----------------------------------------------------------------------------------------
			//
			//
			#endregion
			#region Find the Linked document that matches with the selected linked model
			//----------------------------------------------------------------------------------------
			foreach (Element elem in elems)
			{
				RevitLinkType lnkTyp = elem as RevitLinkType;
				foreach (Document lnkDoc in this.Application.Documents)
				{
					if (lnkDoc.Title.Equals(lnkTyp.Name) && slctdLnk.Name.StartsWith(lnkDoc.Title))
			//
			//					{
			#endregion			
			
						#region Get Room separation lines and draw space sepatation lines in current model
						//----------------------------------------------------------------------------------------
						FilteredElementCollector lineColl = new FilteredElementCollector(lnkDoc);
						lineColl.OfCategory(BuiltInCategory.OST_RoomSeparationLines);
						
						using (Transaction t = new Transaction(doc))
						{
							t.Start("Add Space Shared Parameters");
							foreach (ModelLine l in lineColl)
							{
								LocationCurve loc = l.Location as LocationCurve;
								XYZ stPoint = loc.Curve.GetEndPoint(0);
								XYZ enPoint = loc.Curve.GetEndPoint(1);
								
								
								
								Level level = l.Document.GetElement(l.LevelId) as Level;
								string levelName = level.Name.ToString();
								
								FilteredElementCollector collLev = new FilteredElementCollector(doc);
								IList<Element> levels = collLev.OfClass(typeof(Level)).ToElements();
								
								foreach (Element e in levels)
								{
									if (e.Name == levelName)
										level = e as Level;
								}
								

								SketchPlane skP = SketchPlane.Create(doc,level.Id);
								
								Line line = Line.CreateBound(stPoint,enPoint);
								ModelLine mline = doc.Create.NewModelCurve(line,skP) as ModelLine;
								
		
							
							}
							t.Commit();
						}
					}
				}
			}

 

 

0 Likes
2,883 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

Hello again,

I have found the way to create new space separator lines, 

 

CurveArray cArray = new CurveArray();
cArray.Append(line);
		
doc.Create.NewSpaceBoundaryLines(skP,cArray,doc.ActiveView);

The problen is that this method needs a view

Untitled.png

 

If i set "doc.ActiveView" and run my macro from a 3D view, te program crashes...

 

Any solution?

thanks in advance!

 

 

0 Likes
Message 3 of 12

Anonymous
Not applicable
Look through the database for a ViewPlan that has the desired level associated with it an use that.
0 Likes
Message 4 of 12

BenoitE&A
Collaborator
Collaborator

Hi all,

Old post but real concern: why would anybody need a view to create a SpaceSeparationLine (or a Room SeparationLine)? I can't figure that out... 

If you check the documentation the NewSpaceBoundaryLines requires :

- a SketchPlane (which can be as simple as a plane associated with a level)

- a CurveArray

Up to here I'm fine and I understand the why. But the last....

- a View

Why would you need a view? This line exists in ALL "correct" views, same as a space/room...

Anybody has an answer ?

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 5 of 12

mathieu.josserand
Contributor
Contributor

Updates ? 

0 Likes
Message 6 of 12

lukaskohout
Advocate
Advocate

Separation Lines can be created only in floor plans and they are level specific.


Hitting Accepted Answer is a Community Contribution from me as well as from you.
======================================================================
0 Likes
Message 7 of 12

mathieu.josserand
Contributor
Contributor

True, so we can't generalize the process to an entire model...

0 Likes
Message 8 of 12

BenoitE&A
Collaborator
Collaborator

Creating a View is not so much a pain though.

What do you mean by "Generalizing the process to the entire model" ?


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 9 of 12

mathieu.josserand
Contributor
Contributor

Generalising the process to the whole model for me means being able to create all the spaces (active model) from the rooms (arch model linked).
To do this, you can use NewSpace function (https://www.revitapidocs.com/2020/ce49bd88-7d6b-b3ca-bd4c-497233718ffb.htm), requiring a Level, a Phase, and a UV point. This method works very well unless for neighbouring rooms (no walls to separate them, only a Separation Line).
In this case, this separation line is not detected by the Active model, and a single Space is generated for these two rooms.
So, to remedy this, we can collect all the Room Separation Lines, and transfer them to Space Separation Lines, this is the biggest problem here:
According to api , (https://www.revitapidocs.com/2020/e95433bf-3440-50e3-c9d0-c5559fbb0aff.htm) to create, a new space separation line, the function requires the sketch plane, the curves, and the associated view.
To answer @BenoitE&A's question: "Why would you need a view? This line exists in ALL "correct" views, same as a space/room..."voi"Here is "here is my answer:
I have just tested the process that draws all space separations lines from rooms'. The process works, all my lines are drawn.
But, all the drawn lines are associated to the view entered in parameter (here doc.ActiveView (Lvl 0) for me).
Ok, all my problems are solved for Lvl 0 (ActiveView) but for all the other levels, the drawn lines are not detected because they do not belong to the view associated to my level 1.
And you cannot change your view in your process if that is not the user's View

This is my reasoning, I hope it will be understandable.
I will continue to search and I will share, if I find a solution.

0 Likes
Message 10 of 12

BenoitE&A
Collaborator
Collaborator

The process you describe is right. And it works fine, at least for us 😉

You are just missing the Elevation criteria for the Separators. Maybe you should check the level in which your Separators are based, and find a view based on this level.


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 11 of 12

mathieu.josserand
Contributor
Contributor

I finally found a solution... FINALLY! 
Indeed, you need to set a View associated to the right current level of the Room Separation Line, for each iteration.

Hope it helps you guys (C#) :

FilteredElementCollector basePointsActive =
    new FilteredElementCollector(m_doc).OfCategory(BuiltInCategory.OST_ProjectBasePoint);
FilteredElementCollector basePointsArchi =
    new FilteredElementCollector(m_archDoc).OfCategory(BuiltInCategory.OST_ProjectBasePoint);

BasePoint basePointActive = basePointsActive.FirstElement() as BasePoint;
BasePoint basePointArchi = basePointsArchi.FirstElement() as BasePoint;

double diffX = basePointActive.Position.X - basePointArchi.Position.X;
double diffY = basePointActive.Position.Y - basePointArchi.Position.Y;
double diffZ = basePointActive.Position.Z - basePointArchi.Position.Z;

FilteredElementCollector lineColl = new FilteredElementCollector(m_archDoc);
lineColl.OfCategory(BuiltInCategory.OST_RoomSeparationLines);

using (Transaction t = new Transaction(m_doc))
{
    t.Start("Add Space Shared Parameters");
    foreach (Element e in lineColl)
    {
        try
        {
            ModelLine l = e as ModelLine;
            LocationCurve loc = l.Location as LocationCurve;
            XYZ stPoint = new XYZ(
                loc.Curve.GetEndPoint(0).X + diffX,
                loc.Curve.GetEndPoint(0).Y + diffY,
                loc.Curve.GetEndPoint(0).Z + diffZ); // Arch Model to Active Model Coordinates (= Transform Attribute)
            XYZ enPoint = new XYZ(
                loc.Curve.GetEndPoint(1).X + diffX,
                loc.Curve.GetEndPoint(1).Y + diffY,
                loc.Curve.GetEndPoint(1).Z + diffZ);

            Level level = l.Document.GetElement(l.LevelId) as Level;
            string levelName = level.Name.ToString();

            FilteredElementCollector collLev = new FilteredElementCollector(m_doc);
            IList<Element> levels = collLev.OfClass(typeof(Level)).ToElements();

            foreach (Element lvl in levels)
            {
                if (lvl.Name == levelName)
                    level = lvl as Level; 
            }
            SketchPlane skP = SketchPlane.Create(m_doc, level.Id);

            Line line = Line.CreateBound(stPoint, enPoint);
            CurveArray cArray = new CurveArray();
            cArray.Append(line);

            FilteredElementCollector collView = new FilteredElementCollector(m_doc);
            IList<Element> views = collView.OfCategory(BuiltInCategory.OST_Views).ToElements();
            View lineView = null;
            foreach (Element view in views)
            {
                ViewPlan vp = view as ViewPlan;
                if (levelName == vp.GenLevel.Name)
                {
                    lineView = view as View;
                    break;
                }
            }
            m_doc.Create.NewSpaceBoundaryLines(skP, cArray, lineView);

        }
        catch
        {
            //Catch Curves (TO do)
            continue;
        }

    }
    t.Commit();
}
Message 12 of 12

kmajor9QJR6
Explorer
Explorer

Would recommend doing a null check on the "GenLevel" property of the views before trying to use the name in a string comparison--this caused me some problems.
Also included below are snippets for setting the two document variables. This assumes the  macro is setup as an application macro and both the target document (where space separation lines are to be created) and the the source document (where room separation lines already exist) are open and the former is the active document. Replace the hard-coded string text based on file names for the specific project.

var m_doc = this.ActiveUIDocument.Document;
			var doc_Iter = this.Application.Documents.ForwardIterator();
			doc_Iter.MoveNext();
			
			while(!((Document)doc_Iter.Current).PathName.Contains("ALLORPORTIONOFFILENAMEHERE"))
			{
				doc_Iter.MoveNext();
			}
			
			
			
			Autodesk.Revit.DB.Document m_archDoc = doc_Iter.Current as Autodesk.Revit.DB.Document;


//NULL CHECK FOR GEN LEVEL NAME

new FilteredElementCollector(this.ActiveUIDocument.Document).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().Cast<View>().Where(q => q.ViewType == ViewType.FloorPlan && q.GenLevel != null).ToList()
			
0 Likes