pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.27k stars 330 forks source link

[Bug]: ipy2711 - FlexForm LoadComponent, 3 args required 2 passed #2185

Closed jmcouffin closed 5 months ago

jmcouffin commented 5 months ago

✈ Pre-Flight checks

🐞 Describe the bug

While using rpw flexform module and the LoadComponent, the code context seems to not go through. The issue occured previously.

I will document the issue later.

⌨ Error/Debug Message

3 arguments required, 2 passed

♻️ To Reproduce

Ipy 2711 Import row flexform Use the LoadComponent () method

⏲️ Expected behavior

No response

🖥️ Hardware and Software Setup (please complete the following information)

-

Additional context

No response

jmcouffin commented 5 months ago

For reference

https://github.com/eirannejad/pyRevit/blob/23b58850070b549ca1128c414ec8eb018d0dfc13/pyrevitlib/rpw/ui/forms/resources.py#L36-L48

https://discourse.pyrevitlabs.io/t/selectfromlist-error/2080/2

https://stackoverflow.com/questions/32013933/ironpython-wpf-withe-revitpythonshell

https://github.com/IronLanguages/main/issues/1273

jbf1212 commented 5 months ago

I just posted a pull request that should fix this. It basically mimics how pyRevit imports wpf. I will leave it to the team to decide whether or now we want to intentionally leave the rpw stale in order to move off of it over time or not. I know this update caused some pain for my company who was relying heavily on rpw forms.

jmcouffin commented 5 months ago

I will check this out

jmcouffin commented 5 months ago

fixed by #2188

thumDer commented 5 months ago

Thanks for this, I had trouble with rpw, because IPY2711PR engine had pyRevitLabs.IronPython.Wpf so clr.AddReference('IronPython.Wpf') threw an exception

thumDer commented 5 months ago

NOTE: below is just an investigation on the original issue, which seems to be solved by the related PR

Okay, so the original issue of LoadComponent is happening in Revit 2022, but in 2023, 2024 it breaks with the IOException when trying to load the IronPython.Wpf assembly. Anyone knows why does it act differently?

Edit: found the reason: IronPython.Wpf is already preloaded by Dynamo, so clr finds it and it doesn't try to load from pyrevit bin IronPython.Wpf 2.7.9.0 C:\Program Files\Autodesk\Revit 2022\AddIns\DynamoForRevit\IronPython.Wpf.dll Thats why we have IronPython.Wpf in 2022, that breaks, but nothing in 2023, 2024

jmcouffin commented 5 months ago

tried it in 2024 2023 2021 image I will try it in 2022 then

jmcouffin commented 5 months ago

tried the pychilizer room data sheet tool from that

from pyrevit import revit, DB, script, forms
from rpw.ui.forms import FlexForm, Label, TextBox, Button, ComboBox, CheckBox, Separator
import rdslocator, rdsui
from itertools import izip
import sys
from pychilizer import units, select, geo, database
from Autodesk.Revit import Exceptions

ui = rdsui.UI(script)
ui.is_metric = units.is_metric
doc = __revit__.ActiveUIDocument.Document

output = script.get_output()
logger = script.get_logger()  # helps to debug script, not used

selection = select.select_with_cat_filter(DB.BuiltInCategory.OST_Rooms, "Pick Rooms for Room Data Sheets")

# collect all view templates for plans and sections
viewsections = DB.FilteredElementCollector(doc).OfClass(DB.ViewSection)  # collect sections
ui.viewsection_dict = {v.Name: v for v in viewsections if v.IsTemplate}  # only fetch the IsTemplate sections
viewplans = DB.FilteredElementCollector(doc).OfClass(DB.ViewPlan)  # collect plans
ui.viewplan_dict = {v.Name: v for v in viewplans if v.IsTemplate}  # only fetch IsTemplate plans

ui.viewport_dict = {database.get_name(v): v for v in
                    database.get_viewport_types(doc)}  # use a special collector w viewport param
ui.set_vp_types()
# add none as an option
ui.viewsection_dict["<None>"] = None
ui.viewplan_dict["<None>"] = None
ui.set_viewtemplates()
ui.set_viewtemplates()

# collect titleblocks in a dictionary
titleblocks = DB.FilteredElementCollector(doc).OfCategory(
    DB.BuiltInCategory.OST_TitleBlocks).WhereElementIsElementType().ToElements()
if not titleblocks:
    forms.alert("There are no Titleblocks loaded in the model.", exitscript=True)
ui.titleblock_dict = {'{} : {}'.format(tb.FamilyName, revit.query.get_name(tb)): tb for tb in titleblocks}
ui.set_titleblocks()

view_scale = 50

# get units for Crop Offset variable
if units.is_metric(doc):
    unit_sym = " [mm]"
else:
    unit_sym = " [decimal feet]"

components = [
    Label("Select Titleblock"),
    ComboBox(name="tb", options=sorted(ui.titleblock_dict), default=database.tb_name_match(ui.titleblock, doc)),
    Label("Sheet Number"),
    TextBox("sheet_number", Text=ui.sheet_number),
    Label("Crop offset" + unit_sym),
    TextBox("crop_offset", Text=str(ui.crop_offset)),
    Label("Titleblock (internal) offset" + unit_sym),
    TextBox("titleblock_offset", Text=str(ui.titleblock_offset)),
    Label("Layout orientation"),
    ComboBox(name="layout_orientation", options=ui.layout_orientation, default=ui.layout_ori),
    CheckBox("el_rotation", 'Rotate elevations', default=ui.rotated_elevations),
    CheckBox("el_as_sec", 'Elevations as Sections', default=ui.el_as_sec),
    Label("Titleblock orientation"),
    ComboBox(name="tb_orientation", options=ui.tblock_orientation, default=ui.titleblock_orientation),
    Separator(),
    Label("View Template for Plans"),
    ComboBox(name="vt_plans", options=sorted(ui.viewplan_dict), default=database.vt_name_match(ui.viewplan, doc)),
    Label("View Template for Reflected Ceiling Plans"),
    ComboBox(name="vt_rcp_plans", options=sorted(ui.viewplan_dict),
             default=database.vt_name_match(ui.viewceiling, doc)),
    Label("View Template for Elevations"),
    ComboBox(name="vt_elevs", options=sorted(ui.viewsection_dict), default=database.vt_name_match(ui.viewsection, doc)),
    Label("Viewport Type"),
    ComboBox(name="vp_types", options=sorted(ui.viewport_dict), default=database.vp_name_match(ui.viewport, doc)),
    Separator(),
    Button("Select"),
]

form = FlexForm("Set Sheet Number", components)
ok = form.show()
jmcouffin commented 5 months ago

it works fine in 2022... @thumDer

thumDer commented 5 months ago

Sorry for the confusion but I was talking about the situation before the related pull request, how the original rpw wpf referencing worked, just wanted to investigate. I should have been more specific.

jmcouffin commented 5 months ago

for reference, interactions with ipy3, rps, ipy2, wpf https://github.com/architecture-building-systems/revitpythonshell/issues/155#issuecomment-2049190852