I know basically 0 about scripting, and i hope no hard working script writers take offence to this post, as it was created with OpenAI.
I asked the program to write me a script to use within revit. Basically to create window elevations and dimension them. It came up with a few errors so i asked it to fix the errors, and it did, i think?
I just know very little and am unsure as to how to link this python script into dynamo for it to read my revit file and run the script. The code is as below:
# Autodesk Revit Python Script
# Script to create window elevations and dimension them
# import necessary modules
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
# define a transaction
def create_window_elevations_and_dimensions(doc):
t = Transaction(doc, 'Create window elevations and dimensions')
t.Start()
# create a new 3D View
view3d = View3D.CreateIsometric(doc, ElementId(BuiltInCategory.OST_Views))
# get all windows in the model
windows = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows).WhereElementIsNotElementType().ToElements()
# loop through all windows
for window in windows:
# create a detail level for elevation view
viewDetail = ViewDetailLevel.CreateDetail
Thereâs a Dynamo node for Python scripts that you can use, simply called âPython Scriptâ.
But uhhh⌠that script isnât going to do muchâŚ
I know basically 0 about scripting
So with no knowledge of Python or coding in general, instead of trying to learn anything youâre hoping an AI can produce functioning code that actually does what you ask it to? Why not just use the node based systems in Dynamo? Visual scripting is accessible as well as easy and fast for prototyping. You donât need coding knowledge.
E.g. below, I saw your Python is trying to create a 3D view at the start, so I rolled with that:
30 seconds max to put together and now youâve got a named 3D iso view for every window in the file.
Creating elevations is more complex, adding dimensions is more complex again. Take it step by step (which is easy to do with nodes in visual scripting). An AI isnât going to whip this up for you in 10 lines of code.
Unless you plan on waiting the 30+ years weâll need for code to learn how to think like a human vs harvest pre-existing info off the web Iâd say itâs time to learn to program vs hope openAI does it for you (no offense intended). At best, most programmers Iâve spoken to (software and hardcore alike) agree it will become an aid for programmers at the best, to assist with debugging and generating simple/reusable code - people will still be needed for creative processâ and ingenuities.
If code becomes so easy that anyone will be able to do it, your boss will do it and fire you instead in a capitalistic society, but I digressâŚ
A good post here by a solid programmer identifying common errors chatGPT makes and highlighting them in light of Revit API here:
Apologies, donât think i pasted the whole codeâŚ
I knew posting this would annoy people, which isnât my intention. If there is a tool to assist people with understanding how code functions, and an AI can give you an answer, or better yet a path to go down and post onto the internet for others to assist in what youâre trying to solve and further teach you scripting.The reason i donât delve into scripting or coding is because it overwhelms me and if this sets me in a direction as to better understand the method behind the madness then whats the issue, right?
SyntaxError: unexpected token ââ
Fix: Add a colon after the for loop.
# Autodesk Revit Python Script
# Script to create window elevations and dimension them
# import necessary modules
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
# define a transaction
def create_window_elevations_and_dimensions(doc):
t = Transaction(doc, 'Create window elevations and dimensions')
t.Start()
# create a new 3D View
view3d = View3D.CreateIsometric(doc, ElementId(BuiltInCategory.OST_Views))
# get all windows in the model
windows = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows).WhereElementIsNotElementType().ToElements()
# loop through all windows
for window in windows:
# create a detail level for elevation view
viewDetail = ViewDetailLevel.CreateDetail
It wont so much as annoy people to explore this field, but it will if we get it thrown at us as a viable alternative - which it clearly isnât at this point in time.
At the very least we would expect you endeavour to learn the basics of a programming language or environment before asking a forum to fix a half baked code from an NLP such as chatGPT. Myself and lot of other programmers are already having to explain to colleagues and relatives on a daily basis why our passions arenât doomed to the masses, so you might find a frosty reception if you donât show any interest/evidence in learning to program a bit.
If you truly want to learn a bit about programming begin with Dynamo, and the Dynamo Primer.
If you donât want to learn programming at any level, keep using third party add-ins built for you until chatGPT and its equivalents learn to build error-proof code.
The idea of using an AI to aid programming or program simple but time consuming tasks that it wonât stuff up, wonât necessarily annoy people. Posting code generated by an AI on a forum with âhelp me fix this, I have zero coding knowledgeâ will annoy people.
If there is a tool to assist people with understanding how code functions
AI isnât going to do this for a long time yet. Youâve asked it to create elevations and itâs creating 3D views. Trying to understand an interpretation of an interpretation is like playing Chinese whispers.
I saw a meme recently that was poking fun at that while the AI might write the code in a fraction of the time it takes a human to, youâll spend 10 times as long debugging it. If the AI code takes significant effort for a dev to work out whatâs going on and fix, how to you expect to understand that code with zero programming knowledge?
AI coding feels more like a tool for people who already have coding knowledge to use as an aid rather than something average joe can use to get things done. Especially when it comes to the Revit API, perhaps itâs more usable for simpler more isolated tasks.
If it helps get the interest/understanding going of programming, I have a platform agnostic series about Python here. About 1.5 hours total watch time and it covers all the basic concepts and syntax involved with Python. No strings attached, free and aimed at non/low level programmers.
At the least it might help you recognize the structure of the code being returned as well as things like variables, methods and comments. Hope that helps! Programming is always frustrating to learn at first I think, and over time things fall into place (but there is always a degree of frustration - learning is hard sometimes!).
As i have 0 program knowledge, and do not understand it how am i meant to know if the script is incorrect? Idk about you, but if i have the option to enable an AI to spit out a script, and debug that script for me to solve a particular tedious issue - and it works, then yes i will choose to not learn scripting as that isnât my goal. I posted this to get insight into the code it wrote to see if it was anywhere on the right path and if it can be incorporated into dynamo to solve my issue.
but if i have the option to enable an AI to spit out a script, and debug that script for me to solve a particular tedious issue - and it works
The fact you are here asking why the code doesnât work shows you this isnât currently an option. Insight has been taken from the outcome at the least I guess, as youâve noted was the goal of coming here and asking about it.
I think if an AI is developed with the goal of solving Revit code specifically youâll have a better chance, but chatGPT is a very general NLP, so will only look for patterns and concepts to form what it assumes is a solution - which whilst amusing and still impressive, will not usually generate viable code for use in Dynamo/Revit.
As i have 0 program knowledge, and do not understand it how am i meant to know if the script is incorrect?
Start learning a basic level of coding so you can understand? Iâm probably going come across like a dick here, but this really feels like âI want results for zero effortâ. People will help you, but thereâs a difference between posting relatively complete code with some minor errors, and this code which is so wrong and so far from doing what is described that youâre really not going to get much.
Idk about you, but if i have the option to enable an AI to spit out a script, and debug that script for me to solve a particular tedious issue - and it works
It doesnât though. And a human will need to debug it, and if you have no knowledge then you canât do that.
then yes i will choose to not learn scripting as that isnât my goal
Learning scripting may not be your goal, but it is a method to get to your goal. If coding was my goal, Iâd be a developer, not in architecture. I was once a computer science student but bailed because I disliked it, yet here I am haha. If youâre so against programming that you donât even want to touch Dynamo nodes then maybe itâs time to start forking out for third party add-ins.
Something that is very important is that the data set used for chatGPT is over 1 year old and it does not have access to current information on the internet.
Also you as a user of AI technology and going to implement something it has given you, you must QA the code and assure it is right for the task in hand. If you have no coding knowledge then things could go bad fairly quickly.
What if the AI gives you some code from a bad source that then infects your system with malwareâŚVery bad situation.
Welcome to the community! Itâs good to see these new technologies are brining in new perspectives.
Donât worry about us taking offense to your work - itâs a totally legitimate toolset to explore. If you feel unwelcome feel free to tag me and Iâll try and smooth things over - while we are welcoming some of us can be a bit grouchy in nature.
I have done some GPT3 testing for this over the last few weeks/months. To âfinalizeâ my review today I live tweeted an attempt to use the OpenAI GPT3 chatbot to make some VERY basic Revit code - drawing a wall. It took me half an hour to get rate limited/break the chatbot as it was just calling variables which werenât defined. The code all looked legitimate in all cases, but in no case was it anywhere near running completely.
After more then 30 minutes and getting to the âbrokenâ state of the chatbot, I did a google search. The first hit was to a 2014 Dynamo forum post which had working code for me.
The take away is that in the current state these coding tools donât provide usable solutions; This makes sense as theyâre built to aggregate answers from multiple sources, but code snippets themselves canât be built piecemeal. If you define your active Revit document as actDoc and I define it as doc, and Gavin defines it as theGreatestDocumentToEverBe then none of our code will be âcopy/pasteâ ready between code samples. This is the first error I see in your code above; doc isnât even defined but itâs the variable you are attempting to feed into the definition⌠which has itâs own transaction but you donât deal with the active one created by Dynamo.
Tools like copilot likely make more sense for what youâre after, as they are built to assist in faster development using a code driven context (doc would already be defined before it recommended calling it); however it doesnât appear that is what you were using (hence the undefined variable).
The good news about this is that you donât really have to worry about it inserting malicious code into your system as even if it tried to the code wouldnât run. The âbadâ news is that some education and training is going to be required to get into this. The bar is likely lowered some already, but itâs got a long way to go to get to the point where an untrained user can get working code.
Good luck with the journey into this space; youâll certainly find many useful new tools as your skill set grows.
Good on you @jem.cicekdagKV2ZC, for us non coders it is a worthwhile question, I landed on this forum for exactly that reason of trying to gain an understaning of what AI means for⌠everything really. Even just trying to get a handle one what area & depth of knowledge you would need to have to utilise it as a tool & whether its a worthwhile investment of my time, or do I continue with business as usual.
If you can afford to wait say 5-10 years then it might be possible to avoid learning any code. In the meantime it will mostly benefit those with a fundamental understanding trying to do more complex things.
If you follow the trajectory of mainstream programming, itâs only gaining more relevance and application to everyday life and careers - I wouldnât advise waiting personally.