urdiafa
September 18, 2018, 3:34am
1
I use Revit api “PostableCommand.DetailLine” to draw detailine,I want to retrieve the newly created element, it described here:
The Revit SDK does not include any example of calling the new PromptForFamilyInstancePlacement method, which prompts the user to interactively and graphically place instances of a specified family symbol, so I am creating a new Building Coder sample...
I try to convert it to python, but it doesn’t work,I got empty list, I think that I’m doing it wrong here
Any help would be much appreciated
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import *
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB.Events import *
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Collections.Generic import List
import System
from System.Windows.Forms import *
from System.Drawing import *
def OnDocumentChanged (sender, e):
collection = e.GetAddedElementIds()
#listId.Add(collection.ElementAt(0))
listId.AddRange(e.GetAddedElementIds())
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
listId = List[ElementId]()
TransactionManager.Instance.EnsureInTransaction(doc)
uiapp.Application.DocumentChanged += OnDocumentChanged
uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.DetailLine))
uiapp.Application.DocumentChanged -= OnDocumentChanged
TransactionManager.Instance.TransactionTaskDone()
OUT = listId
Hi @urdiafa , I know its an old post but were you able to find a solution to this?
Thanks
@Shambhavee @urdiafa ,
@Alien , @JacobSmall ,
I solved it finaly
[grafik]
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from System.Collections.Generic import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
elements = UnwrapElement(IN[0])
result = []
x = 1
…
is this a “event” for you to see that transaction happend?
Hi @Draxl_Andreas ,
Thanks for replying, I should have made myself clear
I was trying to look for a way to use Application Events in IronPython, which in this case is DocumentChange Event so I can implement it on other events. Let me know if you have a solution to this. I see a lot of examples in C# but as I’m fairly new to Revit API as well as coding so I’m currently able to execute Revit API through python.
I’m basically facing the same issue as in this article:
Hi all, I was able to get pretty far with this article, and the other info in this post. Has anyone had an issue where the “Open Model” dialog does not go away after Dynamo is done opening a cloud model? Dynamo still works and I can edit and rerun the script, but this dialog box locks up Revit itself. Has anyone run into this and solved it?
Thank you
[image]
and I’m trying to use DocumentOpening and DocumentOpened Events and see if suppressing these popups is possible.
I’m currently refering to this article to try and convert it to python:
Registering Events Using events is a two step process. First, you must have a function that will handle the event notification. This function must take two parameters, the first is an Object that denotes the "sender" of the event notification, the...
Thanks in Advance!
Shambhavee
Dynamo generally doesn’t work in a way which supports events to my knowledge.
It would probably be possible using an addin to load dynamo and run a script when an event is detected, but unless it’s an infrequent event it might cause issues or just slow the overall experience. At that point you’d likely just code the addin to run code after the event anyway.
Maybe look into pyRevit and its ‘hook’ system which enables scripts written in Python whilst detecting events.