コード例 #1
0
class SelectParameter(Form):
    def __init__(self):
        self.fm = doc.FamilyManager
        self._all_param_names = None

        self.Text = 'Параметры'
        self.Name = 'Select Parameters'
        self.Width = 210
        self.Height = 400

        self.title = Label()
        self.title.Text = "Выберете параметры"
        self.title.Height = 30
        self.title.TextAlign = ContentAlignment.MiddleCenter
        self.title.Dock = DockStyle.Top

        self.combobox = ListBox()
        self.combobox.MultiColumn = False
        self.combobox.SelectionMode = SelectionMode.MultiExtended
        self.combobox.BeginUpdate()
        for i in self.all_param_names:
            self.combobox.Items.Add(i)
        self.combobox.EndUpdate()
        self.combobox.Height = 270
        self.combobox.Location = Point(0, 30)
        self.combobox.Dock = DockStyle.Top

        self.button = Button()
        self.button.Text = "Выполнить"
        self.button.Dock = DockStyle.Top
        self.button.Click += self.change_param_type

        self.Controls.Add(self.button)
        self.Controls.Add(self.combobox)
        self.Controls.Add(self.title)

        self.handler = Execute_change_type()
        self.exEvent = ExternalEvent.Create(self.handler)

    @property
    def all_param_names(self):
        if self._all_param_names is None:
            self._all_param_names = [
                i.Definition.Name for i in self.fm.GetParameters()
                if not i.IsInstance
            ]
        return self._all_param_names

    @property
    def graph(self):
        return [self.depend_of_param(i) for i in self.combobox.SelectedItems]

    def depend_of_param(self, param):
        res = {"param": param, "dep": []}
        for cur_param in self.all_param_names:
            if cur_param == param:
                continue
            f_param = self.fm.get_Parameter(cur_param)
            if f_param.IsDeterminedByFormula:
                templ = re.compile(
                    "(^({0})[^A-Za-zА-Яа-я0-9_])|([^A-Za-zА-Яа-я0-9_]({0})[^A-Za-zА-Яа-я0-9_])|(({0})$)|(\[({0})\])"
                    .format(param))
                if templ.search(f_param.Formula):
                    res["dep"].append(self.depend_of_param(cur_param))
        return res

    def change_param_type(self, arg, prop):
        self.handler.graph = self.graph
        self.exEvent.Raise()
        self.Close()
コード例 #2
0
ファイル: __init__.py プロジェクト: NauGaika/RedBimTest
class SelectParameter(Form):
    _all_param_group = {}

    def __init__(self):
        self.fm = doc.FamilyManager
        self._all_param_names = None

        self.Text = 'Параметры'
        self.Name = 'Select Parameters'
        self.Width = 400
        self.Height = 450

        self.title = Label()
        self.title.Text = "Выберете параметры"
        self.title.Height = 30
        self.title.TextAlign = ContentAlignment.MiddleCenter
        self.title.Dock = DockStyle.Top

        self.label = Label()
        self.label.Text = "Выберете новую группу параметров"
        self.label.Height = 30
        self.label.TextAlign = ContentAlignment.MiddleCenter
        self.label.Dock = DockStyle.Top

        self.listbox = ListBox()
        self.listbox.MultiColumn = False
        self.listbox.SelectionMode = SelectionMode.MultiExtended
        self.listbox.BeginUpdate()
        params = list(self.all_param_names.keys())
        params.sort()
        for i in params:
            self.listbox.Items.Add(i)
        self.listbox.EndUpdate()
        self.listbox.Height = 270
        self.listbox.Location = Point(0, 30)
        self.listbox.Dock = DockStyle.Top

        self.combobox = ComboBox()
        els = list(self.all_param_group.keys())
        els.sort()
        for i in els:
            self.combobox.Items.Add(i)
        self.combobox.Location = Point(0, 300)
        self.combobox.Dock = DockStyle.Top

        self.button = Button()
        self.button.Text = "Перенести"
        self.button.Dock = DockStyle.Top
        self.button.Click += self.change_param_group

        self.Controls.Add(self.button)
        self.Controls.Add(self.combobox)
        self.Controls.Add(self.label)
        self.Controls.Add(self.listbox)
        self.Controls.Add(self.title)

        self.handler = Execute_change_group()
        self.exEvent = ExternalEvent.Create(self.handler)

    @property
    def all_param_names(self):
        if self._all_param_names is None:

            self._all_param_names = {
                "({}) {}".format(
                    LabelUtils.GetLabelFor(i.Definition.ParameterGroup),
                    i.Definition.Name): i
                for i in self.fm.GetParameters()
            }
        return self._all_param_names

    @property
    def all_param_group(self):
        if not self.__class__._all_param_group:
            els = {
                LabelUtils.GetLabelFor(getattr(BuiltInParameterGroup, i)):
                getattr(BuiltInParameterGroup, i)
                for i in dir(BuiltInParameterGroup) if i[0:2] == "PG"
            }
            self.__class__._all_param_group = els
        return self.__class__._all_param_group

    def change_param_group(self, arg, prop):
        self.handler._selected_params = [
            self.all_param_names[i] for i in self.listbox.SelectedItems
        ]
        self.handler._selected_group = self.all_param_group[
            self.combobox.SelectedItem]
        self.exEvent.Raise()
        self.Close()