Results 1 to 3 of 3

Thread: Processing a selection set of LightWeight Polylines to provide midpoints

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2007-04
    Posts
    1
    Login to Give a bone
    0

    Question Processing a selection set of LightWeight Polylines to provide midpoints

    I cant seem to pass in any way a selection set for each polyline to place a point at the midpoint of a each polyline?
    Its driving me nuts, I have tried modifying the origianal code to select the list and process that way but it still isnt working

    Code:
    (defun c:MidPoly ( / ent ename entl en oname param len hLen MidPt OS )
     (vl-load-com)
     (setq ent (entsel "\nSelect polyline:"))
    	(if ent
    		(progn
    			(setq	ename (car ent)
    					entl (entget ename)
    					en (cdr (assoc 0 entl))
    			)
    			(if (member en (list "POLYLINE" "LWPOLYLINE"))
    				(progn
    					(setq	oname (vlax-ename->vla-object ename)
    							param (vlax-curve-getEndParam oname)
    							len (vlax-curve-getDistAtParam oname param)
    							hLen (* 0.5 len)
    							MidPt (vlax-curve-getPointAtDist oname hLen)
    					)
    					(vlax-release-object oname)
    					(setq OS (getvar "OSMODE"))
    					(setvar "OSMODE" 0)
    					(command "._Point" MidPt)
    					(princ "\nPoint object created at mid-point:")(princ MidPt)
    					(setvar "OSMODE" OS)
    				)
    				(princ "\nYou must pick a polyline object only.")
    				
    			)
    		)
    	)
    (prin1)
    )
    (defun c:test1 ( / e i s x )
        (if (setq s (ssget "_X" (list (cons 8 "MGA55_ROW_Stripping_Depth") (cons 0 "LWPOLYLINE"))))
            (progn
                (setq i (1- (sslength s)))
                (while (<= 0 i)
                    (setq e (ssname s i)
                          x (cdr (assoc 0 (entget e)))
                          i (1- i)
                    )
    				(command "(c:MIDPOLY)" e)
                    (print x)
                )
            )
        )
        (princ)
    )
    (defun c:test2 ( / e i s x )
        (if (setq s (ssget "_X" (list (cons 8 "MGA55_ROW_Stripping_Depth") (cons 0 "LWPOLYLINE"))))
            (progn
                (setq i 0)
                (repeat (sslength s)
                    (setq e (ssname s i)
                          x (cdr (assoc 0 (entget e)))
                          i (1+ i)
                    )
    				(command "(c:MIDPOLY)" e)
                    (print x)
                )
            )
        )
        (princ)
    )
    (defun c:test3 ( / s )
        (if (setq s (ssget "_X" (list (cons 8 "MGA55_ROW_Stripping_Depth") (cons 0 "LWPOLYLINE"))))
            (foreach e (ssnamex s)
                (if (= 'ename (type (cadr e)))
                    (command "(c:MIDPOLY)" (cdr (assoc 0 (entget (cadr e)))))
                )
            )
        )
        (princ)
    )
    (defun c:test4 ( / e s )
        (if (setq s (ssget "_X" (list (cons 8 "MGA55_ROW_Stripping_Depth") (cons 0 "LWPOLYLINE"))))
            (while (setq e (ssname s 0))
                (print (cdr (assoc 0 (entget e))))
    			(setq x (cdr (assoc 0 (entget e))))
    			(command "(c:MIDPOLY)" e)
                (ssdel e s)
            )
        )
        (princ)
    )
    
    
    I also want to do the same for Lines using this
    (defun c:MIDLINE ( / ent nPt p2 p1 )
    	(if (setq ent (car (entsel "\nSelect line:")))
    		(progn
    			(setq	p1 (cdr (assoc 10 (entget ent)))
    					p2 (cdr (assoc 11 (entget ent)))
    			)
    			(setq npt (Line-centroid p1 p2))
    			(setq OS (getvar "OSMODE"))
    			(setvar "OSMODE" 0)
    			(command "._Point" nPt)
    			(princ "\nPoint object created at mid-point:")(princ nPt)
    			(setvar "OSMODE" OS)
    		)
    	)
    )
    
    (defun Line-centroid (p1 p2)
    (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.0)) p1 p2)
    )
    Last edited by Wanderer; 2018-06-06 at 12:42 PM. Reason: edited to add code tags

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Processing a selection set of LightWeight Polylines to provide midpoints

    Code:
    (defun c:midcurves ( / ss i e l p )
    
      (vl-load-com)
    
      (while
        (or
          (prompt "\nSelect curve entities...")
          (not (setq ss (ssget '((0 . "*POLYLINE,ARC,CIRCLE,ELLIPSE,SPLINE,HELIX,LINE")))))
        )
        (prompt "\nEmpty sel.set...")
      )
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i))))
        (setq l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
        (setq p (vlax-curve-getpointatdist e (/ l 2.0)))
        (entmake (list '(0 . "POINT") (cons 10 p)))
      )
      (princ)
    )
    HTH., M.R.

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: Processing a selection set of LightWeight Polylines to provide midpoints

    Also over at Cadtutor two posts with various offerings.

Similar Threads

  1. Replies: 7
    Last Post: 2018-04-07, 01:26 AM
  2. Replies: 0
    Last Post: 2016-11-21, 05:02 AM
  3. Lightweight lights, still looking
    By ron.sanpedro in forum Revit Architecture - Families
    Replies: 2
    Last Post: 2007-01-25, 02:22 AM
  4. Replies: 9
    Last Post: 2005-11-02, 01:09 PM
  5. Lightweight 2D Sanitaryware
    By Damo in forum Revit Architecture - Families
    Replies: 2
    Last Post: 2004-11-18, 10:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •