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.
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
Solved by FAIR59. Go to Solution.
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
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(); }
@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.
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);
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!
Thank you for the solution, Fair59!
Edited and published on the blog for future reference:
Cheers,
Jeremy