gtalarico / revitpythonwrapper Goto Github PK
View Code? Open in Web Editor NEWPython Wrapper for the Revit API
Python Wrapper for the Revit API
>>> with rpw.db.Transaction():
... rpw.revit.active_view.override.projection_line(s0.Id, color=[255,0,255])
...
[ERROR] Error in Transaction Context: has rolled back.
[ERROR] <type 'exceptions.Exception'>:Category cannot be overridden.
Parameter name: categoryId
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "D:\Dropbox\Shared\dev\repos\revitpythonwrapper\revitpythonwrapper.lib\rpw\db\transaction.py", line 43, in __exit__
Exception: (Exception('Category cannot be overridden.\r\nParameter name: categoryId',), '')
# ^ Exception is printed, but not full traceback
Full traceback for this error should look like this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Dropbox\Shared\dev\repos\revitpythonwrapper\revitpythonwrapper.lib\rpw\db\view.py", line 286, in projection_line
File "D:\Dropbox\Shared\dev\repos\revitpythonwrapper\revitpythonwrapper.lib\rpw\db\view.py", line 240, in _set_overrides
File "D:\Dropbox\Shared\dev\repos\revitpythonwrapper\revitpythonwrapper.lib\rpw\db\view.py", line 252, in _set_category_overrides
Exception: Category cannot be overridden.
Parameter name: categoryId
Tried to use RevitPythonWrapper outside Revit Envroment:
`` import rpw
[WARNING] Revit Application handle could not be found
[WARNING] RevitAPI References could not be added`
Could i use RevitPythonWrapper outside Revit ?
Hello,
I want to add footer for my FlexForm but I couldn't find the sample on website. I just found footer for TaskDialog only.
Hope to see your respond. Thank you!
hi @gtalarico ,
first off thank for the awesome gui wrappers. (-;
I use them quite a bit. Today is the first time I needed
select_file and it seems to me that there might be a typo
in the example code on readthedocs for the select_file:
>>> from rpw.ui.forms import select_file
>>> filepath = select_file('Revit File ('*.rvt)|*.rvt'))
File "<stdin>", line 1
filepath = select_file('Revit File ('*.rvt)|*.rvt'))
^
SyntaxError: unexpected token '.'
So I thought, oh well I do a quick PR with the
(what I thought might be the ) fixed example which runs:
filepath = select_file('Revit File (*.rvt)|*.rvt)')
but when the file dialog pops up with the preset *.rvt filter, it seems like
everything except for directories is filtered away, even rvt. If I provide
the path as a string into this dialog, then filepath is considered not defined.
If I choose to not use the filter the dialog works as expected for all file
types, but obviously no filtering.
(I ran it in Revit 2017.2.2 in RevitPythonShell, rpw version: 1.7.4)
The following error occurred when I added the following statement:
The import sys
Sys. Path. Append (IN [0])
The import RPW
Col = RPW. Db. The Collector (of_category = 'OST_Levels', is_not_type = True)
OUT = col elements
RPW. UI. Forms. SelectFromList (" bm ", OUT)
The following error :警告:IronPythonEvaluator.EvaluateIronPythonScript 操作失败。
Traceback (most recent call last):
File "", line 16, in
File "C:\Users\Administrator\AppData\Roaming\Dynamo\Dynamo Revit\2.2\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\forms\quickform.py", line 35, in SelectFromList
File "C:\Users\Administrator\AppData\Roaming\Dynamo\Dynamo Revit\2.2\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\forms\flexform.py", line 58, in init
AttributeError: 'module' object has no attribute 'LoadComponent'
Hi gtalarico,
I try to install RevitPythonWrapper Autocomplete to Visual Studio Code but it's not work.
My setting like this:
{
"python.pythonPath": "C:\Users\GIGA\AppData\Local\Programs\Python\Python38-32\python.exe"
"python.autoComplete.extraPaths": [
"D:\Python Code\Revit\ironpython-stubs-master\release\stubs.min",
"D:\Python Code\Revit\revitpythonwrapper-master\rpw"]
}
Hope to see your reply. Thank you!
Hi,
According to Selection docstrings. It is supposed to work :
>>> from rpw import ui
>>> selection = ui.Selection()
>>> selection[0]
FirstElement
But when I try, I got following error :
>>> import rpw
>>> sel = rpw.ui.Selection()
>>> sel
<rpw:Selection [count:1]>
>>> sel[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\FichiersLocauxRevit\revitpythonwrapper\revitpythonwrapper.lib\rpw\db\collection.py", line 176, in __getitem__
KeyError: 0
Repr is sometimes not clean and has unnecessary info.
Most rpw classes maintain the same name as the revit object, so expressing it is redundant.
<rpw:Element % Material [id:1919]>
rpw.db.Element is wrapping Revit Material class
% syntax is shown because wrapper name and wrapped Element name is different
If name is the same wrapper % class
syntax is omitted.
Furthermore custom repr was sometimes hard to read, so bracket are used instead of spaces.
Previously:
<rpw:Parameter % ..DB.Parameter | name:Name value:SomeValue type:string>
Becomes:
<rpw:Parameter [name:Name] [value:SomeName] [type:string]>
Dear gtalarico,
Can we display a sketch or a preview in the wrapper to help the user insert his imports?
if element is wrapped, something element.Pinned' will return it's correct value, however
element.Pinned = True` will not set it, because the Base wrapper does not implement a catch all setter.
The code was added, but commented because it was causing a crash
Hello,
I tried to used rpw.db.Parameter in my last script but I was unable to retrieve a suitable value as it was intend to be human readable.
Here is a case :
When you retrieve value from BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP storage type is ElementId which is not human readable. When you print it or pass in a str() function, it return a number or -1. In the script it is used to batch rename views, so I need a human readable value.
Do you find relevant to add a method display_value or alike in rpw.db.Parameter class ? If yes. Do you want me to send a pull request ?
select_file function always returns one file path even though It is possible to select multiple files in dialog when multiple = true. The reason is that function returns form.FileName
*1 regardless of multiple option when it should return form.FileNames
*2
*1 - https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filename(v=vs.110).aspx
*2 - https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filenames(v=vs.110).aspx
Proposed solution:
if form.ShowDialog() == Forms.DialogResult.OK:
if multiple:
return list(form.FileNames)
return form.FileName
@gtalarico I ended up defining the class below in the sphinx conf.py
that will handle all dot net imports:
# based on:
# http://blog.dowski.com/2008/07/31/customizing-the-python-import-system/
class DotNetImporter(object):
domain_modules = ['clr', 'System', 'Autodesk', 'Microsoft']
found_mods = dict()
def find_module(self, fullname, path=None):
if fullname in self.domain_modules:
return self
if path:
for p in path:
if p in self.domain_modules:
self.domain_modules.append(fullname)
return self
return None
def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
mod = imp.new_module(fullname)
mod.__loader__ = self
sys.modules[fullname] = mod
mod.__file__ = fullname
mod.__path__ = [fullname]
return mod
# add importer to the list
sys.meta_path.append(DotNetImporter())
I'm running sphinx on a mac to create the docs for pyRevit and is working well. I also had to define global __sphinx__
parameter to protect the module level code from execution.
<rpw:Parameter % ..DB.Parameter | name:Level value:3616>
could be:
<rpw:Parameter % ..DB.Parameter | name:Level value:3616 type:ElementId>
I downloaded the Zip. file and I am trying to add a string input box to a pyRevit command. After downloading the zip I unzipped the contents to this location: C:\Users\hazell\AppData\Roaming\pyRevit\pyRevit-v3beta\modules\rpw
added this code to my pyRevit command:
import sys
sys.path.append(r'C:\Users\hazell\AppData\Roaming\pyRevit\pyRevit-v3beta\modules')
import rpw
Getting the following error:
Could not add reference to assembly IronPython.Wpf
I'd like to use a variation of %appdata% to call instead of the direct path, but that's for a later day:
Hi,
As Name is a member of Autodesk.Revit.DB.Element. I think it would be great to be able to access it for any wrapped object child of it. I saw that you defined a property name on some specific element class, but it uses built in parameter names which are not common to all DB.Element subclasses and sometimes read only. So I tried to add following code to your Element class but it fails for some reason. I don't understand because when I do it manually in RPS it works. As you know, just doing element.Name doesn't work on any element subclass so I use DB.Element.Name.GetValue(element) :
@property
def name(self):
""" Name Property """
return DB.Element.Name.GetValue(self.unwrap())
@name.setter
def name(self, value):
""" Name Property Setter """
return DB.Element.Name.SetValue(self.unwrap(), value)
rpw.db.Element.Factory(s0)
<RPW_Instance: 72" x 36">
i = rpw.db.Element.Factory(s0)
isinstance(i, Element)
False <<< This should return True
isinstance(i.unwrap(), Element)
True
Hi @gtalarico , we use rpw.forms for a couple of tools in pyRevit, where it works pretty smoothly.
however if I were to paste code into RevitPythonShell , like the one from the readthedocs documentation I get the following exception:
from rpw import forms
prompt = forms.TextInput('Title', default="3")
prompt.show()
print(prompt.selected)
IronPython 2.7.4 DEBUG (2.7.0.40) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>>
... from rpw import forms
...
... prompt = forms.TextInput('Title', default="3")
... prompt.show()
... print(prompt.selected)
...
[INFO] Running In Revit
Exception : System.MissingMemberException: 'NoneType' object has no attribute 'LoadComponent'
any ideas? Thank you!
If a console is called in a loop, user needs to be able to force close
Include __setattr__
method in Base Wrapper to allow:
wall = rpw.Element(some_wall)
wall.Pinned = True
The initial implementation was removed because it was causing infinite recursion loops on setattr
import rpw crashes in Revit 2023 in revitpythonshell
import pyrevit works fine but import rpw crashes it
I am using rpw that came with pyRevit v 4.8.14.24016 which is latest as Feb 2024 on windows 10
>>> from rpw import db
>>> db.Collector(of_class='Wall')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Revit\revitpythonwrapper-master\rpw\db\collector.py", line 480, in __repr__
File "E:\Revit\revitpythonwrapper-master\rpw\db\collector.py", line 477, in __len__
AttributeError: 'FilteredElementCollector' object has no attribute 'GetElementCount'
>>>
I got this exception in my RevitPythonShell. I'm using Revit 2015. I looked up here but couldn't find GetElementCount
. GetElementCount
only appears from 2016 API
Is there any workaround for my case?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.