Jump to content

Recommended Posts

Posted

Lisp functions take a resbuf argument. A resbuf in python is a list of tuples  

Each tuple (Typed value) has a data type and a value, you can also use integers as ARX does

 

Rx.LispType:
    kAngle
    kDottedPair
    kDouble
    kInt16
    kInt32
    kListBegin
    kListEnd
    kNil
    kNone
    kObjectId
    kOrientation
    kPoint2d
    kVector2d
    kPoint3d
    kVector3d
    kT_atom
    kText
    kVoid
    kSelectionSet

 

you can also use integers as ARX does

 

#define RTNONE    5000 /* No result */
#define RTREAL    5001 /*Real number */
#define RTPOINT   5002 /* 2D point X and Y only */
#define RTSHORT   5003 /* Short integer */
#define RTANG     5004 /* Angle */
#define RTSTR     5005 /* String */
#define RTENAME   5006 /* Entity name */
#define RTPICKS   5007 /* Pick set */
#define RTORINT   5008 /* Orientation */
#define RT3DPOINT 5009 /* 3D point - X, Y, and Z */
#define RTLONG    5010 /* Long integer */
#define RTVOID    5014 /* Blank symbol */
#define RTLB      5016 /* list begin */
#define RTLE      5017 /* list end */
#define RTDOTE    5018 /* dotted pair */
#define RTNIL     5019 /* nil */
#define RTT       5021 /* T atom */
#define RTMODELESS 5027 /* interrupted by modeless dialog */

 

  • Like 1
Posted

Create a lisp function by using the “@Ap.LispFunction()”

 

example

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback

@Ap.LispFunction()
def lfunc(resbuf):
    try:
        #iterate the resbuf
        for type, value in resbuf:
            print(type, value)
            
        return resbuf
    except Exception as err:
        traceback.print_exception(err)
        
        

 

  • Like 1
Posted

maybe a useful example, check if two curves overlap

 

the lisp:

(defun c:doit (/ c1 c2)
  (setq c1 (car (entsel "pick curve 1\n")))
  (setq c2 (car (entsel "pick curve 2\n")))
  (check_overlap c1 c2)
)

 

the python

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback


@Ap.LispFunction()
def check_overlap(resbuf):
    try:
        cv1 = None
        cv2 = None

        # check the resbuf
        if len(resbuf) != 2:
            return None

        if resbuf[0][0] != Rx.LispType.kObjectId:
            return None

        if resbuf[1][0] != Rx.LispType.kObjectId:
            return None

        # get the geometry 
        dbc1 = Db.Curve(resbuf[0][1])
        cv1 = dbc1.getAcGeCurve()

        dbc2 = Db.Curve(resbuf[1][1])
        cv2 = dbc2.getAcGeCurve()

        # do the check
        cc = Ge.CurveCurveInt3d(cv1, cv2)
        return cc.overlapCount() > 0

    except Exception as err:
        traceback.print_exception(err)

 

and the results

 

result.png.e3b11d7e733cc9dfa5e36163d877c96a.png

  • Like 1
Posted

some examples of building list to return back to autolisp

 

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback


#return a list
@Ap.LispFunction()
def lfunc1(resbuf):
    try:

        buf = [
            (Rx.LispType.kPoint3d, Ge.Point3d(1, 0, 0)),
            (Rx.LispType.kPoint3d, Ge.Point3d(2, 0, 0)),
            (Rx.LispType.kPoint3d, Ge.Point3d(3, 0, 0)),
            (Rx.LispType.kPoint3d, Ge.Point3d(4, 0, 0)),
        ]
        return buf

    except Exception as err:
        traceback.print_exception(err)


# ((1.0 0.0 0.0) (2.0 0.0 0.0) (3.0 0.0 0.0) (4.0 0.0 0.0))

#return a nested list
@Ap.LispFunction()
def lfunc2(resbuf):
    try:

        buf = [
            
            (Rx.LispType.kListBegin, 0), # these must match
            (Rx.LispType.kPoint3d, Ge.Point3d(1, 0, 0)),
            (Rx.LispType.kPoint3d, Ge.Point3d(2, 0, 0)),
            (Rx.LispType.kListEnd, 0),
            
            (Rx.LispType.kListBegin, 0),
            (Rx.LispType.kPoint3d, Ge.Point3d(3, 0, 0)),
            (Rx.LispType.kPoint3d, Ge.Point3d(4, 0, 0)),
            (Rx.LispType.kListEnd, 0),
            
        ]
        return buf

    except Exception as err:
        traceback.print_exception(err)
        
# (((1.0 0.0 0.0) (2.0 0.0 0.0)) ((3.0 0.0 0.0) (4.0 0.0 0.0)))

 

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...