gtalarico / revitapidocs

Online Revit API Documentation: 2015, 2016, 2017, 2017.1, 2018
http://www.revitapidocs.com
33 stars 20 forks source link

where to add python examples to revitapidocs? #79

Closed fbe-work closed 7 years ago

fbe-work commented 7 years ago

Hi @gtalarico, sorry if this is obvious and I just missed it: How would I add a Python RevitAPI example to revitapidocs? I could not find a simple and short Python example on the IFailuresPreprocessor, so I wrote one, which hopefully might be helpful to others (as shown below below). Would I PR it on github to revitapidocs? Thank you. Best, @hdm-dt-fb


import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import Transaction, IFailuresPreprocessor, BuiltInFailures, UV
from System.Collections.Generic import List

doc = __revit__.ActiveUIDocument.Document
active_view = doc.ActiveView
active_lvl = active_view.GenLevel

class RoomWarningSwallower(IFailuresPreprocessor):
    def PreprocessFailures(self, failuresAccessor):
        fail_list = List[FailureMessageAccessor]()
        fail_acc_list = failuresAccessor.GetFailureMessages().GetEnumerator()
        for failure in fail_acc_list:
            failure_id = failure.GetFailureDefinitionId()
            failure_severity = failure.GetSeverity()
            failure_type = BuiltInFailures.RoomFailures.RoomNotEnclosed
            if failure_id == failure_type:
                print("{0} with id: {1} of type: RoomNotEnclosed removed!".format(failure_severity, failure_id.Guid))
                failuresAccessor.DeleteWarning(failure)
        return FailureProcessingResult.Continue

# "Start" the transaction
tx = Transaction(doc, "place unenclosed room")
tx.Start()

options = tx.GetFailureHandlingOptions()
options.SetFailuresPreprocessor(RoomWarningSwallower())
tx.SetFailureHandlingOptions(options)

room = doc.Create.NewRoom(active_lvl, UV(0,0))

# "End" the transaction
tx.Commit()
gtalarico commented 7 years ago

This is great, thank you for sharing @hdm-dt-fb

The python examples in the Python Tab are pulled from my public gists, located here: https://gist.github.com/gtalarico/ If you are interested in becoming a regular contributor, let me know and I can find a way to make the platform open for multiple contributors (ie. search multiple gists)

In the meantime, for one-off contributions, you can just add the code as a comment at the bottom of a relevant page. Make sure you add tags <pre><code>...your code... </code></pre> so that it formats nicely. Just added this as an example: http://www.revitapidocs.com/2017/053c6262-d958-b1b6-44b7-35d0d83b5a43.htm

fbe-work commented 7 years ago

Well, thank you for the awesome revitapidocs! I am happy to share it - thanks for adding it. I see, they are coming from gists. Yes I would indeed like to add more python examples, just haven't used the gists myself yet. Would it crawl all my gists or only certain ones with a specific tag?

gtalarico commented 7 years ago

Yep. It Crawls each gist in my account and pulls any that match a certain pattern. Kind of hacky, but works so that I can add code samples without having to mess with the main code base.

I'm doing some re writing a lot of back end stuff, so I won t get to this for a while, but I will this in mind. In the meantime, feel free to post any code samples/tool you want added as an issue, and I will include then, with the proper credit of course.

fbe-work commented 7 years ago

That is pretty cool! (out of curiousity: Is a plugin of flask doing this or a separate script, that feeds the db that flask reads?) I looked through your gists and adjusted the IFailuresPreprocessor example, so it hopefully fits your web scrape pattern. I would create future snippets the same way, if that is fine. No worries, no rush. Best, Frederic

gtalarico commented 7 years ago

I use http://pygithub.readthedocs.io/en/latest/introduction.html It's not required, but helps with authentication and parsing.

If you want to send me a code to your gist, and I can copy it and add it on my end.

gtalarico commented 7 years ago

@hdm-dt-fb the code sample section now pulls code from a repository. Feel free to send prs or let me know if you want me to add you as contributor Github.com/gtalarico/revitapidocs.code