jbreard Posted March 6, 2016 Share Posted March 6, 2016 Hello, I'm having issues when trying to find the intersection between two lwpolylines using the following code : (vl-load-com) (defun c:intersect (/ curve1-ename curve2-ename curve1-obj curve2-obj c d) (setq curve1-ename (car (entsel "\nSelect first curve"))) (setq curve2-ename (car (entsel "\nSelect second curve"))) (setq curve1-obj (vlax-ename->vla-object curve1-ename)) (setq curve2-obj (vlax-ename->vla-object curve2-ename)) (setq c (vlax-variant-value (vlax-invoke-method curve1-obj "IntersectWith" curve2-obj acExtendnone ) ) ) (setq d (vl-catch-all-apply 'vlax-safearray->list (list c) ) ) (entmakex (list (cons 0 "POINT") (cons 8 "00-CONSTR7") (cons 10 (list (car d) (cadr d))) ) ) (princ) ) All my lwpolylines have an elevation of 0 so this is not the issue. In the attached file, you will see small polyline in a blue revision cloud that apparently do not intersect the white polyline on layer "AXE-REF-PK" (but they obviously do ; an error of the type : "ActiveX Server returned an error : invalid index" is generated). This polyline has 1900+ vertexes so maybe there is a limitation that comes with the size. I have drawn above the exact same situation but with a poyline with half the vertexes. This time, the program finds an intersection everytime. There sure are many things I don't get with the intersectwith method Does someone has ever encounter a similar problem ? Regards, Jacques Intersectwith Method Issue.dwg Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 6, 2016 Share Posted March 6, 2016 The intersectwith method can be temperamental if the objects are far from the origin - try the following code instead: (defun c:inters ( / lst ob1 ob2 vec ) (if (and (setq ob1 (car (entsel "\nSelect 1st curve: "))) (setq ob2 (car (entsel "\nSelect 2nd curve: "))) (setq ob1 (vlax-ename->vla-object ob1)) (setq ob2 (vlax-ename->vla-object ob2)) ) (if (or (setq lst (group3 (vlax-invoke ob1 'intersectwith ob2 acextendnone))) ( (lambda ( vec / ob3 ob4 ) (vla-move (setq ob3 (vla-copy ob1)) (vlax-3D-point vec) (vlax-3D-point 0 0)) (vla-move (setq ob4 (vla-copy ob2)) (vlax-3D-point vec) (vlax-3D-point 0 0)) (setq lst (group3 (vlax-invoke ob3 'intersectwith ob4 acextendnone)) lst (mapcar '(lambda ( x ) (mapcar '+ x vec)) lst) ) (vla-delete ob3) (vla-delete ob4) lst ) (vlax-curve-getstartpoint ob1) ) ) (foreach pnt lst (entmake (list '(0 . "POINT") '(8 . "00-CONSTR7") (cons 10 pnt)))) (princ "\nNo intersection detected.") ) ) (princ) ) (defun group3 ( lst / rtn ) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst) ) ) (reverse rtn) ) (vl-load-com) (princ) Also, I would advise against defining intersect as a custom command, as this is already a built-in AutoCAD command. Quote Link to comment Share on other sites More sharing options...
jbreard Posted March 6, 2016 Author Share Posted March 6, 2016 Thanks a lot Lee Mac ! Works like a charm. I will keep in mind that AutoCAD can have problems with typical geographical coordinates values. As for the intersect built-in command, I was not trying to emulate it. I actually need to be able to find the intersection between two polylines inside a larger lisp programm and your method does the job perfectly. And I managed to set eyes on news commands like vla-move ! Thanks again and best regards, Jacques Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 6, 2016 Share Posted March 6, 2016 You're welcome! - I'm glad the function is now performing well. I'm aware that you were not trying to emulate the built-in AutoCAD command, but you should refrain from using the names of built-in commands as AutoLISP custom commands. Quote Link to comment Share on other sites More sharing options...
jbreard Posted March 7, 2016 Author Share Posted March 7, 2016 Ah ok. I understand now the true meaning of your comment. I will not do it in the future ! Thanks again. Jacques Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.