Results 1 to 8 of 8

Thread: Select closed lwpolyline, automatically select all lines within lwpolyline...

  1. #1
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    Default Select closed lwpolyline, automatically select all lines within lwpolyline...

    Hi there;
    I have just read through the ATP 67 notes by Peter and trying to write a code for a routine to select a closed lwpolyline and then automatically select all lines within the lwpolyline and calculate the intersection points.I am now trying to write a selection function using VL method but am facing an error which I could not solve. The attached code has an error in the program line "(print " d")(princ newsset)" when executed. Could anyone please enlighten me on this as I followed this code from Afralisp tutorial. Another question is that, how can we get the intersection points of the lwpolyline and the line if the lwpolyline and the line have different z- elevation values? It seems the method intersectwith is only valid for 2D values . Please enlighten.


    Code:
    ;
    ;subroutine dxf
    (defun dxf (code ename)
     (cdr (assoc code (entget ename)))
    ); dxf
    
    ;;================================================  ===========
    ;; C:WG-MP Routine to calculate area of sublots by picking only a closed LWpolyline
    ;;
    (defun C:WG-MP ( / 2pi e coords ss Total object)
     (vl-load-com)
       (setvar "errno" 0)
       (setq 2pi (* pi 2))
       (while (/= (getvar "errno") 52)
          (cond
    	((setq coords (@polydir (setq e (car (entsel "\nSelect a polyline: "))))) 
            (if coords
    	  (progn
    	    (print "here1")
    	    (entdel e)
    	    (print "coords ")(princ coords)
    ;using autolisp method
    	    (setq ss (ssget "CP" coords (quote ((0 . "LINE")))))
    	    (entdel e)
    	    (if ss 
                 (progn
                  (setq Total (sslength ss))
    	      (setq IntersectionPts-List (WG_VL-get-intersection-pts Total))
    	     );progn ss
                );if ss
    	  );progn coords
    	);if coords
    (prompt " using VL method")
    ;using VL method
    	(selectionVL)
    (print "selectionsets ")(princ selectionsets)
    	); 1st condition
          );cond
       );while
      (princ)
    );polydir
    
    ; To select objects using VL method
    (defun selectionVL()
      (setq activedocumentObj(vla-get-activedocument(vlax-get-acad-object)))
      (setq ssets (vla-get-selectionsets activedocumentObj))
      (setq newsset (vla-add ssets "SS1"))
    (print "d")(newsset)
      (setq filter_code (vlax-make-safearray vlax-vbinteger '(0.0)))
      (setq filter_value (vlax-make-safearray vlax-vbvariant '(0.0)))
      (vlax-safearray-fill filter_code '(0))
      (vlax-safearray-fill filter_value '("LINE"))
      (vla-selectONscreen newsset filter_code filter_value)
      (vla-delete(vla-item ssets "SS1"))
    );selectionVL
    
    (defun WG_VL-get-intersection-pts(Total / object2 iPts Pts L xy1 xy2)
              (setq L 0)
              (while (< L Total)
    	    (setq object2 (vlax-ename->vla-object
    	         	   (ssname ss L)
                              )
    ;             xy1 (vla-get-Coordinates object2)
    ;             xy2 (vla-get-EndPoint object2)
    	     ; find intersection of objects
                 iPts (vla-intersectwith object object2 0)
                 iPts (vlax-variant-value iPts)
                );setq
    ;(print "xy1 ")(princ xy1)
    ;(print "xy2 ")(princ xy2)
    	    
    	    (if (> (vlax-safearray-get-u-bound iPts 1) 0)
                 (progn
                  (setq iPts (vlax-safearray->list iPts))
                  (while (> (length iPts) 0)
                   (setq Pts (cons (list (car iPts)(cadr iPts)(caddr iPts)) Pts)
                      iPts (cdddr iPts)
                   )
                  );while
                 );progn
                );if
                (setq L (1+ L))
    	  );while < L total
    Pts
    );WG_VL-get-intersection-pts
    
    
      ;;-----------------------------------------------------------------------
       ;; This function returns the deflection angle (in radians) of two angles:
       ;;
       (defun @delta (a1 a2)
          (cond
             ((> a1 (+ a2 pi))
                (setq a2 (+ a2 2pi))
             )
             ((> a2 (+ a1 pi))
                (setq a1 (+ a1 2pi))
             )
          )
          (- a2 a1)
       );@delta
    
       ;;-------------------------------------------------------------
       ;; Function returns a list of 3D points from a continuous list
       ;; as returned by (vlax-safearray->list (vlax-variant-value X))
       ;;
       (defun @cv_parse_list (data n / item new)
          (foreach element (reverse data)
             (setq item (cons element item))
             (if (= (length item) n)
                (setq new (cons item new) item nil)
             )
          )
          new
       ); @cv_parse_list
    
    
       (defun @polydir (e / ent etype flag i p1 p2 p3 sum)
          (cond
             ((/= (type e) 'ENAME) 
               nil
             )
             ((not (vl-position (setq etype (dxf 0 e)) 
                    '("LWPOLYLINE")))
                (prompt (strcat " Object selected is a(n) " etype))
             )
             ((and (setq flag (dxf 70 e))(> (boole 1 16 flag) 0))
                (prompt " Object selected is a 3DMESH")
             )
             (1 (setq object (vlax-ename->vla-object e)
                      coords (vlax-get object "Coordinates")
                      coords (@cv_parse_list coords (if (= etype "LWPOLYLINE") 2 3))
                      i 1
                      sum 0.0
                )
                (and
                   flag
                   (= (logand 1 flag) 1) ; closed
                   (setq coords (reverse (cons (car coords)(reverse coords))))
                )
                (repeat (- (length coords) 2)
                   (setq p1  (nth (1- i) coords)
                         p2  (nth i coords)
                         i   (1+ i)
                         p3  (nth i coords)
                         sum (+ sum (@delta (angle p1 p2)(angle p2 p3)))
                   )
                )
    ;            (if (minusp sum) "CW" "CCW")
                (if (minusp sum) coords (reverse coords))
             );1
          );cond
       );@polydir
    Thanks

    csgoh
    5-3-05

  2. #2
    100 Club lance.81922's Avatar
    Join Date
    2005-01
    Location
    Santa Fe, NM
    Posts
    176
    Login to Give a bone
    0

    Default Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    Howdy -- the first thing I see is that you're trying to execute an undefined function: The line
    "(print "d")(newsset)" is calling a function [newsset] that isn't there! If your intent was for it to say
    "(print "d")" and then "(princ newsset)" like you said above, you will simply be printing the name of the selection set and not the set itself -- but you won't get the error.

    Next problem is the lines
    Code:
    (setq filter_code (vlax-make-safearray vlax-vbinteger '(0.0)))
      (setq filter_value (vlax-make-safearray vlax-vbvariant '(0.0)))
    Here you are using the number '(0.0) when you mean a dotted pair '(0 . 0). VL (or AutoLISP) needs to see those spaces to differentiate between a dotted pair and a number. Because you're defining a safearray, you need the dotted pair notation.

    Try fixing those things and keep going!

    Lance

  3. #3
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    Default Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    Thanks. Silly of me for misprinting and the dotted pair.
    Have tried to do further modifications on the selection sets. Shall ask for further help as I go along.
    However, I am rather confused with
    1) (vlax-get-property object "coordinates")
    2) (vlax-get object "coordinates")
    3) (vla-get-coordinates object)

    1) & 3) return you the variant whereas 2) would return the list of coordinates. The question is how can we differentiate which to use. Is there a general rule of thumb as to which function we should use as the help section sometimes do not show the functions.

    Thanks

    csgoh

  4. #4
    Member agmetzler's Avatar
    Join Date
    2004-07
    Posts
    9
    Login to Give a bone
    0

    Post Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    Quote Originally Posted by csgohjmj
    However, I am rather confused with
    1) (vlax-get-property object "coordinates")
    2) (vlax-get object "coordinates")
    3) (vla-get-coordinates object)

    1) & 3) return you the variant whereas 2) would return the list of coordinates. The question is how can we differentiate which to use. Is there a general rule of thumb as to which function we should use as the help section sometimes do not show the functions.
    csgoh
    Well I, personally do not have the time to explain the principals of "OOP" or "Object Oriented Programing", this what you are asking for in a nut shell. Here is what I can do, I have attached the Visual Lisp Developers Bible. It should be of more help than afralisp and the F1 key put together on the topic of Visual Lisp. A good understanding of VB/a would not hurt either for this subject filed under Lisp. I first started out with afralisp and found that alot of their tutorials have errors in them, so I went else where and found this.

    <AUGI Moderator - Action = On>
    Copyright material removed. Please respect the intellectual property of the Author.

    David Stein's Visual LISP Developer Bible can be found -

    http://www.dsxcad.com/

    Thanks for your understanding on this very serious matter,

    Mike

    Forum Moderator.
    <AUGI Moderator - Action = Off>
    Last edited by Mike.Perry; 2005-03-12 at 05:55 PM. Reason: Copyright material removed.

  5. #5
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    Default Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    Thanks.
    would look the bible as you suggested.

    csgoh

  6. #6
    Member agmetzler's Avatar
    Join Date
    2004-07
    Posts
    9
    Login to Give a bone
    0

    Red face Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    To all who read my earlier post (mainly the moderator), I apologize for the copy right thingy I did by mistake. It was my understanding that the author did not, and/or does not mind if one shares his work, seeing that he no longer is working with AutoLisp or Visual Lisp. I guess I made a boo boo, sorry!

  7. #7
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    Quote Originally Posted by agmetzler
    To all who read my earlier post (mainly the moderator), I apologize for the copy right thingy I did by mistake. It was my understanding that the author did not, and/or does not mind if one shares his work, seeing that he no longer is working with AutoLisp or Visual Lisp. I guess I made a boo boo, sorry!
    Hi Adam

    No worries, and no sorry required.

    I hope you can appreciate / understand AUGI can not take an chances when it comes to Copyright infringements / notices, therefore the action I took was nothing personal against yourself (plus the material is available directly from the authors web site).

    If an author has given their permission to freely share their work, no problem, but if in doubt it is always best to contact the author directly and ask.

    Thanks, Mike

    Forum Moderator

  8. #8
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Select closed lwpolyline, automatically select all lines within lwpolyline...

    Quote Originally Posted by csgohjmj
    However, I am rather confused with
    1) (vlax-get-property object "coordinates")
    2) (vlax-get object "coordinates")
    3) (vla-get-coordinates object)
    There isn't any "rule" about which to use. Pick a paradigm and stick with it. However, I should mention that the vlax-get statement is undocumented and therefore might be removed in future releases. (I seriously doubt it however, as Autodesk seems it will never do any more work on VLisp.) A couple of helper functions make working with options 1 and 3 almost as easy as easy as option 2.

Similar Threads

  1. Reshape of LWPOLYLINE
    By srinivasarajug in forum AutoLISP
    Replies: 1
    Last Post: 2014-06-26, 06:31 PM
  2. Replies: 4
    Last Post: 2007-09-12, 09:03 PM
  3. lwpolyline bulge
    By pnorman in forum AutoLISP
    Replies: 3
    Last Post: 2005-05-17, 04:59 PM

Posting Permissions

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