George Duls Posted January 30, 2009 Share Posted January 30, 2009 Hello! (me again ) I'll do my best to explane my problem. Intersection between line and arc is my problem, and I've got a kind of solution but it's not very good. I will try to write with the code and make my self more clear. (defun dtr (x) (* pi (/ x 180.0)) ) (defun c:ninja-app () (setq line (entget (car (entsel "Line?")))) (setq line-sp (cdr (assoc 10 line))) (setq line-ep (cdr (assoc 11 line))) I select a line, and take the start and the end point. (setq arc (car (entsel "Arc?"))) I select an arc and prepare it for VLAX commands (setq line-angle (angle line-sp line-ep)) I get the angle of the line (for POLAR command later) (setq line-distance 0) Setting this var to 0 so I can add that 0.000001 to it (while (= distance nil) (setq line-distance (+ line-distance 0.000001)) (setq line-point (polar line-sp line-angle line-distance)) (setq distance (vlax-curve-getdistatpoint arc line-point)) (if (> line-distance (distance profil-sp profil-ep)) (exit)) ) In this loop I am trying to "scan" a line point by point and with (vlax-curve-getdistatpoint) hoping to find the intersection (and distance) point. But even with this small step (0.0000001) I sometimes fail to find it. This could be simple if I could make the precision (like 1.235685=1.24) smaller (or something like that) but I am lost, and even don't know am I on the right path here. I hope I made my self clear enough (i know my explaining sucks big time). ThankYou very much! Greetings! Danko. Quote Link to comment Share on other sites More sharing options...
CarlB Posted January 30, 2009 Share Posted January 30, 2009 Check out the function "vla-intersectwith", should save you a lot of code. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 30, 2009 Share Posted January 30, 2009 This may help you: ; Ints ~ by Lee McDonnell ; 2 Arg Input: ; cEnt VL Object ; dEnt VL Object ; Return: ; Point of Intersection (defun Ints (cEnt dEnt) (alert (vl-princ-to-string (vlax-safearray->list (vlax-variant-value (vla-IntersectWith cEnt dEnt acExtendNone))))) (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 30, 2009 Share Posted January 30, 2009 Haha, Carl you just beat me to it Quote Link to comment Share on other sites More sharing options...
CarlB Posted January 30, 2009 Share Posted January 30, 2009 OK found link to example code: http://management.cadalyst.com/cadman/article/articleDetail.jsp?id=101854 (Lee's is a good start...) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 30, 2009 Share Posted January 30, 2009 (Lee's is a good start...) Cheers Carl, and nice link - very informative, thanks. Quote Link to comment Share on other sites More sharing options...
CAB Posted January 30, 2009 Share Posted January 30, 2009 Another way: (setq p1 (vlax-invoke line1 'IntersectWith cir acExtendNone)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 30, 2009 Share Posted January 30, 2009 CAB, I have seen "vlax-invoke-method" but I didn't know that you could just use "vlax-invoke". Just out of interest, is the return a variant? or does it return the point straight off? Thanks as always Lee Quote Link to comment Share on other sites More sharing options...
CAB Posted January 30, 2009 Share Posted January 30, 2009 It returns a point list. Quote Link to comment Share on other sites More sharing options...
CAB Posted January 30, 2009 Share Posted January 30, 2009 These use & return standard points vlax-invoke obj ' vlax-put- obj vlax-get- obj (setq pt (vlax-invoke (vlax-ename->vla-object e1) 'IntersectWith (vlax-ename->vla-object e2) acExtendNone)) ================================== These use & return variant points vlax-invoke-method vlax-put-property vlax-get-property (setq pt (vlax-safearray->list (vlax-variant-value (vlax-invoke-method (vlax-ename->vla-object e1) 'IntersectWith (vlax-ename->vla-object e2) acExtendNone)))) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 30, 2009 Share Posted January 30, 2009 Many thanks to you CAB, I am gradually understanding more of Visual LISP. My preferred method still remains as Common LISP and messing around with DXF Tables, but once I am confident in VL, I am sure things will be a lot easier to manipulate. Thanks once again for your patience and explanations, both are much appreciated. Cheers Lee Quote Link to comment Share on other sites More sharing options...
CAB Posted January 31, 2009 Share Posted January 31, 2009 Any time Lee. Quote Link to comment Share on other sites More sharing options...
George Duls Posted January 31, 2009 Author Share Posted January 31, 2009 ThankYou, I didn't know about (vla-intersectwith) I am not in VL but I see I should try it. (it is very confusing to me like AL once was and is still in some moments ) Greetings. p.s. I know I will confuse myself again with this VL, ActiveX (I don't have a clue about it) variant, ACExtendNone, data conversion and so on. I don't have a clue about anything here, but I will learn. TNX Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 31, 2009 Share Posted January 31, 2009 No problem George, Glad we could help somewhat - I am still learning VL myself Cheers Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 31, 2009 Share Posted January 31, 2009 Based on the link from Carl, I rewrote the intersection LISP: (defun ssInter (ss / i y Ent1 Ent2 iArr iLst) (setq i (sslength ss)) (while (not (minusp (setq y (1- i) i (1- i)))) (setq Ent1 (vlax-ename->vla-object (ssname ss i))) (while (not (minusp (setq y (1- y)))) (setq Ent2 (vlax-ename->vla-object (ssname ss y)) iArr (vlax-variant-value (vla-IntersectWith Ent1 Ent2 acExtendNone))) (if (> (vlax-safearray-get-u-bound iArr 1) 0) (progn (setq iLst (vlax-safearray->list iArr)) (while (not (zerop (length iLst))) (setq ptLst (cons (list (car iLst) (cadr iLst) (caddr iLst)) ptLst) iLst (cdddr iLst)))))))) (defun c:test (/ ptLst) (vl-load-com) (ssInter (ssget)) (alert (vl-princ-to-string ptLst)) (princ)) (*complete with tester program*) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 31, 2009 Share Posted January 31, 2009 Another way: (defun ssInter (ss / vLst i j obj1 obj2 iArr iLst) (setq vLst (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) i (length vLst)) (while (not (minusp (setq j (1- i) i (1- i)))) (setq obj1 (nth i vLst)) (while (not (minusp (setq j (1- j)))) (setq obj2 (nth j vLst) iArr (vlax-variant-value (vla-IntersectWith obj1 obj2 acExtendNone))) (if (> (vlax-safearray-get-u-bound iArr 1) 0) (progn (setq iLst (vlax-safearray->list iArr)) (while (not (zerop (length iLst))) (setq ptLst (cons (list (car iLst) (cadr iLst) (caddr iLst)) ptLst) iLst (cdddr iLst)))))))) (defun c:test (/ ptLst) (vl-load-com) (ssInter (ssget)) (alert (vl-princ-to-string ptLst)) (princ)) Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 26, 2009 Share Posted August 26, 2009 I just wanted to say that this thread is proving very informative. Great forum! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 26, 2009 Share Posted August 26, 2009 This thread seems like ages ago now! Glad you could take something from it 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.