How to set up uidoc in Sharp Develop

How to set up uidoc in Sharp Develop

stever66
Advisor Advisor
2,402 Views
8 Replies
Message 1 of 9

How to set up uidoc in Sharp Develop

stever66
Advisor
Advisor

I've got a short program that works in the Revit Python Shell.   I'd like to run it from the Sharp Develop editor in Revit.

 

The problem is, I'm not sure how to set up or access some of the variables like "uidoc".

 

For example, in RPS, I have the following line:

 

picked = uidoc.Selection.PickObject(ObjetType.Element)

 

But I can't get this to work with Sharp Develop.  I can't figure out how to set up "uidoc".  I've tried studying the examples provided with Sharp Develop, but I can't quite follow them.

 

Can anyone explan the basics of how to get variables like "app" , "doc", and "uidoc" to work with Sharp Develop?  Or is there anything that explains this?

 

Thanks:
Steve

0 Likes
Accepted solutions (2)
2,403 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Steve,

If you set up a new macro, it will automatically be equipped with a 'this' pointer.

The 'this.Application.ActiveUIDocument' object returns the UIDocument representing the current model file.

The 'this.Application.ActiveUIDocument.Document' object returns the database Document representing the current model database.

 

For more info on this, please read the 'getting started with Revit macros' material:

 

http://thebuildingcoder.typepad.com/blog/2015/10/rtc-classes-and-getting-started-with-revit-macros.h...

Cheers,

Jeremy

 


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

Message 3 of 9

stever66
Advisor
Advisor

Thanks Jeremy.   I thought I had tried that and couldn't get it to work.  But it was that simple.

 

I forgot to mention, I'm using python, so its slightly different:

 

uidoc = self.ActiveUIDocument
doc = self.ActiveUIDocument.Document
app = self.Application

 

 

It looks like this has to go after the Macro definition.  It doesn't work at the top of the module after all the import statements.  Maybe that's what I was trying to do yesterday.

0 Likes
Message 4 of 9

Anonymous
Not applicable

Hey Stever, 

 

I'm facing exactly what you asked in this thread. 

Could you show me how you fixed it? 

 

Also, i'm wondering if it is possible to write an addin in Python so that i don't have to use the Revit Python Shell. 

 

thanks!

0 Likes
Message 5 of 9

stever66
Advisor
Advisor

Yes, the three lines in my last post worked fine.

 

You can use the Sharp develop included with revit to write macros in Python, but it's more limited than using visual studio.  You are always tied to the sharp develop editor, it's basically a macro not an external application you can compile.  i think you always have to run the macro from the editor.  

 

If if you are still interested I have a couple of things on my website at:

 

sites.google.com/site/revitapi123

 

See the Sharp Develop Python 1st example.

 

 

 

 

0 Likes
Message 6 of 9

Anonymous
Not applicable

Thankyou Steve, 

 

i've seen your website. Are you still building / adding to it? 

If so i'll be able to add some python knowledge to it. The last while i've been digging into the Revit API and made a couple of usefull programs for my company. Especially when it comes to Python it's hard to find the answers to your questions on internet. 

 

Let me know if you'd like me to add to the website through a message. 

Cheers~

0 Likes
Message 7 of 9

Salomatin_
Participant
Participant

I have taking two errors. What I'm not understanding?

var uiDocument = this.Application.ActiveUIDocument;
var document =  this.Application.ActiveUIDocument.Document;

        public void uu1()
        {
            FilteredElementCollector familyCollector = new FilteredElementCollector(document);
            familyCollector.OfClass(typeof(FamilySymbol));

        FamilySymbol familySymbolToFind = null;

        foreach (FamilySymbol familySymbol in familyCollector)

0 Likes
Message 8 of 9

stever66
Advisor
Advisor
Accepted solution

If you are using C#, use something like this:

 

UIDocument uidoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;

 

look ok here for more on macros:

 

http://help.autodesk.com/view/RVT/2019/ENU/?guid=GUID-4DFDA8CD-B0FD-492E-8EDE-A28C29B1E316

Message 9 of 9

Salomatin_
Participant
Participant

Thank you!

0 Likes