WPF accessing Document doc

WPF accessing Document doc

Anonymous
Not applicable
1,328 Views
6 Replies
Message 1 of 7

WPF accessing Document doc

Anonymous
Not applicable

Hi,

I have a windows WPF which I’d like to populate with some parameters from the titleblock which is selected from a ComboBox.  I’m using a selectionChangedEventArgs to manage the selection.  When an item is selected from the ComboBox the parameters from the titleblock selected should update. My problem is that I need to check the FamilySymbol which is selected and retrieve the FamilySymbol's parameters.  I have built the class and methods to do this.  The problem is that I need the “Document doc” which I can’t seem to access without “ExternalCommandData”.  Is it possible to make a method which would return the Document?   Or maybe something simple such as “Autodesk.Revit.DB.Document doc;”?

 

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
            ComboBox cmb = sender as ComboBox;
            object selectedValue = cmb.SelectedItem;
            selectedTitleblock = selectedValue.ToString();
            SchemaAndStoreData schemaAndStoreData = new SchemaAndStoreData();

            Titleblock tb = new Titleblock();
//This is where I need the Document doc.
tb.TitleblockFamilySymbolList(doc); FamilySymbol titleblock = tb.getFamilySymbol(selectedTitleblock); schemaAndStoreData.RetrieveData(titleblock); }
0 Likes
Accepted solutions (1)
1,329 Views
6 Replies
Replies (6)
Message 2 of 7

Charles.Piro
Advisor
Advisor
Accepted solution

Hi,

 

you must pass the document in the WPF.

In your command :

 

UserControl WPF_control = new WPF_control(doc);
WPF_control.ShowDialog();

 

 

and in your WPF :

 

public partial class UserControl : Window
    {
        private Document doc;

        public UserControl(Document _doc)
        {
            doc = _doc;
            InitializeComponent();
        }

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
//YOUR CODE
}
}

 

Smiley Wink

 



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 3 of 7

Anonymous
Not applicable

I usually just pass the UIApplication because you never know when you might need access to UIDocument, Application, etc.  Which all can be derived from the UIApplication, including the Document.

0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Dear Danny,

 

Thank you for your query.

 

Dear Charles and Michael, thank you for your helpful suggestions.

 

Danny, please be aware lest these friendly uncles lead you astray.

 

The first thing you need to clarify is:

 

Are you in a valid Revit context?

 

If you do not have access to the current document nor ExternalCommandData, the answer is quite probably no.

 

In that case, any access whatsoever that you attempt to make to the Revit API is illegal and will probably crash your add-in and Revit with no warning sooner or later.

 

Please avoid that!

 

Please do not get lynched by your poor unsuspecting customers!

 

Please read this exhaustive collection of discussions on Idling and External Events for Modeless Access and Driving Revit from Outside:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28

 

You might want to start at the end and continue until you really truly grok it.

 

It is very simple, actually, and really, really important, so well worth spending some time on.

 

I hope this helps both you and others.

 

Thank you for your attention!

 

Best regards,

 

Jeremy



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

Message 5 of 7

Anonymous
Not applicable

danny.bentley never said he was working on a modeless form.  Otherwise, it is slightly different, but I still pass UIApplication to my main form.  All transactions are done in the RequestHandler.

0 Likes
Message 6 of 7

jeremytammik
Autodesk
Autodesk

Dear Michael,

 

Absolutely true, he did not.

 

Does he know the importance of this?

 

Your approach sounds as if you do, and sounds pretty interesting, to boot.

 

So you have a modeless form, and it interacts with Revit via an external event?

 

Cool.

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 7 of 7

Anonymous
Not applicable

Thank you everyone for your help.  Jeremy, I have access to the ExternalCommandData so I shouldn't be in a modeless form.  Sorry about confussing everyone.  I'm using a handful of methods and classes. Which got me to a point where I couldn't pass the document through an argument into my WPF. I got stuck and need to figure a solution on how to pass the document.  I think the solution was given by Charles.  I will read and do more research to make sure I have a stable add-in.  

0 Likes