Is it possible to get the distance between vlax-3d-points (not simple AutLISP points) by using something like:
(distance vlax-3d-point1 vlax-3d-point2)
or
(vla-GetDistance vlax-3d-point1 vlax-3d-point2) ?
The whole geometry should be built with ActiveX, like vlax-3d-points -> vla-AddLine to speed up calculation and get the following code working...
(vl-load-com) (defun c:rdline (/ bw r1 r2 pt1 pt2 dbp) (setq acadObj (vlax-get-acad-object) c_doc (vla-get-Activedocument acadObj) modelSpace (vla-get-ModelSpace c_doc) ) (setq bw 100 ;box width r1 (* (LM:rand) bw) r2 (* (LM:rand) bw) pt1 (vlax-3d-point 0 r1 0) pt2 (vlax-3d-point bw r2 0) ) (setq lineObj (vla-AddLine modelSpace pt1 pt2)) ;line from random points (setq dbp (distance pt1 pt2)) ;distance between points (princ (strcat "\nDistance between points:" (rtos dbp 2 4)) ) (princ) ) (defun LM:rand (/ a c m) (setq m 4294967296.0 a 1664525.0 c 1013904223.0 $xn (rem (+ c (* a (cond ($xn) ((getvar 'date)) ) ) ) m ) ) (/ $xn m) )
Solved! Go to Solution.
Solved by ronjonp. Go to Solution.
Call addline like this:
;; Don't need vlax-3d-point (vlax-invoke modelSpace 'addline pt1 pt2)
And set your points like so:
(setq bw 100. ;box width r1 (* (LM:rand) bw) r2 (* (LM:rand) bw) pt1 (list 0. r1 0.) pt2 (list bw r2 0.) )
Or even simpler, use entmakex:
(entmakex (list '(0 . "line") (cons 10 pt1) (cons 11 pt2)))
If you use the addline method, you will also need to convert all the integers within the list to reals .. with entmakex, it does not matter:
And if you want to use DISTANCE with VLAX-3D-POINT you'll need to convert them back to a list like so.
(distance (vlax-safearray->list (vlax-variant-value (vlax-3d-point 0. 0. 0.))) (vlax-safearray->list (vlax-variant-value (vlax-3d-point 8. 8. 8.))) )
The entmakex method works fine but 'addline doesn't?
I simplified the example without using random variables, but it returns neither line nor distance?
(vl-load-com) (defun c:addline (/ pt1 pt2 lineObj dbp) (setq acadObj (vlax-get-acad-object) c_doc (vla-get-Activedocument acadObj) modelSpace (vla-get-ModelSpace c_doc) ) (setq pt1 (list 100 100 0) pt2 (list 0 0 0) ) (setq lineObj (vlax-invoke modelSpace 'addline pt1 pt2) dbp (distance pt1 pt2) ) ;line / distance between points (princ (strcat "\nDistance between points:" (rtos dbp 2 4)) ) (princ) )
I did not see the end of your message at first sight. Just changed integers to reals and now 'addline is working.
Sorry for that...
Perhaps a consideration could be to retrieve the Length of your line rather than distance between points? I am not sure which would be faster, but in my head it makes more sense to grab an existing property than to calculate distance with geom/trig.
(setq dbp (vla-get-Length lineObj))
Just a thought.
Best,
~DD
Can't find what you're looking for? Ask the community or share your knowledge.