Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy with base point

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
Anonymous
1730 Views, 18 Replies

Copy with base point

Hi,

 

How do I call copy with base point via api.

 

Thanks & Regards

Sanjay Pandey(BIM[Revit] Developer)

18 REPLIES 18
Message 2 of 19
stever66
in reply to: Anonymous

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.

 

 

Message 3 of 19
Mustafa.Salaheldin
in reply to: Anonymous

I can't understand the question, can you clarify more please?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 4 of 19
Anonymous
in reply to: Mustafa.Salaheldin

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)

Message 5 of 19
Revitalizer
in reply to: Anonymous

Hi,

 

for the group's center point, why not get the bounding boxes of the members and then calculate it ?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 19
Anonymous
in reply to: Revitalizer

Hi,

 

Thanks for the suggestion.

 

How about getting the bounding box of the group itself and getting the center.

 

Thanks & Regards

Sanjay Pandey

Message 7 of 19
Revitalizer
in reply to: Anonymous

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:

 

  1. Model groups
  2. Detail groups
  3. Model groups with attached Detail 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

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 8 of 19
Anonymous
in reply to: 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 badSmiley Frustrated

 

Thanks & Regards

Sanjay Pandey(BIM[Revit] Developer)

Message 9 of 19
Revitalizer
in reply to: Anonymous

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




Rudolf Honke
Software Developer
Mensch und Maschine





Message 10 of 19
Mustafa.Salaheldin
in reply to: Anonymous

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
    }
}

¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 11 of 19
stever66
in reply to: Anonymous


@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 badSmiley Frustrated

 

Thanks & Regards

Sanjay Pandey(BIM[Revit] Developer)


For step 2, don't you mean:

 

min + (max - min)/2  ?

 

 

Message 12 of 19

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
    }
}

¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 13 of 19
Anonymous
in reply to: Mustafa.Salaheldin

Dear Mustafa,

I don;t know but I see a bonding getting developed here.Smiley Wink 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.

mustafa.png

 

 

 

 

Message 14 of 19
Mustafa.Salaheldin
in reply to: Anonymous

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
    }
}

 

 

 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 15 of 19
Anonymous
in reply to: Mustafa.Salaheldin

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:

 

mustafa1.png

 

 

 

 

Message 16 of 19
Mustafa.Salaheldin
in reply to: Anonymous

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);

 

 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 17 of 19
Anonymous
in reply to: Mustafa.Salaheldin

sorry but the revised code did nothing. In fact it even didn;t got rotated

Message 18 of 19
Mustafa.Salaheldin
in reply to: Anonymous

Sorry it was my mistake Smiley Sad

 

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 Smiley Very Happy

 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 19 of 19
Anonymous
in reply to: Mustafa.Salaheldin

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.

Post to forums  

Autodesk Design & Make Report