Jump to content

Recommended Posts

  • Replies 84
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    35

  • cabltv1

    22

  • The Buzzard

    20

  • rami_9630

    5

Top Posters In This Topic

Posted Images

Posted
You might find something here of interest:

 

http://www.cadtutor.net/forum/showthread.php?t=45820

 

Thanks alot Lee ! we are lucky to have you here , the code is exactly what i was looking for , but i just wonder about little thing, how can i have it work with pline, what im doing now is exploding pline to convert it to line though i guess there is better way to handle this.

Posted

I shall have a look when I get a minute, and see what I can come up with :)

Posted

I'm not sure if this is what you are after? A slight bug if the Polyline vertex lies inside the break radius, but its a start:

 

(defun c:Jumper ( / GroupByNum SS->VLA MakeSafearrayVariant
                   GetIntersectionsinSS CurveifFoo
                   2DPointList AddItemsatIndexes GetBoundingBox

                   B1 B2 BBOX BRAD COORDS D E ENT I ILST
                   INDEXES ITEMS LST MODE OBJ P1 P2 SS )
 (vl-load-com)
 ;; Lee Mac  ~  28.04.10

 (setq bRad 1.0)

 (defun GroupByNum (lst num / rtn)
   (setq rtn nil)
   
   (if lst
     (cons
       (reverse
         (repeat num
           (progn
             (setq rtn (cons (car lst) rtn)
                   lst (cdr lst))
             rtn
           )
         )
       )
       (GroupByNum lst num)
     )
   )
 )

 (defun SS->VLA ( ss / e lst )
   (
      (lambda ( i )
        (while (setq e (ssname ss (setq i (1+ i))))
          (setq lst (cons (vlax-ename->vla-object e) lst))
        )
      )
     -1
   )
 )

 (defun MakeSafeArrayVariant ( datatype data )
   (vlax-make-variant
     (vlax-safearray-fill
       (vlax-make-safearray (eval datatype)
         (cons 1 (length data))
       )
       data
     )
   )
 )
         
 (defun GetIntersectionsinSS ( ss obj mode )

   (apply (function append)
     (vl-remove-if (function null)
       (mapcar
         (function
           (lambda ( object )
             (GroupByNum
               (vlax-invoke object
                 'IntersectWith obj (eval mode)
               )
               3
             )
           )
         )
         (SS->VLA ss)
       )
     )
   )
 )

 (defun CurveifFoo ( foo str / sel ent )
   (while
     (progn
       (setq sel (entsel str))
       
       (cond
         ( (vl-consp sel)

           (if (not (foo (setq ent (car sel))))
             (princ "\n** Invalid Object Selected **")
           )
         )
       )
     )
   )
   ent
 )

 (defun 2DPointList ( lst )
   (mapcar
     (function
       (lambda ( point )
         (list (car point) (cadr point))
       )
     )
     lst
   )
 )

 (defun AddItemsatIndexes ( lst items indexes )
   (apply (function append)
     (
       (lambda ( i )
         (mapcar
           (function
             (lambda ( x / p )
               (if (setq p (vl-position (setq i (1+ i)) indexes))
                 (append (nth p items) (list x))
                 (list x)
               )
             )
           )
           lst
         )
       )
       -1
     )
   )
 )

 (defun GetBoundingBox ( obj / ll ur )
   (if (vlax-method-applicable-p obj 'GetBoundingBox)
     (progn
       (vla-getBoundingBox obj 'll 'ur)
       (mapcar (function vlax-safearray->list) (list ll ur))
     )
   )
 )

 (if
   (and
     (setq ent
       (CurveIfFoo
         (lambda ( x )
           (eq "LWPOLYLINE" (cdr (assoc 0 (entget x))))
         )
         "\nSelect LWPolyline: "
       )
     )
     (setq obj (vlax-ename->vla-object ent))
     (setq bbox
       (mapcar
         (function
           (lambda ( p )
             (trans p 0 1)
           )
         )
         (GetBoundingBox obj)
       )
     )
     (setq ss   (ssget "_C" (cadr bbox) (car bbox)))
     (setq iLst
       (GetInterSectionsinSS
         (ssdel ent ss) obj acExtendNone
       )
     )
   )
   (progn
     (setq Coords
       (GroupByNum
         (vlax-safearray->list
           (vlax-variant-value
             (vla-get-Coordinates obj)
           )
         )
         2
       )
     )
     (foreach int iLst
       (setq d (vlax-curve-getDistatPoint ent int))
       (if
         (and
           (setq b1 (vlax-curve-getPointatDist ent (- d bRad)))
           (setq b2 (vlax-curve-getPointatDist ent (+ d bRad)))
         )
         (if (= (setq p1 (1+ (fix (vlax-curve-getParamatPoint ent b1))))
                (setq p2 (1+ (fix (vlax-curve-getParamatPoint ent b2)))))
         
           (setq items   (cons (list b1 b2) items)
                 indexes (cons p1 indexes))
         
           (setq items   (cons (list b2) (cons (list b1) items))
                 indexes (cons p2 (cons p1 indexes)))
         )
       )
     )

     (setq Coords
       (AddItemsAtIndexes Coords
         (reverse Items) (reverse Indexes)
       )
     )

     (vla-put-Coordinates obj
       (MakeSafeArrayVariant vlax-vbDouble
         (apply (function append)
           (2DPointList Coords)
         )
       )
     )

     (vla-Update obj)

     (mapcar
       (function
         (lambda ( intersection )
           (vla-SetBulge obj
             (fix
               (vlax-curve-getParamatPoint ent intersection)
             )
             1.
           )
         )
       )
       iLst
     )       
   )
 )
 
 (princ)
)

Posted
I'm not sure if this is what you are after? A slight bug if the Polyline vertex lies inside the break radius, but its a start:

 

(defun c:Jumper ( / GroupByNum SS->VLA MakeSafearrayVariant
                   GetIntersectionsinSS CurveifFoo
                   2DPointList AddItemsatIndexes GetBoundingBox

                   B1 B2 BBOX BRAD COORDS D E ENT I ILST
                   INDEXES ITEMS LST MODE OBJ P1 P2 SS )
 (vl-load-com)
 ;; Lee Mac  ~  28.04.10

 (setq bRad 1.0)

 (defun GroupByNum (lst num / rtn)
   (setq rtn nil)
   
   (if lst
     (cons
       (reverse
         (repeat num
           (progn
             (setq rtn (cons (car lst) rtn)
                   lst (cdr lst))
             rtn
           )
         )
       )
       (GroupByNum lst num)
     )
   )
 )

 (defun SS->VLA ( ss / e lst )
   (
      (lambda ( i )
        (while (setq e (ssname ss (setq i (1+ i))))
          (setq lst (cons (vlax-ename->vla-object e) lst))
        )
      )
     -1
   )
 )

 (defun MakeSafeArrayVariant ( datatype data )
   (vlax-make-variant
     (vlax-safearray-fill
       (vlax-make-safearray (eval datatype)
         (cons 1 (length data))
       )
       data
     )
   )
 )
         
 (defun GetIntersectionsinSS ( ss obj mode )

   (apply (function append)
     (vl-remove-if (function null)
       (mapcar
         (function
           (lambda ( object )
             (GroupByNum
               (vlax-invoke object
                 'IntersectWith obj (eval mode)
               )
               3
             )
           )
         )
         (SS->VLA ss)
       )
     )
   )
 )

 (defun CurveifFoo ( foo str / sel ent )
   (while
     (progn
       (setq sel (entsel str))
       
       (cond
         ( (vl-consp sel)

           (if (not (foo (setq ent (car sel))))
             (princ "\n** Invalid Object Selected **")
           )
         )
       )
     )
   )
   ent
 )

 (defun 2DPointList ( lst )
   (mapcar
     (function
       (lambda ( point )
         (list (car point) (cadr point))
       )
     )
     lst
   )
 )

 (defun AddItemsatIndexes ( lst items indexes )
   (apply (function append)
     (
       (lambda ( i )
         (mapcar
           (function
             (lambda ( x / p )
               (if (setq p (vl-position (setq i (1+ i)) indexes))
                 (append (nth p items) (list x))
                 (list x)
               )
             )
           )
           lst
         )
       )
       -1
     )
   )
 )

 (defun GetBoundingBox ( obj / ll ur )
   (if (vlax-method-applicable-p obj 'GetBoundingBox)
     (progn
       (vla-getBoundingBox obj 'll 'ur)
       (mapcar (function vlax-safearray->list) (list ll ur))
     )
   )
 )

 (if
   (and
     (setq ent
       (CurveIfFoo
         (lambda ( x )
           (eq "LWPOLYLINE" (cdr (assoc 0 (entget x))))
         )
         "\nSelect LWPolyline: "
       )
     )
     (setq obj (vlax-ename->vla-object ent))
     (setq bbox
       (mapcar
         (function
           (lambda ( p )
             (trans p 0 1)
           )
         )
         (GetBoundingBox obj)
       )
     )
     (setq ss   (ssget "_C" (cadr bbox) (car bbox)))
     (setq iLst
       (GetInterSectionsinSS
         (ssdel ent ss) obj acExtendNone
       )
     )
   )
   (progn
     (setq Coords
       (GroupByNum
         (vlax-safearray->list
           (vlax-variant-value
             (vla-get-Coordinates obj)
           )
         )
         2
       )
     )
     (foreach int iLst
       (setq d (vlax-curve-getDistatPoint ent int))
       (if
         (and
           (setq b1 (vlax-curve-getPointatDist ent (- d bRad)))
           (setq b2 (vlax-curve-getPointatDist ent (+ d bRad)))
         )
         (if (= (setq p1 (1+ (fix (vlax-curve-getParamatPoint ent b1))))
                (setq p2 (1+ (fix (vlax-curve-getParamatPoint ent b2)))))
         
           (setq items   (cons (list b1 b2) items)
                 indexes (cons p1 indexes))
         
           (setq items   (cons (list b2) (cons (list b1) items))
                 indexes (cons p2 (cons p1 indexes)))
         )
       )
     )

     (setq Coords
       (AddItemsAtIndexes Coords
         (reverse Items) (reverse Indexes)
       )
     )

     (vla-put-Coordinates obj
       (MakeSafeArrayVariant vlax-vbDouble
         (apply (function append)
           (2DPointList Coords)
         )
       )
     )

     (vla-Update obj)

     (mapcar
       (function
         (lambda ( intersection )
           (vla-SetBulge obj
             (fix
               (vlax-curve-getParamatPoint ent intersection)
             )
             1.
           )
         )
       )
       iLst
     )       
   )
 )
 
 (princ)
)

 

mmm, ya , there is a little issue with the code but seems promising

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