learning lisp vs python

learning lisp vs python

sunlight1
Enthusiast Enthusiast
7,644 Views
17 Replies
Message 1 of 18

learning lisp vs python

sunlight1
Enthusiast
Enthusiast

hi, dont shoot me yet 😃 

im an autocad drafter for 6 years and i wanted to learn how to code in autocad. 

i saw some posts about python and autocad, 

and idk which way to go. 

i want to get full control on autocad commands. 

should i go with python? or myb should i learn how to code lisps?

does python has full control on autocad? looks like lisp does. 

 i know this forum is not a python forum, but any advice will help! 

tnx a lot ! 

0 Likes
7,645 Views
17 Replies
Replies (17)
Message 2 of 18

ВeekeeCZ
Consultant
Consultant

Read THIS then follow the second part.

0 Likes
Message 3 of 18

Sea-Haven
Mentor
Mentor

Lisp has been around since day dot with Autodesk and they know if they stopped support the crash would be heard around the world. VBA has been stated by Autodesk to be discontinued but it is still there what 5 years on now ? I would be wary though of when they will pull the plug.

 

The push is for .net it has a lot of advantages particuarly speed when doing massive tasks. If you just want to draw a box lisp is your friend. 

 

Have a look here how many lisp answers a day compared to .net

 

Lisp becomes simpler once you get to understand it, VL was added to improve functionality. There is a few Python people out there asking questions, do a google, there is a macro record in Autocad but for some of us not worth the effort as its not really editable not like say excel.

 

DCL is old but OPENDCL provides a modern day programming interface as a substitute. 

 

I started with intel 86 processors look how fast programs run watching lines appear, with processing speed now we talk micro seconds creating objects, blink and its done, maybe .net is a half blink. 

 

So in the end its your choice.

 

0 Likes
Message 4 of 18

hak_vz
Advisor
Advisor

One of the main advances of Acad to other cad environments, that many users maybe don't realize,  its is command console and autolisp (visual lisp) built in it as a scripting language. That enables us to create simple scripts "on the fly" what's not possible with other provided languages (practically all compiled languages).  For more complex stuff there are .net and arx, that require previous  knowledge of programing in this languages, and working with windows environment. Of course there are attempts with pyton, javascript (nodejs) but all of this is in early stage of development.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 5 of 18

Sea-Haven
Mentor
Mentor

With the introduction of Dynamo into CIV3D is this the way Autodesk want us to go as another programming platform.

0 Likes
Message 6 of 18

sunlight1
Enthusiast
Enthusiast

@ВeekeeCZ  hi, tnx for the info. 

that what i though, lisp is the best language i should learn from the list there. 

however that article is from 2012. so there is no python in that list at all. 

 

@Sea-Haven tnx to u 2. 

im watching this forum for a long time. 

u dont need to convince me about lisp compare to other language (except from python) 

i know lisp is great.

but everytime i read the lisp, i dont understand whats going on. 

thats why i thought about python. this language is easy to understand. 

and myb even easier to learn. 

u said "Lisp becomes simpler once you get to understand it"  i think thats what i need to hear. 

because im scared that it takes me a long time to learn lisp, and even then,  i will have a hard time to express myself into the code.

Not because I do not know the technique ,but because the code is less readable and understandable.

 

i did a search on google about python and autocad, some ppl show how to make 3 circles in autocad. 

that is far from what i want. because its basics. 

thats why i have doubts on how python can be involved in autocad. 

and like u said "There is a few Python people out there asking questions"

they r only a few. 

 

As i write the response i thought that it might be better to go where everyone went before me, 

instead of starting a new path from zero. 

 

0 Likes
Message 7 of 18

Sea-Haven
Mentor
Mentor

I deal with private clients and the 1st question is write down a list of what your looking for, then I look at the list and if dont understand ask more questions, if I think I know what they want would put forward an explanation is this what you want.

 

You say lisp may be to simple but if you ask here there are plenty of skilled people who can advise if its a lisp or a .net type solution. So post a question, the answer may come back a fee will be required as its a so individual answer.

 

I am sure there are people out there using python with Autocad have seen posts. 

 

Is this what you looked at

How to write Python scripts for AutoCAD: Intro to the pyautocad module (supplychaindataanalytics.com...

 

The attached is a similar excel example where Excel controls Autocad. Using Activex or VBA examples I would expect python to use similar syntax. 

 

 

 

 

 

0 Likes
Message 8 of 18

sunlight1
Enthusiast
Enthusiast

@Sea-Haven  i saw that python link. 

thats what i said "some ppl show how to make 3 circles in autocad that is far from what i want. because its basics"

myb @hak_vz  is right and "all of this is in early stage of development" 

there is so many questions about the connection of python and autocad, that only time can answer. 

i think ill go with lisp,

ill search in the forum and start a self learning.

tnx a lot for ure answers 😃 

0 Likes
Message 9 of 18

Sea-Haven
Mentor
Mentor

Dont disgard it totally. Autocad can Shell external commands so could run a compiled python program then a script or a lisp that does something.

 

Again I ask what do you see as to hard maybe, some of my programs and others submitted here are 100's of lines long with maybe 20 sub functions inside. One package I co developed is 100+ lisps. Like others found out recently have some like 3000 lisps.

0 Likes
Message 10 of 18

sunlight1
Enthusiast
Enthusiast

Im not disgarding python, i know its great, thats why i came to ask about that from the 1st place.

and i was sure i want/need to learn on of them now. 

But im saying myb the connection with autocad and the community around it is to small ATM so if ill have questions and problems in the future, ill need to figure them out myself and work twice harder than in lisp area. 

which has large community and solution. 

and the proof is that i have not found many people who deal with both Python and AutoCAD and connect them together. except from 1-2 ppl on youtube that creating things that is far from my ambitions and the size of the work i want to get into. 

so that info and support is critical for me because im learning by my self. 

in my country i have no friends that know how to create/edit lisps, no FB group, and i think also no university courses.

so basictly i need to do all the work from 0. 

 

And yes, I know the size of the work. thats not scaring me. 

what did scared me is that lisp is not readable like python, but im sure ill know that in the future. 

like u said  "Lisp becomes simpler once you get to understand it"

 

 

0 Likes
Message 11 of 18

diagodose2009
Collaborator
Collaborator

You can develop Autol;isp in C# syntax,mathmatically0Lisp. Tu ai nevoi sa inveti un limbaj de programare, cu populaitate mare in mintile programatorilor, **** ari (Java,Delphi, C#). VLisp este foarte frumos doar la nivel de executie-prin intrepretare Lisp-Surse, la nivel de programator(eng. developer) nu prezinta un mare viitor cerute de Firme la angajare.

De aceea este bine sa inveti cateva limbaje de programare (C++ARx, C# sau Java sau php), cerute pe C.V-uri

Daca tu vrei sa inveti VLISP folosind ca syntaxa-gramaticala (C#,C+) atunci  tu vizioneaza filmul youtube.com-atasat.

 

 

 

 

0 Likes
Message 12 of 18

stevor
Collaborator
Collaborator

If you have plenty of free time, Python, or the C languages.

If you have lots of work,  in Autocad, then Autolisp.

S
0 Likes
Message 13 of 18

Sea-Haven
Mentor
Mentor

People who have a go are more likely to get behind the scenes help as well. So  don't be afraid to just ask for method rather than code. Lots of examples will be provided. Have a look at sites like Lee-mac.com lots of very useful functions.

0 Likes
Message 14 of 18

asak25
Community Visitor
Community Visitor

I used pyautocad and pyautogui libraries for cool staff.

0 Likes
Message 15 of 18

daniel_cadext
Advisor
Advisor

If your interested in using python and cad, I’ve been working on bindings for arx

https://github.com/CEXT-Dan/PyRx

 

check under releases for binaries to load in AutoCAD

 

it’s 100s of times faster than pyautocad, since pyautocad is run out of process

BTY, you can use the modules above to run pyautocad in process

 

I’ve posted some samples and thoughts as I progress here.

https://www.theswamp.org/index.php?board=76.0

 

AcDb, AcEd, AcGe, Palettes, Jigs, events are mostly wrapped  

 

The GUI is wxPython, so it’s possible to build rich GUIs.

 

Still a work in progress, but it’s quite usable now… looking for feedback from Python experts

On how to make it more “Pythonic” lol

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 16 of 18

daniel_cadext
Advisor
Advisor

this would be an example of extracting attributes into pandas

 

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
 
import traceback
import pandas as pd
 
def selectRef()->[Db.ObjectId]:
    ids = []
    entSetRes = Ed.Editor.entSel("\nSelectBlock: \n",Db.BlockReference.desc())
    if entSetRes[0] != Ed.PromptStatus.eNormal:
        raise Exception(entSetRes[0]) 
    ref = Db.BlockReference(entSetRes[1])
    btr = Db.BlockTableRecord(ref.blockTableRecord())
    return btr.getBlockReferenceIds()
    
def PyRxCmd_doit():
    try:
        data = {}
        for refId in selectRef():
            ref = Db.BlockReference(refId)
            for attid in ref.attributeIds():
                att = Db.AttributeReference(attid)
                tag = att.tag()
                if not tag in data:
                    data[tag] = [att.textString()]
                else:
                    data[tag].append(att.textString())
                    
        df = pd.DataFrame(data)        
        print(df)
       
    except Exception as err:
        traceback.print_exception(err)
        

.

out.png

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 17 of 18

asak25
Community Visitor
Community Visitor

Thank you for the reply. it would be good to see how this is used in AutoCAD

0 Likes
Message 18 of 18

daniel_cadext
Advisor
Advisor

Still need to work on installation and usage documentation.

There’s a small install readme on github, it’s a slight pain to install currently, you must install Python and wxPython yourself before installing the bundle. I hope to make it an all in one.

 

currently, it’s for more experienced users, or at least slightly familiar with. ARX and .NET APIs. Though you can run pyautoacad, but there’s no main, so you would need to run the code from a command context

 

using a sample from pyautoacad, PyRxCmd_ defines a command, similar to what ‘defun c:pyautoacad’ would do.

 

PyRxCmd_pyrx is more verbose, more like what you would find in ARX or .NET. I.e. having to open objects for read/write

 

Running pyautoacad from a command context is orders or magnitude faster because I’ve embedded CPython into an ARX module.

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
 
import traceback

from pyautocad import Autocad, APoint


#pyautoacad from a command context
def PyRxCmd_pyautoacad():
    try:
        acad = Autocad()
        acad.prompt("Hello, Autocad from Python\n")
        print(acad.doc.Name)

        p1 = APoint(0, 0)
        p2 = APoint(50, 25)
        for i in range(5):
            text = acad.model.AddText('Hi %s!' % i, p1, 2.5)
            acad.model.AddLine(p1, p2)
            acad.model.AddCircle(p1, 10)
            p1.y += 10
            
    except Exception as err:
        traceback.print_exception(err)
        

def PyRxCmd_pyrx():
    try:
        #calls acutPrintf
        print("Hello, Autocad from Python\n")
        
        #db = Db.curDb() or
        db = Db.HostApplicationServices().workingDatabase()
        model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite)
        
        p1 = Ge.Point3d(0,0,0)
        p2 = Ge.Point3d(50,25,0)
        
        #move to the right so we don't overlap pyautoacad
        p1 += (Ge.Vector3d.kXAxis * 100)
        p2 += (Ge.Vector3d.kXAxis * 100)
        
        for i in range(5):
            
            mt = Db.MText()
            mt.setLocation(p1)
            mt.setContents('PyHi %s!' % i)
            mt.setTextHeight(2.5)
            model.appendAcDbEntity(mt)
            
            line = Db.Line(p1, p2)
            model.appendAcDbEntity(line)
            
            circle = Db.Circle(p1,Ge.Vector3d.kZAxis, 10)
            model.appendAcDbEntity(circle)
            p1.y += 10
            
    except Exception as err:
        traceback.print_exception(err)
        

.

pyautocad.png

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes