Results 1 to 4 of 4

Thread: Following Udemy tutorial: ThisDocument does not contian a definition for 'ActiveUIDocument'...

  1. #1
    Member
    Join Date
    2016-03
    Posts
    9
    Login to Give a bone
    0

    Default Following Udemy tutorial: ThisDocument does not contian a definition for 'ActiveUIDocument'...

    I'm currently viewing tutorials for the RevitAPI by udemy, currently on the second video i.e. "Prompt user to select an element, get element info".

    When I build the code however, which I just followed from the tutorial, I get the error in the title, like it's saying that it can't find ActiveUIDocument or something.

    Code:
    namespace promptuser
    {
        [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
        [Autodesk.Revit.DB.Macros.AddInId("4C3F6AF8-A7AF-4E43-9D90-2DE1A9DB7BA3")]
    	public partial class ThisDocument
    	{
    		public void selectElement()
    		{
    			// info about how the revit user interacts with the file
    			// icludes info about view windows and selection of elements in those windows
    			// then we get the activeUiDocument use the ff syntax
    			UIDocument uidoc = this.ActiveUIDocument;
    			
    			// Database doc = stores info about walls, floors, parameters, etc.
    			Document doc = uidoc.Document;
    			
    			// prompt the user to select an object
    			// Namespace: Autodesk.Revit.UI.Selection
    			// this would have been the code = uidoc.Selection.PickObject(ObjectType.Element);
    			
    			// but since this returns a Reference object, store that in a variable
    			Reference myRef = uidoc.Selection.PickObject(ObjectType.Element);
    			
    			// get the element itself
    			Element e = doc.GetElement(myRef);
    			
    			// display its name, and ID
    			TaskDialog.Show(e.Name + Environment.NewLine + e.Id);
    		}
    		
    		public void SimpleDialog()
    		{
    			TaskDialog.Show("This is a title", "Hello Revit WOrld");
    		}
    		
    		
    	}
    }
    I have no idea why this is happening.

  2. #2
    Member
    Join Date
    2016-03
    Posts
    9
    Login to Give a bone
    0

    Default Re: Following Udemy tutorial: ThisDocument does not contian a definition for 'ActiveUIDocument'...

    Nevermind, just discovered the problem, just checked the RevitAPI chm, apparently ActiveUIDocument is a property of UIApplication which in turn is part of the Autodesk.Revit.UI namespace.

    The solution would simply be

    Code:
    UIApplication uiapp = this.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    What's weird though is that the tutorial worked despite the lack of the code above. What could be the reason for this?
    Last edited by polylop; 2017-12-03 at 12:18 PM.

  3. #3
    Member
    Join Date
    2015-09
    Posts
    8
    Login to Give a bone
    0

    Default Re: Following Udemy tutorial: ThisDocument does not contian a definition for 'ActiveUIDocument'...

    The original udemy tutorial is for an application macro. It does not need to access the application.

  4. #4
    Member
    Join Date
    2015-12
    Posts
    19
    Login to Give a bone
    0

    Default Re: Following Udemy tutorial: ThisDocument does not contian a definition for 'ActiveUIDocument'...

    Quote Originally Posted by willw663499 View Post
    The original udemy tutorial is for an application macro. It does not need to access the application.
    That is correct. Accessing the active document from an application macro is through referencing the application first and then grabbing the active document from it, while accessing the active document from a document macro is direct because the macro would be running from within the active document itself.

Similar Threads

  1. Replace existing block definition with new definition of the same name
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2016-10-31, 07:37 PM
  2. Line type definition duplicate definition problem.
    By AJGKennedy in forum ACA General
    Replies: 2
    Last Post: 2010-06-22, 06:55 PM
  3. Bad Definition?
    By cadman_meg in forum AutoCAD General
    Replies: 6
    Last Post: 2008-10-23, 06:06 PM
  4. Definition of FBX
    By jermcmartin166066 in forum Revit - Rendering
    Replies: 1
    Last Post: 2008-07-07, 01:13 AM
  5. Replies: 0
    Last Post: 2005-02-09, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •