by Jaime Rosales (@afrojme)
I think it has been quite some time since my last post, but definitely it will be something that would not happen again. I’ve been all over the place presenting and evangelizing about Forge, View and Data API and our upcoming DevCon in San Francisco in the month of the Rainy Summer of June.
The conference is intended for developers, entrepreneurs or technology enthusiasts, who are interested in using Autodesk 'cloud' technologies to disrupt the AEC and Manufacturing industries. Interested? Wait no more click the image below.
Early bird registration is due to end on April 15th, so you don't have much time to buy your ticket at the low cost of $499. If you're a student, you can come for FREE- just sign up for a student ticket using a .edu email address.We're still working on the agenda. Visit this link for a list of the classes we currently have planned.
----------------------------------------------------------------------------------
Back to Revit, This week I had the chance to work in a Revit API forum question by community contributor erikeriksson5686 about how to Move the Gridlines using DatumPlane API Method. Forum question here.
Question:So I've been asked to synchronize grid leader locations (along the grid line) between files.I thought that this would be easy using the new API for DatumPlane, BUT i was wrong. The property I want to change in the Leader is the Anchor, but that property is readonly and the documentation says: " This is a read-only property, for the this point gets always computed based on various properties of the annotation element. "
Well for the grid element there are no annotation elements attached to the Leader, right?
Am i missing something? Thanks!
After some back and fort with Revit Engineering one of their own, Lily Li, got back to me with a macro sample on how to achieve the desired workflow. It was so nice of her.
Answer:Hi Erik, Revit Engineering got back to me with a solution for moving the grid. Here is what they wrote:
"The new API for DatumPlane works and the data should be computed by users according to their requirements. Here is a Macro as a sample showing how to get from A to B. Please open the file and run the ‘SynGridLeaders’, it will get the following result.
After running the Macro, here is the result --------->
The Anchor property of the leader is read-only as it is computed by the Elbow and End properties set by the users. The new leader should also be set via SetLeader() method to get it work."
You can find the Revit File here
And the code for the Macro is the following:
{
FilteredElementCollector collector = new FilteredElementCollector(Document);
collector.OfClass(typeof(Grid));
IEnumerable<Grid> grids = collector.Cast<Grid>().OrderBy<Grid, int>(vp => vp.Id.IntegerValue);
View view = Document.ActiveView;
if(!(view is ViewPlan))
{
return;
}
using (Transaction trans = new Transaction(Document, "Set leader"))
{
Leader leaderBase = null;
trans.Start();
try
{
foreach(Grid grid in grids)
{
// The Grid 1 is the baseline
if(grid.Name == "1")
{
leaderBase = grid.GetLeader(DatumEnds.End1, view);
continue;
}
else
{
Leader leader = grid.GetLeader(DatumEnds.End1, view);
if(leader != null)
{
XYZ anchor = leader.Anchor;
XYZ end = leader.End;
XYZ elbow = leader.Elbow;
XYZ newEnd;
XYZ newElbow;
double distY = leaderBase.Elbow.Y - leaderBase.End.Y;
double distElbowX = leaderBase.Elbow.X - leaderBase.End.X;
double distEndX = leaderBase.End.X - leader.End.X;
newEnd = new XYZ(leader.End.X + distEndX, leader.End.Y, leader.End.Z);
newElbow = new XYZ(leader.End.X + distEndX + distElbowX, leader.End.Y +distY, leader.Elbow.Z);
leader.Elbow = newElbow;
leader.End = newEnd;
grid.SetLeader(DatumEnds.End1, view, leader);
}
}
}
if(Document.IsModified)
trans.Commit();
}
catch(Exception ex)
{
trans.RollBack();
}
}
}
The file attached is saved by R2016R2 version. If running the macro the grid leaders don’t change, please click ‘edit’ button of the macro, compile it then run it again. ( Remember to enable the macro when opening the file.)
Check it out and let me know, hope this solves your question
Thank you again for your patience and collaboration.
--------------------------------------------------
I’m still waiting for Erik to get back to me, but after testing the macro, I’m sure it will be something that you guys can benefit from. Cheers and until next time.