Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Hi,
How do I call copy with base point via api.
Thanks & Regards
Sanjay Pandey(BIM[Revit] Developer)
Solved! Go to Solution.
Solved by Mustafa.Salaheldin. Go to Solution.
Something like this:
Selection selection = uidoc.Selection;
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
XYZ point1 = new XYZ(0, 0, 0);
XYZ point2 = new XYZ(0, 0, 0);
XYZ point3 = new XYZ(0, 0, 0);
point1 = selection.PickPoint("Please pick a base point.");
point2 = selection.PickPoint("Please pick a point to place elements");
point3 = point2.Subtract(point1);
t.Start();
ICollection<ElementId> pastedIds = ElementTransformUtils.CopyElements(doc, selectedIds, point3);
t.Commit();
The view must have a workplane set for the PickPoint to work. With a workplane set, this will work in plan views, elevation views, and even 3D views.
I have a group whose group origin i have changed. Now How do I find the center point of the group. because after changing the group origin to the top left the rotation of the group is not working properly.
I have a group whose group origin i have changed. Now How do I find the center point of the group.
Thanks & Regards
Sanjay Pandey(BIM[Revit] Developer)
Hi,
for the group's center point, why not get the bounding boxes of the members and then calculate it ?
Revitalizer
Hi,
Thanks for the suggestion.
How about getting the bounding box of the group itself and getting the center.
Thanks & Regards
Sanjay Pandey
Hi sanjayman,
I've already seen that you created another thread for the Group center point.
http://forums.autodesk.com/t5/revit-api/group-center-point/td-p/6379898
As far as I can see, there are about three types of Groups:
Each group consists of a list of members.
You can get the members' BoundingBoxes, this method needs a View parameter.
Depending on the kind of the group,use the View the Element resides in (Detail group) or null (for Model group).
May be that you need to use a valid View3D instead of null, in this case.
For the third case, I have no idea so far.
Once having the BoundinBoxXYZ for each Element in a group, get their minimum and maximum extends.
Calculate the center of the extends by dividing it by two...
(Remark: Groups can contain groups.)
That's all.
Revitalizer
Hi,
I am only dealing with Model Groups[no detail group attached nor any group within group]. After replying to you I tried to do :
1. got the bounding box of the group group.get_BoundingBox(activeview)
2. divide the max and min by two.
but results are quiet bad
Thanks & Regards
Sanjay Pandey(BIM[Revit] Developer)
Hi,
not the BoundingBox of the Group itself but those boxes of its members.
Get the member Elements (respectively their Ids) by Group.GetMemberIds().
Note that Groups can be embedded recursively, a Group's member could be another Group, since a Group is an Element itself.
For a Model group, I wouldn't use the ActiveView since the result will be view depending.
Revitalizer
Please try this and tell me the result:
#region Namespaces using System; using System.Text; using System.Linq; using System.Xml; using System.Reflection; using System.ComponentModel; using System.Collections; using System.Collections.Generic; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Forms; using System.IO; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Events; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.UI.Events; //using Autodesk.Revit.Collections; using Autodesk.Revit.Exceptions; using Autodesk.Revit.Utility; using RvtApplication = Autodesk.Revit.ApplicationServices.Application; using RvtDocument = Autodesk.Revit.DB.Document; #endregion namespace RevitAddinCS5 { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExtCmd : IExternalCommand { #region Cached Variables private static ExternalCommandData _cachedCmdData; public static UIApplication CachedUiApp { get { return _cachedCmdData.Application; } } public static RvtApplication CachedApp { get { return CachedUiApp.Application; } } public static RvtDocument CachedDoc { get { return CachedUiApp.ActiveUIDocument.Document; } } #endregion #region IExternalCommand Members public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet) { _cachedCmdData = cmdData; try { FilteredElementCollector collector = new FilteredElementCollector(CachedDoc); collector.OfCategory(BuiltInCategory.OST_IOSModelGroups).WhereElementIsNotElementType(); List<Element> els = collector.Cast<Element>().ToList(); Element el = els.First(); Group g = el as Group; BoundingBoxXYZ box = g.get_BoundingBox(CachedDoc.ActiveView); XYZ p1 = box.Max.Add(box.Min) / 2; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); using (Transaction t = new Transaction(CachedDoc, "Revit")) { t.Start(); ElementTransformUtils.RotateElement(CachedDoc, el.Id, ln, Math.PI / 2); t.Commit(); } return Result.Succeeded; } catch (Exception ex) { msg = ex.ToString(); return Result.Failed; } } #endregion } }
@Anonymous wrote:Hi,
I am only dealing with Model Groups[no detail group attached nor any group within group]. After replying to you I tried to do :
1. got the bounding box of the group group.get_BoundingBox(activeview)
2. divide the max and min by two.
but results are quiet bad
Thanks & Regards
Sanjay Pandey(BIM[Revit] Developer)
For step 2, don't you mean:
min + (max - min)/2 ?
Please try this and tell me the result:
#region Namespaces using System; using System.Text; using System.Linq; using System.Xml; using System.Reflection; using System.ComponentModel; using System.Collections; using System.Collections.Generic; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Forms; using System.IO; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Events; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.UI.Events; //using Autodesk.Revit.Collections; using Autodesk.Revit.Exceptions; using Autodesk.Revit.Utility; using RvtApplication = Autodesk.Revit.ApplicationServices.Application; using RvtDocument = Autodesk.Revit.DB.Document; #endregion namespace RevitAddinCS5 { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExtCmd : IExternalCommand { #region Cached Variables private static ExternalCommandData _cachedCmdData; public static UIApplication CachedUiApp { get { return _cachedCmdData.Application; } } public static RvtApplication CachedApp { get { return CachedUiApp.Application; } } public static RvtDocument CachedDoc { get { return CachedUiApp.ActiveUIDocument.Document; } } #endregion #region IExternalCommand Members public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet) { _cachedCmdData = cmdData; try { FilteredElementCollector collector = new FilteredElementCollector(CachedDoc); collector.OfCategory(BuiltInCategory.OST_IOSModelGroups).WhereElementIsNotElementType(); List<Element> els = collector.Cast<Element>().ToList(); Element el = els.First(); Group g = el as Group; BoundingBoxXYZ box = g.get_BoundingBox(CachedDoc.ActiveView); XYZ p1 = box.Max.Add(box.Min) / 2; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); using (Transaction t = new Transaction(CachedDoc, "Revit")) { t.Start(); ElementTransformUtils.RotateElement(CachedDoc, el.Id, ln, Math.PI / 2); t.Commit(); } return Result.Succeeded; } catch (Exception ex) { msg = ex.ToString(); return Result.Failed; } } #endregion } }
Dear Mustafa,
I don;t know but I see a bonding getting developed here. Thanks for spending time for me. Can I have your emailid?
I tried your code and you can see the results in the image below.
You have to adjust the angle in the code because it is already set to 90 degree (Math.Pi / 2).
I've modified the code to make you able to control the value of the angle.
If this reply satisfies your need please don't forget to mark it as solution.
This code will rotate the group by 180 dgree now.
#region Namespaces using System; using System.Text; using System.Linq; using System.Xml; using System.Reflection; using System.ComponentModel; using System.Collections; using System.Collections.Generic; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Forms; using System.IO; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Events; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.UI.Events; //using Autodesk.Revit.Collections; using Autodesk.Revit.Exceptions; using Autodesk.Revit.Utility; using RvtApplication = Autodesk.Revit.ApplicationServices.Application; using RvtDocument = Autodesk.Revit.DB.Document; #endregion namespace RevitAddinCS5 { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExtCmd : IExternalCommand { #region Cached Variables private static ExternalCommandData _cachedCmdData; public static UIApplication CachedUiApp { get { return _cachedCmdData.Application; } } public static RvtApplication CachedApp { get { return CachedUiApp.Application; } } public static RvtDocument CachedDoc { get { return CachedUiApp.ActiveUIDocument.Document; } } #endregion #region IExternalCommand Members public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet) { _cachedCmdData = cmdData; try { FilteredElementCollector collector = new FilteredElementCollector(CachedDoc); collector.OfCategory(BuiltInCategory.OST_IOSModelGroups).WhereElementIsNotElementType(); List<Element> els = collector.Cast<Element>().ToList(); Element el = els.First(); Group g = el as Group; BoundingBoxXYZ box = g.get_BoundingBox(CachedDoc.ActiveView); XYZ p1 = box.Max.Add(box.Min) / 2; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); using (Transaction t = new Transaction(CachedDoc, "Revit")) { t.Start(); //control the rotation angle from here. double RotationAngle = Math.PI; ElementTransformUtils.RotateElement(CachedDoc, el.Id, ln, RotationAngle); t.Commit(); } return Result.Succeeded; } catch (Exception ex) { msg = ex.ToString(); return Result.Failed; } } #endregion } }
don;t know what's going wrong;
my code with your help goes like this:
trans.Start("sun");
XYZ targetPoint = Command.uidoc.Selection.PickPoint("Please pick a point.");
Group dt = uidoc.Document.Create.PlaceGroup(targetPoint, ty);
BoundingBoxXYZ box1 = dt.get_BoundingBox(Command.doc.ActiveView);
XYZ p1 = box1.Max.Add(box1.Min) / 2;
XYZ p2 = p1.Add(new XYZ(0, 0, 1));
Line ln = Line.CreateBound(p1, p2);
ElementTransformUtils.RotateElement(Command.doc, dt.Id, ln, 180);
result:
Revit uses the radian measurments for angel so your code should be:
trans.Start("sun"); XYZ targetPoint = Command.uidoc.Selection.PickPoint("Please pick a point."); Group dt = uidoc.Document.Create.PlaceGroup(targetPoint, ty); BoundingBoxXYZ box1 = dt.get_BoundingBox(Command.doc.ActiveView); XYZ p1 = box1.Max.Add(box1.Min) / 2; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); // replace 180 with Math.Pi ElementTransformUtils.RotateElement(Command.doc, dt.Id, ln, Math.Pi);
To rotate around the arbitary point
trans.Start("sun"); XYZ targetPoint = Command.uidoc.Selection.PickPoint("Please pick a point."); Group dt = uidoc.Document.Create.PlaceGroup(targetPoint, ty); BoundingBoxXYZ box1 = dt.get_BoundingBox(Command.doc.ActiveView); XYZ p1 = targetPoint ; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); ElementTransformUtils.RotateElement(Command.doc, dt.Id, ln, 180);
sorry but the revised code did nothing. In fact it even didn;t got rotated
Sorry it was my mistake
trans.Start("sun"); XYZ targetPoint = Command.uidoc.Selection.PickPoint("Please pick a point."); Group dt = uidoc.Document.Create.PlaceGroup(targetPoint, ty); BoundingBoxXYZ box1 = dt.get_BoundingBox(Command.doc.ActiveView); XYZ p1 = targetPoint ; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); ElementTransformUtils.RotateElement(Command.doc, dt.Id, ln, Math.PI);
I forget to repalce the 180 by PI
Dear Mustafa,
Thanks for you time and help. Your code did the trick only with a very very little minor change.
trans.Start("sun"); XYZ targetPoint = Command.uidoc.Selection.PickPoint("Please pick a point."); Group dt = uidoc.Document.Create.PlaceGroup(targetPoint, ty); BoundingBoxXYZ box1 = dt.get_BoundingBox(Command.doc.ActiveView); XYZ p1 = box1.Max.Add(box1.Min) / 2; XYZ p2 = p1.Add(new XYZ(0, 0, 1)); Line ln = Line.CreateBound(p1, p2); // replace 180 with Math.Pi //ElementTransformUtils.RotateElement(Command.doc, dt.Id, ln, Math.Pi);
//Replaced above line with
ElementTransformUtils.RotateElement(Command.doc, dt.Id, ln, rotation defined bu user * Math.PI / 180);
Again a big thank for you. Kudos to you and I will accept your solution as accepted answer. But I want to carry it forward. I am posting a new query in the forum. I which I will be needing your expert suggestion.
Thanks & Regards
Sanjay Pandey(BIM[Revit] Developer)
Can't find what you're looking for? Ask the community or share your knowledge.