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: 

Moving Detail Group only moves its LocationPoint, not detail items inside

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
htlcnn
876 Views, 6 Replies

Moving Detail Group only moves its LocationPoint, not detail items inside

I'm trying to move Detail Group element to a point that was picked. But only the Location of the group moves, not the detail items inside.

Here is my code to create detail lines, group them and move the created detail group.

 

import clr
clr.AddReference('RevitAPI')
import Autodesk
import System
import rpw
from rpw import doc, uidoc

class RebarFilter(Autodesk.Revit.UI.Selection.ISelectionFilter):
    def AllowElement(self, element):
        if element.Category.Name == 'Structural Rebar':
            return True
        else:
            return False

def pick_point():
    # Pick Point
    sp = rpw.db.Collector(of_class='SketchPlane', where=lambda x: x.OwnerViewId==doc.ActiveView.Id)[0]
    plane = sp.GetPlane()
    with rpw.db.Transaction('Set Work plane'):
        new_sp = rpw.DB.SketchPlane.Create(doc, plane)
        uidoc.ActiveView.SketchPlane = new_sp
    point = uidoc.Selection.PickPoint('Pick point to place rebar detail')
    return point

selection = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element,
                                           RebarFilter(), 'Pick Rebar')
rebar = rpw.db.Element.from_id(selection.ElementId).unwrap()

rb_curves = rebar.GetCenterlineCurves(False, False, False,
                            Autodesk.Revit.DB.Structure.MultiplanarOption.IncludeOnlyPlanarCurves,
                            0)
ca = rpw.DB.CurveArray()
for curve in rb_curves:
    ca.Append(curve)
with rpw.db.Transaction('Create Detail Line'):
    try:
        dca = doc.Create.NewDetailCurveArray(doc.ActiveView, ca)
        list_dc = System.Collections.Generic.List[Autodesk.Revit.DB.ElementId]()
        for dc in dca:
            list_dc.Add(dc.Id)
        g = doc.Create.NewGroup(list_dc)
        group_type = rpw.db.Element.from_id(g.GetTypeId()).unwrap()
        group_type.Name = str(rebar.Id)
    except Exception as e:
        rpw.ui.forms.Alert('Not in plane')

point = pick_point()
with rpw.db.Transaction('Move detail group'):
    Autodesk.Revit.DB.ElementTransformUtils.MoveElement(doc, g.Id, point)

How can I move detail curves inside detail group to picked point?

Thanks.

6 REPLIES 6
Message 2 of 7
jeremytammik
in reply to: htlcnn

The location point of the detail group insertion only affects the placement of the whole group "from the outside".

 

To move things within the detail group definition "on the inside", you probably have to enter the definition and maybe even redefine the detail group from scratch.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7
FAIR59
in reply to: htlcnn

to move the entire group:

 

			XYZ moveVector = new XYZ(5,0,0);
			using (Transaction t = new Transaction(doc, "MoveGroup"))
			{
				List<ElementId> toMove = new List<ElementId>(){group.Id};
				toMove.AddRange(group.GetMemberIds());
				t.Start();
				ElementTransformUtils.MoveElements(doc, toMove,moveVector);
				t.Commit();
			}
Message 4 of 7
htlcnn
in reply to: FAIR59

@FAIR59 I tried to MoveElements but the group stayed in the original position. One thing to note is that Group.GetElementIds() returns List of ElementIds so I use it directly without creating a new List and add all element ids.

 

@jeremytammik I tried moving detail curves before creating group. The curves moved but not to the point I picked. I'm wondering if the XYZ point I picked is the XYZ vector I need to pass into MoveElements in order to place curves there?

 

Also, I'm thinking about creating a new detail family with the curve I got from rebar, then load them back into the project and pick a point to place the family instance. I also want to add custom parameter to the detail item/group/family instance to store the rebar id so that I can update the detail later when the rebar geometry changes.

Which method do you think I should follow?

Thank you.

 

Message 5 of 7
FAIR59
in reply to: htlcnn

In the creation of the (extra) list, I added the group.Id. So I move the "group.Id" and the "member.Ids".

 

 

for the translation vector, old_point to picked point:

 

			XYZ locPoint = (group.Location as LocationPoint).Point;
			XYZ pickedPoint;
			moveVector = pickedPoint.Subtract(locPoint);
Message 6 of 7
htlcnn
in reply to: FAIR59

Apologize for my poor reading. That's exactly the solution.

About the way to manage detail item, I'll try to create family and add parameters. The question of this topic is answered.

Thank you very much!

Message 7 of 7
jeremytammik
in reply to: htlcnn

Thank you for the solution, Fair59!

 

Edited and published on the blog for future reference:

 

http://thebuildingcoder.typepad.com/blog/2017/08/forge-installed-version-move-group-filter-by-name.h...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community