I just arrived in Greece to give a Revit API training here during the next few days. I am in a pleasant place called Κηφισια (Kifissia), a suburb of Athens. I still need to get the training material set up properly...
Meanwhile, here are some notes on a different topic that I have been sitting on for a while:
Analysing the geometry of linked files is a challenge.
Certain basic information is actually easily accessible, as shown by the discussion on listing elements in linked documents and the CmdLinkedFileElements command.
More intense geometric analysis is not so easy, however. For instance, the FindReferencesWithContextByDirection method does not work on linked elements, which is understandable, and even the Intersect method will fail when fed geometry from linked elements.
The Revit 2012 API introduces the new Instance.GetTransform and Instance.GetTotalTransform methods which help handle this. These new methods provide the transform for a given Instance (which is the parent class for elements like family instances, link instances, and imported CAD content). GetTransform obtains the basic transform for the instance based on how the instance is placed. GetTotalTransform provides the transform modified with the true north transform, for instances like import instances.
The transform obtained can be applied to geometry elements using the new GeometryElement.GetTransformed method, which returns a copy of the geometry in the original element, transformed by the input coordinate transformation.
We had a look at this method recently to analyse getting the transformed family instance geometry and taking into account the transformation already built into the GetTransformed method.
Here is an explanation of some further aspects of this topic:
Question: I just don't understand why you say that geometry of the linked elements cannot be obtained. When walls, floors etc. are obtained from a linked document, it seems that I'm able to also obtain their geometry. Obviously it would not even be possible to call the Intersect method without obtaining the geometry first. The problem is that result is incorrect. Why is it that the linked geometry appears to be OK but still is somehow incomplete?
Answer: The geometry of the linked document is not necessarily the same as the geometry of the document itself. When you get the elements from the document, the geometry does not reflect (for example) the transformation of the linked document into the coordinate system of the host document. You can now get the transformation into the current project using the inherited method Instance.GetTransform on the link instance, and the transformed geometry of an element using GeometryElement.GetTransformed.
Hopefully, by applying the appropriate transform retrieved from the link instance to the target curve, e.g. using Curve.Transformed, you will then be able to correctly detect the intersection.
There are other potential differences regarding filters applied by the host document on the link which would not necessarily be reflected in the geometry of the document which is linked in. So when we say that the geometry of the link is not truly available this is accurate; the geometry you can find from the document in memory doesn't know how the host modifies the link.
Hello Jeremy Tammik
In here, I want to ask some question about the workset in Revit Architecture 2011.
when I create the workset in revit 2011, and I can set the specific workset visible or hidden in the view.
if I set the specific workset hidden, How can I get the element in the workset that is set to be hidden in the view.
I know that in revit 2012 ,it provide some relative method to resolve thie question, but in revit 2011 , I can't find them!
Therefor, I hope you can give me some example code which how to get the element in workset by RevitAPI 2011.
Best Regards
Ian
Posted by: Ian | July 26, 2011 at 11:38
Dear Ian,
These methods are new in Revit 2012, and are not available in Revit 2011.
Cheers, Jeremy.
Posted by: Jeremy Tammik | July 27, 2011 at 19:04
Thanks!
But I want to ask whether it exists other methods to find the element in workset in Revit 2011?
Posted by: Ian | July 28, 2011 at 09:44
Dear Ian,
Not as far as I know, sorry.
Cheers, Jeremy.
Posted by: Jeremy Tammik | August 09, 2011 at 04:26
Hello sir,
I am getting problem to get a real time view(like in case inserting door on a wall,after selecting the door, i am not getting the door view of moving along with the mouse cursor only getting cursor and if click on wall directly it will inserting.) before placing family inserting.
my code is like this:
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
..........
try
{
trans.Start();
Family family = null;
FamilySymbol symbol = null;
if (doc.LoadFamily(@h4, out family))
{
foreach (FamilySymbol s in family.Symbols)
{
symbol = s;
}
View view = uidoc.ActiveView;
Reference r = sel.PickObject(ObjectType.PointOnElement, "Select");
Element elem = doc.GetElement(r);
Wall wall = elem as Wall;
XYZ globalPoint = r.GlobalPoint;
XYZ levelPoint = new XYZ(10, 10, 1);
Wall wall = doc.GetElement(r) as Wall;
FamilyInstance instance = doc.Create.NewFamilyInstance(levelPoint, symbol, wall,level,StructuralType.NonStructural);
}
trans.Commit();
}
catch (Exception)
{
}
return Result.Succeeded;
}
Posted by: sachin | April 01, 2013 at 03:12
Hello Jeremy!
Could you give me please your advice in next problem:
I have a big model with several linked files. One of this link is reflected (mirrored)3 times in different directions.
I need to convert this model to other format, so I'm getting all links, their transformation and then convert each linked model (processDocument method):
foreach (RevitLinkInstance linkInstance in _doc.GetInstances(_app.Application, false))
{
Transform transform = linkInstance.GetTransform();
if (transform != null && transformCoordinates)
LinkedDocumentTranslationHelper.SetParentTransform(transform);
processDocument(linkInstance.GetDocument(...));
}
But I can't get reflections. Should I do reflection manually, if so - where can I get infor about reference plane for linked model with flag HasReflection = true.
Thank you,
Olga
Posted by: Olga | July 24, 2014 at 11:22
Dear Olga,
I cannot say off-hand, so I am asking the development team for you.
One other thing you might try, though, depending on what you are exporting, and how and why:
Use the custom exporter framework.
It includes data for linked files.
In fact, it includes everything that you see on the screen, honouring your view specific setting:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.1
Cheers, Jeremy.
Posted by: Jeremy Tammik | July 24, 2014 at 12:52
Hi Jeremy!
Thank you for advice.
I've found the reason of my problem. It was absolutely in other place.
I was wrong when thought, that property HasReflection means that current link HAS reflection, in fact it means that link IS reflection.
The reason for the disappearance of the mirror links was very easy - they just had the same name of file and were overwritten during storing.
Sorry to trouble you.
Thanks,
Olga
Posted by: Olga | July 28, 2014 at 11:09
Dear Olga,
Congratulations on solving it, and thank you for letting us know.
Cheers, Jeremy.
Posted by: Jeremy Tammik | July 28, 2014 at 11:16