Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

trying to use application in Revit Macro

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
jjesusdelpino
2114 Views, 7 Replies

trying to use application in Revit Macro

Im trying to use the .NewCategorySet() method of the Autodesk.Revit.DB.Creation.Application class.

I dont know how to call this object while in sharpDevelop creating macros because when I type Application, it just automatically goes to an Autodesk.Revit.ApplicationServices.Application object that is not what I want to use.

 

Any tips about this? Thanks!

 

Tries this but didnt work.

https://forums.autodesk.com/t5/revit-api-forum/revit-macros-uiapp-and-postcommand/td-p/8222697#

7 REPLIES 7
Message 2 of 8
bhprest
in reply to: jjesusdelpino

If this:

 

    Document doc = this.ActiveUIDocument.Document;   
    Application app = doc.Application;

 

did not work, the most likely culprit is that you are using a Document Module instead of an Application Module. 

 

From the Autodesk help website:

How do I access the Application object or the externalCommandData equivalent?All the Application-level macros are associated with the UIApplication object. In application-level macros, the Application keyword pointer in C# and VB.NET returns the API Application object.

In document-level macros, the Document keyword returns the API Document object. To access the UIApplication object from a document-level macro, use this.Application.

 https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2016/EN...

 

Hope this helps!

Message 3 of 8
jjesusdelpino
in reply to: bhprest

Hi bhprest and thanks for your anwser! All you tell me seems logic but I still have the same problem. I tried all that but still some errors are raising. I confirm that I am using an application module. According to the Autodesk help website, the "Application" keyword should work for me but as long as I type "Application" this error raise:

            UIDocument uidoc = this.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            // UIApplication uiapp = new UIApplication(Application);         
            CategorySet CatSet = Application.NewCategorySet();

 - 'Autodesk.Revit.ApplicationServices.Application' doesnt have a definition of 'NewCategorySet' 

 

Its clearly pointing to another Application object. And the thing is, no other approach seems to work for me. I have tried also:

            UIDocument uidoc = this.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            UIApplication uiapp = new UIApplication(Application);         
            CategorySet CatSet = uiapp.NewCategorySet();

 

And the error is:

- 'Autodesk.Revit.UI.UIApplication' doesnt have a definition of 'NewCategorySet'.

 

Then I also tried:

            UIDocument uidoc = this.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            UIApplication uiapp = new UIApplication(Application);         
            CategorySet CatSet = uiapp.Application.NewCategorySet();

 

And in this case the error is:

- 'Autodesk.Revit.ApplicationServices.Application' doesnt have a definition of 'NewCategorySet'.

 

Then I also tried:

            UIDocument uidoc = this.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            //UIApplication uiapp = new UIApplication(Application);         
            CategorySet CatSet = this.Application.NewCategorySet();

 

And in this case the error is:

- 'Autodesk.Revit.ApplicationServices.Application' doesnt have a definition of 'NewCategorySet'.

 

 

Its a bit confused but I think I have tried every single posibility according to my knowledge here. I think Im missing something but I dont know what is. I believe that the first way is the one that should work according to what I see in the help site.

 

Thanks you so much for your anwser. Regards

 

 

 

 

 

 

 

Message 4 of 8
FAIR59
in reply to: jjesusdelpino

try:

 

this.Application.Create.NewCategorySet();

Message 5 of 8
so-chong
in reply to: jjesusdelpino

Hi,

 

As Fair59 suggest

this.Application.Create.NewCategorySet();

is equivelant to

Application app = this.Application;
...
CategorySet CatSet = app.Create.NewCategorySet();

Hope this helps

Message 6 of 8
stever66
in reply to: so-chong

I don't get that to work in a DOCUMENT level macro.  (I'm using Revit 2020.  One of the previous replies referenced 2016. )

 

According to the help, Document.Application refers to the Application object in a document level macro.

 

This seems to compile:

 

Document.Application.Create.NewCategorySet();

 

https://help.autodesk.com/view/RVT/2020/ENU/?guid=GUID-C6E0196D-918B-4131-9B64-050DBE452158

 

 

 

Message 7 of 8
so-chong
in reply to: stever66

Hi @stever66 ,

You are right about a Document level macro your code snippet is the way to go.
Though i thought the orginal poster of this thread said something about....."I confirm that I am using an application module".
So my snippet of code will only work in Application level macro.
I hope the orginal poster can clarifies which level( application or document ) the code is intended to be used or show more of his code where the error occurs.

Message 8 of 8

Hi all and thanks for your anwsers. I finally manage to solve this as FAIR59 said. To clarify some doubts around this post. Im working on an application module and what I learned here is.

 

            UIDocument uidoc = this.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            
            Autodesk.Revit.ApplicationServices.Application app = this.Application;
            Autodesk.Revit.Creation.Application app1 = app.Create;
            

And then either:
             CategorySet CatSet = app.Create.NewCategorySet();

            or:
            CategorySet CatSet = app1.NewCategorySet();

 

The conflict came when Application can refer to either Autodesk.Revit.ApplicationServices.Application or Autodesk.Revit.Creation.Application. In this case I needed the Creation one to create the CategorySet but you will obviously have to understand both depending on your code. For example, later in the same code I need to use Autodesk.Revit.ApplicationServices.Application.OpenSharedParameterFile() so I have to use "app" there. Hope this helps and Thanks you all for your anwsers 😃

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report