NWC export for different project location

I am looking to export .nwc for all project locations possible.
The code runs with no errors but the .nwc is not exported.
Please do share your view on this code.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import System

import math

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument


# Get the current project location
project_location = doc.ActiveProjectLocation

# Get the new location list from input
new_location_list = UnwrapElement(IN[0])

# Initialize a list to store the exported file paths
exported_files = []

#coll = FilteredElementCollector(doc).OfClass(ProjectLocation)

output = []
path = IN[1]
name = IN[2]
view = UnwrapElement(IN[3])
ChooseCoordinates = IN[5]
Linksbool = IN[6]
i=0

# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

for new_location in new_location_list:
	name1 = name[i]
	#Set the new project position
	project_location.SetProjectPosition(XYZ.Zero, new_location_list[i])
	location=new_location_list[i]
	#path = Autodesk.Revit.DB.FilePath(pathName)
	Options = Autodesk.Revit.DB.NavisworksExportOptions()
	Options.ExportScope = NavisworksExportScope.View
	Options.ViewId = view.Id
	Options.ExportLinks = Linksbool
	Options.Coordinates = ChooseCoordinates
	Options.ExportParts = False
	Options.ExportElementIds = True
	Options.ConvertElementProperties = True
	Options.ExportRoomAsAttribute = True
	Options.ExportRoomGeometry = True
	Options.ExportUrls = True
	Options.DivideFileIntoLevels = False
	Options.FindMissingMaterials = True
	doc.Export(path, name1, Options)
	i += 1
	exported_files.append(name1)
#TransactionManager.Instance.EnsureInTransaction(doc)    
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
# OUT = dir(Autodesk.Revit.DB.NavisworksExportOptions.ExportScope)
OUT = exported_files

Offhand it looks fine. Few things to check:

  1. Do you have write access to the path, and is it valid?
  2. If you append the current location to the list of locations, so you get a single export?
  3. If you use an XYZ for the location of (1,1,1) do you get results?
  4. If you output one item from the new_locations list, what is the object type?

Thanks @jacob.small for asap reply

1.I have write access to the path.
2.I am able to export without a for loop.(No issue for change of location)
3.Yes I do get results
4. new_location_list outputs DB.ProjectPosition

I believe the problem to be at doc.Export and TransactionManager.
If I run the script without β€œfor” loop for a single position it works perfectly

Ah! Yes you need to put the transaction inside the for loop. :slight_smile:

Yupp tried that as well no errors, no output

Got the solution you can refer the code below.
Issue was just due to Transaction.
Thank you @jacob.small

1 Like