change Parameter values from ModalDialog

change Parameter values from ModalDialog

dirk.neethling
Advocate Advocate
687 Views
2 Replies
Message 1 of 3

change Parameter values from ModalDialog

dirk.neethling
Advocate
Advocate

Hello,

I've got a Modal Dialog (instance: thisForm), with references to Document and FamilyManager, which gets started from the Execute method using

thisForm.ShowDialog().

 

 

The Parameter values can be updated successfully in the Dialog, but the redraw method fails. It only redraws once the Dialog is closed.

I assume it is the call familyDoc.ReloadLatest(rlo); which closes the Dialog?

 

I would like to refresh the document leaving the Dialog open.

 

                if (null != familyDoc)
                {
                    FamilyManager familyManager = familyDoc.FamilyManager;

                    using (frmObjStyles thisForm = new frmObjStyles(pathToFamilyDoc, ref doc,
                        ref familyDoc, ref familyManager, ref opt))
                    {
                        thisForm.ShowDialog();
                        if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                        {
                            return Result.Cancelled;
                        }
                        else if (thisForm.DialogResult == System.Windows.Forms.DialogResult.OK)
                        {
                            Class2 c2_ = frmObjStyles.c2 as Class2;

                            using(Transaction trans4 = new Transaction(familyDoc, "Pick a group"))
                            {
                                trans4.Start();
                                FamilyParameter familyParam = familyManager.get_Parameter("HT_INSIDE_RADIUS_COMPONENT");
                                if (null != familyParam)
                                    familyManager.SetValueString(familyParam, c2_.HT_INSIDE_RADIUS_COMPONENT);

                                familyParam = familyManager.get_Parameter("HT_THICKNESS_COMPONENT");
                                if (null != familyParam)
                                    familyManager.SetValueString(familyParam, c2_.HT_THICKNESS_COMPONENT);

                                familyParam = familyManager.get_Parameter("HT_WIDTH_NOMINAL_COMPONENT");
                                if (null != familyParam)
                                    familyManager.SetValueString(familyParam, c2_.HT_WIDTH_NOMINAL_COMPONENT);
                                trans4.Commit();
                            }

                            f2 = familyDoc.LoadFamily(doc, opt);
                            SaveAsOptions options = new SaveAsOptions();
                            options.OverwriteExistingFile = true;
                            options.SetWorksharingOptions(null);
                            familyDoc.SaveAs(pathToFamilyDoc, options);
                            ReloadLatestOptions rlo = new ReloadLatestOptions();
                            familyDoc.ReloadLatest(rlo);
                        }
                    }
                }

 

In the Form class used for the Dialog, the changes are thus captured in a TextChanged Handler:

        private void HT_WIDTH_NOMINAL_COMPONENT_TextChanged(object sender, EventArgs e)
        {
            if (!init)
            {
                //c2.HT_WIDTH_NOMINAL_COMPONENT = HT_WIDTH_NOMINAL_COMPONENT.Text;
                using(Transaction trans4 = new Transaction(familyDoc, "Pick a group"))
                {
                    trans4.Start();
                    System.Windows.Forms.TextBox box = sender as System.Windows.Forms.TextBox;
                    FamilyParameter familyParam = familymanager.get_Parameter(box.Name);
                    if (null != familyParam)
                        familymanager.SetValueString(familyParam, box.Text);
                    trans4.Commit();
                }

                ReloadLatestOptions rlo = new ReloadLatestOptions();
                familyDoc.ReloadLatest(rlo);
            }
        }

 

 

 

 

0 Likes
688 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Dear Dirk,

 

Your code looks rather convoluted to me.

 

Normally, a user has to select OK in the modal form before any modifications are executed.

 

I would (always!) suggest completely separating your Revit database interaction from the modal dialogue user interfface code.

 

In the user interface, keep a record of all the user's input and modification requests.

 

After the dialogue has been closed with OK, apply them to the Revit document.

 

That will carify things tremendously and hopefully resolve your problem automatically.

 

KISS!

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

arnostlobel
Alumni
Alumni

I think the problem in this particular cases here is with refreshing. The programmer needs to understand that once a modal dialog is open, it occupies the message loop in Revit, therefore nothing else can be updated there, unless explicitly forced. That is most likely why the document gets updated only after the dialog is dismissed. I may suggest trying to explicitly call RefreshActiveView from the dialog to see if that helps, but chances are that it may not help.

 

Dirk, I have some trouble with following you code. Is your 'familyDoc' actually a project document, by any chance?

 

Thanks

Arnošt Löbel
0 Likes