Jump to content

Advice on learning to code for autocad....


chauncy274

Recommended Posts

Hey guys, I've been searching around for some advice threads from the past and can't seem to find much. I'd love to have some advice from the users on here as I'm starting to get into coding for autocad. The stuff I see you guys put out is quite amazing, so thanks for any help, it's really appreciated.

 

So basically I know alittle bit about lisp and I have been able to take other peoples code and twist it enough to do some cool things and help out around the office and automate some things. But I want to get into actual coding and with that comes the obvious questions. What language is the most useful for autocad? I keep hearing the same names popping up with small differences and it can be quite confusing. I have found and completed a good tutorial on Visual Basic .NET (http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=18162797) but I remember hearing that VB is a dying code that won't be used much longer or something like that? I've found and completed some good tutorials on C# but nothing that involves autocad.

 

So can anyone tell me what is a good code to start off with and maybe recommend a good tutorial on how to code with it in autocad and how to set up visual basic (using express 2015 at the moment) to make it work with autocad? I think you need a different setup for each code type correct?

 

If any of you know of a tutorial but think it might be over my head, please let me know about it anyways. I catch on quick and I'm eager to learn.

 

Thanks so much.

Link to comment
Share on other sites

I think the answer depends on what you want to accomplish and how much time you want to invest in learning.

 

Autolisp is limited in what it can do (although don't tell that to @LeeMac....), but it has the shortest learning curve.

.NET can do a lot more, and has access to APIs that are limited in some cases for autolisp (especially if you're working with a vertical such as Civil 3D), but at the cost of being a more difficult to master.

 

I'll stop here and wait on @LeeMac and @BlackBox to chime in with more and better info. :-)

Link to comment
Share on other sites

Thanks.

 

I'm willing to spend a good amount of time in learning. And the company that I work for is happy to put me in courses or classes for coding if I ask for it. I have set it up right now to where using one of Lee Macs lisp programs we can export attribute info from blocks we have in all the drawings (using autocads data extraction tool) in a job (the last job was over a thousand drawings) and fill in those attributes with data from our instrument index where all the designers have went in and filled out the info and finally put all that data from the excel sheet back in to drawing. It has saved us tons of time in drafting and needless to say the mistakes that have to be corrected during checking are extremely minimal. But even with that it takes a number of steps and alot of mistakes can be made if the designers make the drawings incorrectly etc and would love to be able to make it even better, along with other types of automation that I'd love to learn.

 

So I'm looking at this opportunity to learn all this coding as a job security device, a useful tool to move up in my job, and because I love autocad and computers, I've just never seemed to find a good time and opportunity to get down in it and learn to code.

Link to comment
Share on other sites

VB is not going to phased out, well not at the moment, but VBA has a more uncertain future. I agree with all that rkm said, especially "...depends on what you want to accomplish..." In .NET you have the choice of using several programming languages such as C#, VB or F#, but there are far more code examples out there for C# than for any of the others. It's a personal thing really and whichever way you decide to go it's going to entail quite a bit of learning and a good deal of time.

 

Best of luck with whatever you choose.

Link to comment
Share on other sites

VB is not going to phased out, well not at the moment, but VBA has a more uncertain future. I agree with all that rkm said, especially "...depends on what you want to accomplish..." In .NET you have the choice of using several programming languages such as C#, VB or F#, but there are far more code examples out there for C# than for any of the others. It's a personal thing really and whichever way you decide to go it's going to entail quite a bit of learning and a good deal of time.

 

Best of luck with whatever you choose.

 

Oh, I wasn't aware there was a difference.

 

So VBA is an older coding and VB is newer and can actually work with the .net framework? Or is there a bigger difference I'm missing?

Link to comment
Share on other sites

I would go back to the original question of how complex is your tasks if you want to change 1 variable in 100 dwgs then .net, if its just day to day make the drafting more productive then there is nothing wrong with lisp,

 

eg a task put a bubble with a number in it increasing each time.

Method 1 circle and text then copy then change text value, keep copying and changing.

Method two lisp enter start number as fast as you can pick it will do a bubble with a number.

 

Another a task took about 20 mins to draw manually, the lisp, draw pline outline, pick control point task finished about 1.5 seconds.

 

Have a look at David Bethel examples here using Acad 2002 answer 20 questions full 3d rendered output of commercial kitchen equipment.

 

Lastly give us an idea/list of tasks and we can comment from so easy, to get some else and pay, hint Lee Mac etc.

Link to comment
Share on other sites

Well, it's not just what I need done now. I want to learn it so I can do anything we need in the future.

 

My current process of filling in our drawings from our database is long winded and prone to errors, but it saves us alot of time. I'd like to make more of it automated. So ideally I'd like to be able to link up fields or attributes with data from our database and update our drawings accordingly. Right now only some of the information is being updated and in order to do it I have to extract all of our attributes from 1000+ drawings, pull it in to MS access, fill in the data, send to a CSV file and then finally I have to update all of the drawings by opening them up individually (I use scriptpro and run a tiny script in each drawing so it opens and closes all of them or me) using a program that LeeMac made to update titleblocks from a CSV file. It works but it could be alot better and I've been told that C# and .net is the way to go to automate this even more.

 

So that's what I'm looking at. But there are lots of other ideas that we have floating around like bringing other types of drawings in to the database so that we can cross check it's data in an easy manner.

 

Alot of it is going to be database reading and maybe editing. Any thing else I've ever needed seems like I can do it through lisp.

Link to comment
Share on other sites

Oh, I wasn't aware there was a difference.

 

So VBA is an older coding and VB is newer and can actually work with the .net framework? Or is there a bigger difference I'm missing?

 

No, there is a big difference between VB and VBA is a tuned down version of VB with a lot less functionality and was developed by Microsoft for their Office applications for people to write macros without knowing that much about programming. VBA stands for Visual Basic for Applications and VBA for AutoCAD and the VBA enabler, which is required to run VBA within AutoCAD, can be downloaded from the Autodesk website. There are lots of tutorials for C#, VB, VBA and VLISP, you just need to Google and there are plenty of books you can buy for all of the languages and which are very handy to have on your desk as a reference. Have a look in Wikipedia to get on overall background view of the languages.

 

There's no harm in learning two or more of these languages and choosing which one to use dependant on which task you have in hand.

Link to comment
Share on other sites

Yea, apparently it's hard to find someone who's good at programming that only knows one language. I was just looking to see if anyone had any advice on the best for starting out but that would also be able to do everything I need.

Link to comment
Share on other sites

Have a look at posts about "getexel" this is a two way lisp about communicating with exel a similar approach can be made for Ms Access it uses a row,column method as well. go to the Sample directories or google.

 

C:\Program Files\Autodesk\AutoCAD 2016\Sample\ActiveX\ExtAttr a exel example by Autodesk.

Link to comment
Share on other sites

I'll stop here and wait on @LeeMac and @BlackBox to chime in with more and better info. :-)

 

Thanks @rkmcswain, that is kind of you to say. :notworthy:

 

I gladly defer to our resident master of LISP, Lee, but will offer what I can on the transition to .NET API.

 

 

@OP - you're correct that most folks who become adept at programming, are familiar, if not proficient in multiple languages. Each has inherent tradeoffs, and it benefits you (the developer) to know when to use the right tool for the job.

 

When I jumped from Visual LISP (ActiveX COM, like VBA), to .NET API, I initially used VB as it was syntactically 'similar' to what I was accustom to using VL, which was easy at first. It was only after I started to get into the larger aspects of .NET that required more knowledge of .NET than knowledge of AutoCAD, I found it difficult to stick with VB.

 

It ended up greatly helping me to teach myself C# - it was an entirely different language which helped me approach .NET with the mindset that I had to learn .NET from scratch, rather than apply what I already knew from VL which often ended up being a deficit to my learning, as well as being inefficient with regard to what the .NET API provides.

 

I purchased a book on C# by Andrew Troelsen, and read through all 1,800 pages of it. In hindsight, learning .NET outside of the realm of AutoCAD, was the best thing I did to help me leverage AutoCAD's .NET API.

 

All of the guidance, and code samples from those that came before me were invaluable - I just needed a certain level of understanding to make sense of what they offered! Haha

 

Once I had a solid grasp on C#, only then was I able to pull concepts from my background in VL in a constructive way, and even find it fairly easy to switch between languages in the forums, etc.

 

When I'm in the midst of a project deadline, I still hop into VLIDE, rather than Visual Studio, but most of my performance focused, and Exchange apps are all done in C#.

 

This is just what I found to be useful, in my limited experience, YMMV.

 

 

 

Here are some old threads which may help you get started with .NET API:

 

http://www.cadtutor.net/forum/showthread.php?69646-Where-to-start-with-.Net

(^^ I cannot believe this was back in 2012 ^^)

 

http://adndevblog.typepad.com/autocad/2012/07/the-right-tools-for-the-job-autocad-part-1.html

(^^ 3 part article series ^^)

 

 

Good luck, HTH! :beer:

 

Cheers

Link to comment
Share on other sites

Thanks @rkmcswain, that is kind of you to say. :notworthy:

 

I gladly defer to our resident master of LISP, Lee, but will offer what I can on the transition to .NET API.

 

Thanks very much for your comments. I've checked out the links and it makes everything a bit more clear. As of right now I'm trying to study up on visual lisp in my spare time at work (I don't have autocad at home so I'm learning C# at home). When I become more proficient I'll start trying to use C# with .NET to work in autocad. I have some other things I need to streamline at work so I'll tackle those smaller projects and hopefully gain experience enough to really tackle this issue properly. It seems that I'm asking for trouble trying to earn to code on a huge complex problem like making a database and thousands of autocad drawings all link together.

 

Thanks everybody. I appreciate all the help. I've been trying to go in to the other forums around here to answer general autocad questions to try to help others out so that in a small way I can contribute to the forums. It's amazing how helpful everyone is on here.

Link to comment
Share on other sites

There are some good VL books on Kindle I purchased 4 and they cost about $8 each, run on a pc and can cut and paste code, there is a link mentioned to down load code but it did not work. Again if you have an idea there is lots here that can provide a method and when you get stuck coding can help that bit more.

Link to comment
Share on other sites

  • 2 weeks later...
Yea, apparently it's hard to find someone who's good at programming that only knows one language. I was just looking to see if anyone had any advice on the best for starting out but that would also be able to do everything I need.

Any good programmer understands fundamental and core concepts that apply to all programming languages.

Link to comment
Share on other sites

Chauncy 274 does your company have Autocad on Subscription ? There is a clause in their license agreement about use at Home, basicly you are only working on 1 computer at 1 time, there is also borrow license which means you take a code home to use. Search for EULA

Link to comment
Share on other sites

Chauncy 274 does your company have Autocad on Subscription ? There is a clause in their license agreement about use at Home, basicly you are only working on 1 computer at 1 time, there is also borrow license which means you take a code home to use. Search for EULA

 

Oh that's a good point. I will look in to that. It wouldn't surprise me if I could use it at home. I will ask the IT department.

 

Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...