Hi,
I’m using python to place a family instance on a point and trying to get its bounding box using get_BoundingBox(None) method. But BoundingBox for the Instance returns Null (as shown in A). Then I tried to use the same family instance to create bounding box in separate python script using same boundingbox method it works
what am I doing wrong in Script A?
here is my code
Version:0.9 StartHTML:00000097 EndHTML:00004693 StartFragment:00000199 EndFragment:00004655 import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitApi')
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit ,Autodesk
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
from math import *
from datetime import datetime
now = datetime.now()
import System
from System.Collections.Generic import *
from System.IO import Directory, Path
famType = UnwrapElement(IN[0])
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
famInstance = doc.Create.NewFamilyInstance(XYZ(0,0,0) , famType , Structure.StructuralType.NonStructural)
bbox = famInstance.get_BoundingBox(None)
TransactionManager.Instance.TransactionTaskDone()
OUT = famInstance , bbox
The element was just created and the document has not yet been regenerated (this will happen after the TransactionTaskDone() method is executed). If you move your bbox variable outside of the transaction you should be able to get the bounding box.
Thanks for reply
I tried it still boundingbox returns null
If you want to have it all in a single script I think that you´ll have to use a revit Databse transaction, not the transaction manager
you´ll need to import
from Autodesk.Revit.DB import Transaction
and define
tran = Transaction(doc, ‘Name’)
and then use tran.Start() and tran.Commit() instead of transactionmanager.insureTransaction and TaskIsDone
2 Likes
it Worked!
thank you for helping me
Another solution to have to BoundingBox of a certain instance is by using the Element Class property .BoundingBox
What if he entered the get_BoundingBox before TransactionTaskDone? Could you please explain what exactly the difference between TransactionManager und Transaction from Database?
Thanks a lot!
Edit: I see that he had done at the beggining like that and output was not correct.
The Transaction Manager is sort of a layer over the revit transactions. Here´s a few more words about it that explain it better than I can:
The transaction manager is just a layer around the regular revit transactions that manages them for you. It’s preferable to use it instead of regular transactions because that way, if your script crashes before a transaction can be committed, the manager will make sure to finalize everything and do all the necessary cleanup. Otherwise you’ll end up with a stray open transaction, at least until revit’s built-in utilities can clean it up.
If you need to do any rollbacks, you can always open a sub…
I guess in this example you could have used TransactionManager.ForceCloseTransaction()
instead ot tran.commit(), but personally i never think about it
3 Likes
This is did not work for me