Duplicating PlanView and dependent views

Duplicating PlanView and dependent views

Anonymous
Not applicable
2,765 Views
1 Reply
Message 1 of 2

Duplicating PlanView and dependent views

Anonymous
Not applicable

HI guys,

I posted this same issue on Augi but im not sure they have the same talent as you guys 🙂

I am pretty new to programming and the revit API but i under stand the program and its user unterface very well.

 


What i am trying to make is a add-in that automates a process of creating views for loadbearing under views, the idea is that the addin create a duplicate of a selected view and applies a view template for the correct view settings then adds it to the selected sheet.

This is the process i want to follow:

a. User to select API tool in add-ins tab in revit,

b. Prompt user to select view <Host View>,
//Duplicate view
//rename view to “<Host View> Under & Over”
//apply view template “Profile Under & Over”
//move view type to “Profile Under & Over” or duplicate view type and rename to “Profile Under & Over”
//(if Host View has dependent views apply sequence b1 otherwise proceed to sequence c)
b1.

//Apply dependent views from Host View
//rename dependent views “<Host View> Under & Over - Part <1>”

c. Prompt user to select “sheet” or “create new sheet” in dialog,
if selected “sheet”
//move “<Host View> Under & Over” or if dependent “<Host View> Under & Over - Part <1>”centre to centre on sheet
if selected “create new sheet”
//create new sheet
//rename sheet to “<Host View>” or if dependent “<Host View> - Sheet <1>
//move “<Host View> Under & Over” or if dependent “<Host View> Under & Over - Part <1>”centre to centre on sheet

Now there are lots of steps between all the listed steps that im still learning to get the end resault. 

This is the start of what i have done with regards to the code to select the view:

 

using System;
using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class Lab1PlaceGroup : IExternalCommand
{
  public Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements)
  {
    //Get application and document objects
    UIApplication uiApp = commandData.Application;    
    Document doc = uiApp.ActiveUIDocument.Document;

    //Define a Reference object to accept the pick result.
    Reference pickedRef = null;    

    //Pick a view
    Selection sel = uiApp.ActiveUIDocument.Selection;
    pickedRef = sel.PickObject(ObjectType.Element, "Please select a view");
    Element elem = pickedRef.Element; 
    ViewPlan profileplan = elem as ViewPlan;

Now i am stuck here.. What i want to do next is duplicate the view but i am not sure how to apply duplicate () and how to check / apply that to dependent views, do i do this in a new class or can i do it in the current class?

Any help would be much appreciated

Thanks heaps
Dave

 

0 Likes
2,766 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Hi Dave,

 

I have simple solution that I use to duplicate the active view, hope this helps.

 

  public void DuplicarVista()
        {
            UIDocument uidoc = this.ActiveUIDocument;
            Document doc = uidoc.Document;
        
            View pickedRef = null;
            
            pickedRef= uidoc.ActiveView;
            
            int nduplicates = 5;
                    
            using (Transaction t = new Transaction(doc,"Set workset"))
            {
                       t.Start();
                       
                    for (int i = 1; i < nduplicates; i++) {
                        
                        //Check if view can be duplicated
                           if (pickedRef.CanViewBeDuplicated(ViewDuplicateOption.AsDependent))
                               pickedRef.Duplicate(ViewDuplicateOption.AsDependent);
                    }


                       t.Commit();
            }
        }

 

Andrei Bejenaru