xpr0 发表于 2022-7-5 17:10:02

Error : bad argument type: 2D/

hello everyone, i'm trying a lisp called branch to creat a takeoff for ducts.but the problem is that when i select the lines its giving me an Error : bad argument type: 2D/3D point: nil. plz help me.

(vl-load-com)(defun C:BD (/ ang1 ang2 ent1 ent2 ent3 ep1 ep3 ipt1 ipt2 ipt21   mp1 mp3 obj1 obj2 obj3 pt1 pt2 pt3 sp1 sp3)(setq ent1 (entsel "\nSelect first line >>")   ent2 (entsel "\nSelect second line >>")   ent3 (entsel "\nSelect third line >>")   obj1 (vlax-ename->vla-object (car ent1))   obj2 (vlax-ename->vla-object (car ent2))   obj3 (vlax-ename->vla-object (car ent3))   )(setq sp1(vlax-curve-getstartpoint obj1)   ep1(vlax-curve-getendpoint obj1)   mp1(mapcar (function (lambda (a b) (/ (+ a b) 2))) sp1 ep1)   sp3(vlax-curve-getstartpoint obj3)   ep3(vlax-curve-getendpoint obj3)   mp3(mapcar (function (lambda (a b) (/ (+ a b) 2))) sp3 ep3)   ipt1 (vlax-invoke obj1 'intersectwith obj3 0)   ipt2 (vlax-invoke obj2 'intersectwith obj3 0)   ang1 (angle ipt1 mp1)   ang2 (angle ipt2 ipt1)   pt1(polar ipt1 ang1 100)   pt2(polar ipt2 ang1 100)   pt3(polar ipt1 ang2 100)   )    (command "_.break" ent1 "f" "_non" pt1 "_non" ipt1)    (command "line" "_non" pt1 "_non" pt2 "")    (command "line" "_non" pt1 "_non" pt3 "")(princ))

Tharwat 发表于 2022-7-5 17:27:23

You need to be sure is that the first & the second lines selected should intersect with the third line.
Besides that, the three new variables that represents new coordinate points (pt1 , pt2 and pt3) should also be placed on the same curve object (line as in you example) to allow the command break slice them into tow pieces.

BIGAL 发表于 2022-7-5 17:32:38

The code reminded of the repetition in code, just me I try to use library defuns for consistency.
 

; library routine for midpoint of a line loaded at start up; note a pline need to use getpointatdist.(defun midptL (obj )(mapcar (function (lambda (a b) (/ (+ a b) 2)))(vlax-curve-getstartpoint obj) (vlax-curve-getendpoint obj)) ; mapcar) ; defun; using posted code(setq mp1 (midptL obj1))(setq mp3 (midptL obj3))

xpr0 发表于 2022-7-5 17:42:41

 
thanx tharwat.. now i know whats the problem.

xpr0 发表于 2022-7-5 17:58:44

 
thanx bigal for ur reply. i dont know anything about lisp writing. so i dont know how to use your code to solve the problem.

Tharwat 发表于 2022-7-5 18:08:23

 
Excellent, you are welcome.

BIGAL 发表于 2022-7-5 18:17:27

Xpr0 if you find your self when starting a code project that you need to repeat maybe 5-6 lines of code a lot you can make them a defun then you can generally just "CALL" them from 1 line through out the code. The example was to find the mid pt of a line or pline you add this defun to say Acaddoc.lsp then you only need (setq pt (midpt obj)) in your new code. As your code gets bigger 200 lines etc using little defuns saves a lot of typing time and reduces any typo errors.
 
The best example is http://www.lee-mac.com who has a vast library of useful little functions and you will see his defun code in lots of posts here.
页: [1]
查看完整版本: Error : bad argument type: 2D/