View of NewGroup Duplicated Elements

I already mentioned that you can work around the lack of programmatic creation possibilities for some element types by grouping existing ones, creating new instances of that group, and then ungrouping it again.

One question that came up in that context is what view the new group appears in:

Question: I am using code like this to duplicate one or more elements:


  void CreateGroup(
    Document doc,
    ICollection<ElementId> ids,
    XYZ offset )
  {
    Group group = doc.Create.NewGroup( ids );
 
    LocationPoint location = group.Location
      as LocationPoint;
 
    XYZ p = location.Point + offset;
 
    Group newGroup = doc.Create.PlaceGroup(
      p, group.GroupType );
 
    group.UngroupMembers();
  }

However, under certain circumstances, the new group is not placed in the same view as the old one.

Is there any way to specify the target view?

Answer: Sorry, there is currently no direct API access to control the view used when placing a group.

The active view will be used to place the new group, so all you have to do is ensure that the target view really is activated.

To be on the really safe side, you might want to try closing all other views to absolutely force the open one to be used.

The Revit API calls should in theory obviously not be influenced by any of the user interface settings, but there may still be some obsolete remnants of such dependencies left.


Comments

7 responses to “View of NewGroup Duplicated Elements”

  1. Hi JEREMY TAMMIK
    About target view with duplicated objects. I just figured out another way recently.
    days ago I am trying drawing windows/doors legend component into LegendView with it’s own parameter value,dimensions with Width / Height / SillHeight,and some Lines.
    I found this page and it’s big help to me,thanks.
    http://thebuildingcoder.typepad.com/blog/2010/05/duplicate-legend-component.html
    after working I faced some problem.
    1.group duplicate has bad performance to element
    2.problem just same as this topic talk about
    about problem 1 ,after using ElementTransformUtils.CopyElement instead Create.PlaceGroup,for now it’s has acceptable performance
    and problem 2,no matter CopyElement or PlaceGroup,that’s all can’t assign target view just like Create.NewDetailCurve do so.
    So I had a concept below
    Create a empty LegendView with ONE LegendComponent,and this VIEW just used to be “Locating”
    reference pic http://www.flickr.com/photos/82824965@N04/7588337638/in/photostream
    in this sample pic I named the prepared view to “positionLegend”
    “DoorWindow Page1” and “DoorWindow Page2” are created by programmatic.
    this is how to work:
    1.function clicked , Pick LegendComponent with API:PickObject in “positionLegend”, then use API:pickedElem.get_Geometry(new Options()) to fetch Origin coordinate,that’s important because it can let me drawing DetailLine in the right position
    2.duplicating LegendView with ViewDuplicateOption.WithDetailing,at this time I determine how much page want to create,for this sample I want drawing six componet each page,and 8 component want to listed:
    int neededPage = (unionFamilies.Count() / pageCnt) + (((unionFamilies.Count() % pageCnt) > 0) ? 1 : 0);
    manipulateViews = new Autodesk.Revit.DB.View[neededPage];
    3.in LegendComponent creating process,int the loop I filled some condition to fetch working view and it’s own Element(the duplicated LegendComponent):
    int validCnt = 0;
    Element positionElem = null;
    for (int i = 0; i < unionFamilies.Count(); i++)
    {
    if ((validCnt % pageCnt) == 0)
    {
    if (positionElem != null)
    m_Document.Delete(positionElem); //new page,delete it
    positionElem = GetPositionElem(manipulateViews[viewIndex]);
    legendView = manipulateViews[viewIndex++];
    }
    }
    private Element GetPositionElem(Autodesk.Revit.DB.View view)
    {
    FilteredElementCollector viewCollector = new FilteredElementCollector(m_Document, view.Id);
    return viewCollector.OfCategory(BuiltInCategory.OST_LegendComponents).ToElements().ElementAt(0);
    //need some error handle of course
    }
    4.everyone are set. starting to CopyElement and drawing DetailLine
    newSets = ElementTransformUtils.CopyElement(m_Document, positionElem.Id, dupObjPoint);
    for now that’s working great to me.
    In this concept,maybe that’s a way to help how specified target view,just Finding “Locating Object” if you CAN.

  2. Hi Jeremy, You mention closing all non-active (hidden) views. I understood this was not possible, did I doze off? Dale

  3. Dear Dale,
    Well, if worst comes to worst, there is always this:
    http://thebuildingcoder.typepad.com/blog/2010/10/closing-the-active-document-and-why-not-to.html
    But, yes, as far as I know, you can close all views except the very last active one.
    Hmm, I wonder how that went?
    Cheers, Jeremy.

  4. Dear Rick,
    Wow, this sounds pretty interesting.
    Would you like to flesh it out to a full-blown guest blog post of its own?
    Thank you!
    Cheers, Jeremy.

  5. sure,but where is suitable.
    thanks.
    Rick

  6. Matt Taylor Avatar
    Matt Taylor

    Now you can use postcommand to close the last active document.

  7. Dear Matt,
    Cool!
    Thank you very much for pointing it out!
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading