Lee Mac Posted March 23, 2009 Posted March 23, 2009 Hi Guys, I have a list of points to be used as vertices, such as: ((1.0 2.0 0.0) (2.0 3.0 0.0) (3.0 4.0 0.0)) Currently I am using the following code to create a polyline: (command "_pline") (foreach x vpts (command x)) (command "_C") However, I would like to use the vla-AddLightweightPolyline, so that I know how to use VL methods. But, I do not know how to specify the "array of doubles" from my list. Any help is much appreciated as always Cheers Lee Quote
CAB Posted March 23, 2009 Posted March 23, 2009 No doubles needed for this one: ;; by CAB 10/05/2007 ;; Expects pts to be a list of 2D or 3D points ;; Returns new pline object (defun makePline (spc pts) ;; flatten the point list to 2d (if (= (length (car pts)) 2) ; 2d point list (setq pts (apply 'append pts)) (setq pts (apply 'append (mapcar '(lambda (x) (list (car x) (cadr x))) pts))) ) (setq pts (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length pts)))) pts ) ) ) (vla-addlightweightpolyline spc pts) ) Quote
CAB Posted March 23, 2009 Posted March 23, 2009 Oops forgot the example for use: ;; usage example (vl-load-com) (setq Doc (vla-get-activedocument (vlax-get-acad-object))) (setq space (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) ; active VP (vla-get-paperspace doc) ) (vla-get-modelspace doc) ) ) (setq newpline (makePline space n1)) (vla-put-layer newpline <layerName>) ;;(vla-put-elevation newpline z) ;;(vla-put-Closed newpline :vlax-true) Quote
Lee Mac Posted March 23, 2009 Author Posted March 23, 2009 CAB, just another quick question, how do you make a safearray of objects? Say, for instance, I have two objects that I want to make into a safearray - is it specified the similar way that you would with doubles? Maybe: (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 1)) (list aObj bObj)) Cheers Lee Quote
Lee Mac Posted March 23, 2009 Author Posted March 23, 2009 Ahh, nevermind CAB - just missed the dot in (0 . 1)! Schoolboy error! Quote
Lee Mac Posted March 23, 2009 Author Posted March 23, 2009 Thanks for the help CAB, finally finished what I was working on! See here: http://www.cadtutor.net/forum/showthread.php?t=34107&page=2 Quote
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.