Author Topic: How to change elliptical arcs into plines  (Read 3748 times)

0 Members and 1 Guest are viewing this topic.

lispman21

  • Guest
How to change elliptical arcs into plines
« on: July 27, 2006, 09:41:14 AM »
I use a program to convert ellipses into plines, but this program does not do a good job with elliptical arcs.  Infact it just makes them a full ellipse instead of the arc it is supposed to be.  MAybe there is a way to either trim or break this ellipse back into its originally looking arc but still be a pline.  I will post the code and if you want you can test it yourself to better explain what i have written.  Just draw an elliptical arc in autocad and run the program and you will see what i mean.  All help is appreciated.


Code: [Select]
(defun e2p( /
old new   ;existent and new polyline
sav    ;store system variables
cen    ;center of ellipse
dep    ;axis end point deplacement (relative to cen)
p1 p2 ;first axis enpoints
p3 ;sec. axis endpoint
 ellObjs   ; added
 numObjs   ; added   
 count ; added   
   )

(setq ellObjs (ssget "x" '((0 . "ELLIPSE"))))
(if ellObjs
  (progn
  (setq numOjbs (sslength ellObjs)
 count 0
 )
  (while (> numOjbs count)
(setq old (cdr (assoc -1 (entget (ssname ellObjs count)))))


   (setq sav (mapcar 'getvar '("PELLIPSE" "OSMODE" "UCSICON"))
cen (cdr (assoc 10 (entget old)))
dep (cdr (assoc 11 (entget old))))
   (mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") '(1 0 0))
   (command "UCS" "e" old)
   (setq p1 (trans (list (+ (car cen) (car dep))
   (+ (cadr cen) (cadr dep))
   (+ (caddr cen) (caddr dep)))
0 1)
p2 (trans (list (- (car cen) (car dep))
   (- (cadr cen) (cadr dep))
   (- (caddr cen) (caddr dep)))
0 1)
p3 (trans (polar cen
(+ (/ PI 2.0) (angle p1 p2))
(* 0.5 (cdr (assoc 40 (entget old))) (distance p1 p2)))
0 1)
)
   (command "ellipse" p1 p2 p3)
   (command "_.chprop" old "" "la" "0" "")   
   (setq new (entget (entlast))
new (subst (cons 8 (cdr (assoc 8 (entget old)))) (assoc 8 new) new))
   (entmod new)
   (entdel old)
   (command "ucs" "p")
   (mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") sav)

(setq count (1+ count))
); while
  ); progn
  ); if
(princ)
   );; end of program

lispman21

  • Guest
Re: How to change elliptical arcs into plines
« Reply #1 on: July 27, 2006, 02:47:53 PM »
What i have to figure out is how to extract the start and end angle of the existing elliptical arc and then draw either actual lines and delete them at the end of the program or imaginary lines and trim the ellipse back to these lines.  Thus making an elliptical arc into a pline that looks like the original arc.

Jochen

  • Newt
  • Posts: 30
Re: How to change elliptical arcs into plines
« Reply #2 on: July 27, 2006, 03:08:23 PM »
Similar to your suggestion I made my PEDIT3D and there is a subroutine which will convert 3D-elliptical-arcs into 3DPOLYLINES.
You can get PEDIT3D from www.black-cad.de
regards
Jochen
 

lispman21

  • Guest
Re: How to change elliptical arcs into plines
« Reply #3 on: July 27, 2006, 03:50:12 PM »
Was wondering if i could hav ethe full version because i would like to automate this to where it pics all ellipses in the drawing and converts them.  Unless you already ahve this done.  WOuld be much appreciated.

lispman21

  • Guest
Re: How to change elliptical arcs into plines
« Reply #4 on: July 31, 2006, 08:59:59 AM »
Ok, here is some code given to me by Tom Beauford.  It still needs alot of work but the program does draw a line to trim the ellipse back to but it is not trimming correctly right now.  If anyone wants to look at the code and try cleaning it up here it is:

Code: [Select]
(defun e2p( /
old new   ;existent and new polyline
sav   ;store system variables
cen   ;center of ellipse
dep   ;axis end point deplacement (relative to cen)
p1 p2   ;first axis enpoints
p3   ;sec. axis endpoint
   )
  (setq old (car (entsel "\n select ellipse to change "))
ellipseObj (vlax-ename->vla-object old)
Center (vlax-safearray->list (vlax-variant-value (vla-get-Center ellipseObj)))
StartPoint (vlax-safearray->list (vlax-variant-value (vla-get-StartPoint ellipseObj)))
EndPoint (vlax-safearray->list (vlax-variant-value (vla-get-EndPoint ellipseObj)))
StartAngle (vla-get-StartAngle ellipseObj)
EndAngle (vla-get-EndAngle ellipseObj)
dist1 (vlax-curve-getDistAtPoint ellipseObj StartPoint)
dist2 (vlax-curve-getDistAtPoint ellipseObj EndPoint)
dist (/ (+ dist1 dist2) 2)
emidpt (vlax-curve-getPointAtDist ellipseObj dist)
ang (+ EndAngle (/ (+ StartAngle EndAngle) 2))
dist (*(distance emidpt Center)1.1)
fpt (polar Center ang dist)
  )
   (setq sav (mapcar 'getvar '("PELLIPSE" "OSMODE" "UCSICON"))
cen (cdr (assoc 10 (entget old)))
dep (cdr (assoc 11 (entget old))))
  (while old
(if (= (cdr (assoc 0 (entget old))) "ELLIPSE")
  (progn
   (mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") '(1 0 0))
   (command "UCS" "e" old)
   (setq p1 (trans (list (+ (car cen) (car dep))
   (+ (cadr cen) (cadr dep))
   (+ (caddr cen) (caddr dep)))
0 1)
p2 (trans (list (- (car cen) (car dep))
   (- (cadr cen) (cadr dep))
   (- (caddr cen) (caddr dep)))
0 1)
p3 (trans (polar cen
(+ (/ PI 2.0) (angle p1 p2))
(* 0.5 (cdr (assoc 40 (entget old))) (distance p1 p2)))
0 1)
)
   (if (= (- EndAngle (* pi 2)) StartAngle)
(command "ellipse" p1 p2 p3)
(progn
   (command "ellipse" p1 p2 p3)
(setq new (entget (entlast))
   new (subst (cons 8 (cdr (assoc 8 (entget old)))) (assoc 8 new) new)
)
(entmod new)
(setq ptrim (list
  '(0 . "LWPOLYLINE")
  '(100 . "AcDbEntity")
  (cons 8 (cdr (assoc 8 (entget old)))) ; layer
  '(6 . "CONTINUOUS") ;linetype
  '(100 . "AcDbPolyline")
  '(90 . 2)   ;# of vertices
  '(39 . 0.0)
  (list 10(car StartPoint)(cadr StartPoint))    ;vertex
  (list 10(car EndPoint)(cadr EndPoint))    ;vertex
  '(210 0.0 0.0 1.0) ;extrusion direction
)
)
(entmake ptrim)
(setq AX (entlast))
(VL-CMDF "._trim" AX "" "f" fpt Center "" "")
(entdel AX)
   ); progn
); if
;   (entdel old)
(command "ucs" "p")
(mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") sav)
   )
   (alert "This is not a spline ellipse!")
 )
 (setq old (car (entsel "\n next ellipse -or none for exit ")))
  )
(princ)
);; end of program