Author Topic: How to fillet a polyline using ActiveX  (Read 3188 times)

0 Members and 1 Guest are viewing this topic.

kenkrupa

  • Newt
  • Posts: 84
How to fillet a polyline using ActiveX
« on: August 10, 2010, 08:54:47 PM »
What I need to do is create a polyline (say a closed rectangle) and then fillet the corners - like using the Fillet command "P" option. But I need to do this in a reactor, so can't use a command. Anyone got anything for this? (I can create the rectangle no problem - I "just" need to add the fillets.)

fixo

  • Guest
Re: How to fillet a polyline using ActiveX
« Reply #1 on: August 11, 2010, 03:18:50 AM »
You need calculate of the points previously
then calculate all values of bulges and then
create this polyline after

IMO

~'J'~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to fillet a polyline using ActiveX
« Reply #2 on: August 11, 2010, 06:28:17 AM »
Something to play with.
Note the  move offset and the rotation option

Change the vars to suit.
perhaps step through in the VLIDE debugger to see what's happening
... enjoy

Code: [Select]

(vl-load-com)

;;;------------------------------------------------------------------
;;;

(defun c:doit () ; leave vars global for testing
  ;;
  ;; CodeHimBelonga kdub@theSwamp 2010.08.11
  ;; establish some testing variables
  ;;
  (setq h          100.0                     ; height
        w          200.0                     ; width
        r          20.0                      ; radius
        ll-offset  (list 500. 500. 100.)     ; lowLeftCorner offset 3D point, expressed in terms of the current UCS.
                                             ; similar to getpoint result
        ;; ang        0.0                       ; rotation angle in Radians
        ang        (* pi 0.25)           ; rotation angle in Radians
        arcbulge90 (kdub:tan (* pi 0.5 0.25)); bulge factor for 90 deg internal corner
        origin     (list 0. 0. 0.)
  )
  (setq RotationMatrix (list (list (cos ang) (- (sin ang)) 0.0)
                             (list (sin ang) (cos ang) 0.0)
                             (list 0.0 0.0 1.0)
                       )
  )
  (setq VertexList (list (list r 0. 0.)
                         (list (- w r) 0. 0.)
                         (list w r 0.)
                         (list w (- h r) 0.)
                         (list (- w r) h 0.)
                         (list r h 0.)
                         (list 0. (- h r) 0.)
                         (list 0. r 0.)
                   )
  )
  (setq outline (vlax-ename->vla-object
                  (setq ent (kbub:EntmakePlineInUCS vertexList layerName 1))
                )
  )
  (vla-setbulge outline 1 arcbulge90)
  (vla-setbulge outline 3 arcbulge90)
  (vla-setbulge outline 5 arcbulge90)
  (vla-setbulge outline 7 arcbulge90)
  ;;
  (setq MatrixVector (mapcar (function -) ll-offset (mxv RotationMatrix origin)))
  ;; Calculate the translation vector
  (setq translationVector (mapcar '- ll-offset (mxv RotationMatrix Origin)))
  ;; translate to ll-offset workpoint
  (setq
    translationMatrix (vlax-tmatrix
                        (append (mapcar '(lambda (v x) (append v (list x)))
                                        RotationMatrix
                                        translationVector
                                )
                                (list '(0.0 0.0 0.0 1.0))
                        )
                      )
  )
  (vla-transformby outline translationMatrix)
  (princ)
)


a piccy;
« Last Edit: August 11, 2010, 07:49:47 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to fillet a polyline using ActiveX
« Reply #3 on: August 11, 2010, 07:49:18 AM »
Library Routines :
Code: [Select]

(vl-load-com)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
;;;   (setq vertexList (list (list 0. 0. 0.)
;;;                          (list 200. 0. 0.)
;;;                          (list 200. 100. 0.)
;;;                          (list 0. 100. 0.)
;;;                    )
;;;         layerName  (getvar "CLAYER")
;;;   )
;;;   (kbub:EntmakePlineInUCS vertexList layerName 1)
;;;   vertexList points expressed in Current UCS
(defun kbub:entmakeplineinucs (l n c / dxf210)
  ;; Codehimbelonga kdub 2010.06.22
  (setq dxf210 (trans '(0 0 1) 1 0 t))
  (entmakex
    (append (list '(0 . "LWPOLYLINE")
                  '(100 . "AcDbEntity")
                  '(100 . "AcDbPolyline")
                  (cons 90 (length l))
                  (cons 70 c)                ; 1 closed : 0 open
                  (cons 8 n)
                  (cons 38 (caddr (trans (car l) 1 dxf210)))
                  (cons 210 dxf210)
            )
            (mapcar (function (lambda (pt) (cons 10 (trans pt 1 dxf210)))) l)
    )
  )
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
Code: [Select]

(setq *max_Real* 1.797693134862315e+308)
;;;------------------------------------------------------------------
;;;
;; pass num as radian.
(defun kdub:tan (num / cosnum)
  (cond ((zerop (rem num pi)) 0.0)
        ((zerop (rem num (* pi 0.5))) *max_real*)
        ((zerop (setq cosnum (cos num))) *max_real*)
        (t (/ (sin num) cosnum))
  )
)
;;;------------------------------------------------------------------
;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v) (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))
;;----------------------------------------------------------------------------
;;


[added to library code]
(setq *max_Real* 1.797693134862315e+308)
« Last Edit: August 12, 2010, 03:47:55 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

fixo

  • Guest
Re: How to fillet a polyline using ActiveX
« Reply #4 on: August 11, 2010, 02:52:57 PM »
Nicely done!

Thanks

Regards,

~'J'~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to fillet a polyline using ActiveX
« Reply #5 on: August 11, 2010, 05:46:14 PM »

Thanks Oleg, it was fun.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kenkrupa

  • Newt
  • Posts: 84
Re: How to fillet a polyline using ActiveX
« Reply #6 on: August 12, 2010, 10:11:08 AM »
Thank you Kerry! I'll start digging into your code. 

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to fillet a polyline using ActiveX
« Reply #7 on: August 12, 2010, 03:46:21 PM »

I added this to the library

(setq *max_Real* 1.797693134862315e+308)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to fillet a polyline using ActiveX
« Reply #8 on: August 12, 2010, 03:58:43 PM »

And after discussion with Oleg, this may be better since we know that the angle is within acceptable geometrical range
there is no need for complicated testing :)
Code: [Select]
(setq ang        (* PI 0.5)
      arcbulge90 (/ (sin (* ang 0.25)) (cos (* ang 0.25)))
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.