Jump to content

vla-AddLightWeightPolyline


Lee Mac

Recommended Posts

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

Link to comment
Share on other sites

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)
 )

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...