1

in Revit, I have selected views (selvpsElements) that I want to align with a primary view (primaryCenter). I have the primary view center shown below:

primaryCenter = [<Autodesk.Revit.DB.XYZ object at 0x00000000000010D9 [(-1.785047418, 0.064021364, 0.000000000)]>]

This is generated with the GetBoxCenter() method applied to a particular Viewport

Then the selected views to align with the primary view are below

selvpsElements = [<Autodesk.Revit.DB.Viewport object at 0x00000000000010D6 [Autodesk.Revit.DB.Viewport]>, <Autodesk.Revit.DB.Viewport object at 0x00000000000010D7 [Autodesk.Revit.DB.Viewport]>, <Autodesk.Revit.DB.Viewport object at 0x00000000000010D8 [Autodesk.Revit.DB.Viewport]>]

I have tried

        for t in selvpsElements:
            t.SetBoxCenter(primaryCenter)

But its not working. Do I need to convert the primaryCenter to XYZ with .ToXyz()? Any help would really be appreciated!

EDIT:

This information is generated via the following:

#Get all viewports in Document
viewPorts = list(DB.FilteredElementCollector(doc).OfClass(Viewport))


#Get all Views on sheets, their Name, Sheet Number and Box Outline
for vp in viewPorts:
    sheet = doc.GetElement(vp.SheetId)
    view = doc.GetElement(vp.ViewId)
    viewPortList.append([sheet.SheetNumber, view.ViewName, vp])

#Sort the list
lbxViewsSorted = sorted(viewPortList, key=lambda x: x[0])

#create lists for WPF ListBox and comboBox
for vp in lbxViewsSorted:
    colViews.append(vp[0] + " , " + vp[1])
    colPrimary.append(vp[0] + " , " + vp[1])

Then using pyrevit forms.WPFWindow with a listbox (colViews) and combobox (colPrimary) selection by user (lbxViews and cmbPrimary) there is a function (alignviews) attached to a button to do the below:

    def alignviews(self, sender, args):
        selvpviews = []
        selvpsublist = []
        selvpsElements = []
        primaryElement = []
        primaryOutline = []
        primaryCenter = []
        selectedOutline = []
        selectedCenter = []
        primaryXYZ = []

# get selected Views to be aligned
        selviews = [vps for vps in self.lbxViews.SelectedItems]
        for vs in selviews:
            selvpviews.append(vs.split(" , "))
        for vp in selvpviews:
            selvpsublist.append(vp[1::])

# flatten selected Views
        selvps = [item for sublist in selvpsublist for item in sublist]

# match selected Views with all Viewports, create new list
        selvpsmatches = set([item[1] for item in lbxViewsSorted]).intersection(selvps)
        selviewPorts = [view for view in lbxViewsSorted if view[1] in selvpsmatches]
        for el in selviewPorts:
          selvpsElements.append(el[2]) 

# get primary View to align with
        primview = (self.cmbPrimary.SelectedItem.split(" , "))
        primvpmatch = set([item[1] for item in lbxViewsSorted]).intersection(primview[1])
        primviewPort = [view for view in lbxViewsSorted if view[1] in primview]
        primaryElement = [i[2] for i in primviewPort]

# get primary viewport Center and Outline
        for i in primaryElement:
            vbox = i.GetBoxOutline()
            vcenter = i.GetBoxCenter()
            primaryOutline.append(vbox)
            primaryCenter.append(vcenter)

# set Viewports centers to primary views center
        for t in selvpsElements:
            t.SetBoxCenter(primaryCenter[0])

# init ui
ui = script.load_ui(MyWindow(), 'ui.xaml')
# show modal or nonmodal
ui.show_dialog()

The application works just fine just want to align selected viewport centers with primary viewport center. Once I do that I intend to provide a selection to align "Top Left" etc.. with the below. But that's for another day

cmbAlignType = ["Top Left", "Top Right", "Center", "Bottom Left", "Bottom Right"]
Simon Palmer
  • 384
  • 1
  • 2
  • 13
  • Seems like `primaryCenter` is a list object. You need to grab the `DB.XYZ` object inside the list `primaryCenter[0]` – Ehsan Iran-Nejad Aug 17 '20 at 21:21
  • 1
    @EhsanIran-Nejad I have imported from pyrevit import revit, DB and from Autodesk.Revit.DB import * but how do you actually get that DB.XYZ in python? particular this use case is outside of dynamo? BTW thank you for all your efforts with pyRevit - an invaluable platform for the global AEC industry – Simon Palmer Aug 18 '20 at 19:15

1 Answers1

0

From a first glance it looks like primaryCenter is a list, so you should be calling t.SetBoxCenter(primaryCenter[0]) - but without more code (or the error youre getting) its a little difficult to debug.

Post some more code if you would like us to take a closer look!

Callum
  • 578
  • 3
  • 8