Jump to content
EricDevault

Convert Any Length Arc into Equal Segments

Recommended Posts

EricDevault

I am looking for a routine to convert arcs into equal segments and join it into a polyline. rather than converting all arcs, a prompt to select various arcs would be helpful, and a promt for number of segments. I have this one lisp routine but it doesnt work with the prototype we load at the beginning of autocad.

Share this post


Link to post
Share on other sites
Lee Mac

This should work with most objects (Arcs, Splines, Lines, Polylines, Circles, Ellipses...):

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:Segs [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ENT EPAR I INC PTS UFLAG[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Lee Mac  ~  29.01.10[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *doc  [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]*doc[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]        
       *segs [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]*segs[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]10[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 
 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

     [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=DARKRED]'[/color][/b]ENAME [b][color=RED]([/color][/b][b][color=BLUE]type[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b]

              [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-error-p[/color][/b]
                    [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ePar
                      [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-apply[/color][/b]
                        [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=Blue]vlax-curve-getEndParam[/color][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

                [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n ** Invalid Object **"[/color][/b][b][color=RED])[/color][/b]
                [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#009900]6[/color][/b][b][color=RED])[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *segs [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]getint[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\nSpecify Number of Segments <"[/color][/b]
                                                     [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] *segs[b][color=RED])[/color][/b] [b][color=#a52a2a]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]*segs[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                  
                  [b][color=RED]([/color][/b][b][color=BLUE]vla-StartUndoMark[/color][/b] *doc[b][color=RED])[/color][/b]

                  [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] inc [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getDistatParam[/color][/b] ent ePar[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]float[/color][/b] *segs[b][color=RED])[/color][/b][b][color=RED])[/color][/b] i [b][color=#009900]-1[/color][/b][b][color=RED])[/color][/b]

                  [b][color=RED]([/color][/b][b][color=BLUE]repeat[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] *segs[b][color=RED])[/color][/b]
                    [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pts [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getPointatDist[/color][/b] ent
                                      [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b] inc[b][color=RED])[/color][/b][b][color=RED])[/color][/b] pts[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

                  [b][color=RED]([/color][/b][b][color=BLUE]entmake[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]append[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b]   [b][color=#a52a2a]"LWPOLYLINE"[/color][/b][b][color=RED])[/color][/b]
                                         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]100[/color][/b] [b][color=#a52a2a]"AcDbEntity"[/color][/b][b][color=RED])[/color][/b]
                                         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]100[/color][/b] [b][color=#a52a2a]"AcDbPolyline"[/color][/b][b][color=RED])[/color][/b]
                                         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]90[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]length[/color][/b] pts[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                                         [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]70[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                                   [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]a[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]10[/color][/b] a[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] pts[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]entdel[/color][/b] ent[b][color=RED])[/color][/b]                   
                  [b][color=RED]([/color][/b][b][color=BLUE]vla-EndUndoMark[/color][/b] *doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Share this post


Link to post
Share on other sites
EricDevault

that worked great, i tested it in our prototype and it worked, however it didn't delete the original arc

Share this post


Link to post
Share on other sites
Lee Mac
that worked great, i tested it in our prototype and it worked, however it didn't delete the original arc

 

Code updated :)

Share this post


Link to post
Share on other sites
EricDevault

Awesome!! that worked and saved a lot of time for us! is there anyway to donate to your work?

Share this post


Link to post
Share on other sites
Lee Mac
Awesome!! that worked and saved a lot of time for us! is there anyway to donate to your work?

 

Well, we used to have PayPal links to our accounts, but they were removed a while ago. You could donate to CADTutor I suppose, or I could PM you with my email. :)

Share this post


Link to post
Share on other sites
gile

Hi,

 

Here's a routine I wrote some times ago.

I works with arcs, circles and polylines arcs

 

(defun c:Arc2Seg (/ arc2pol pol2pol seg del org ss n ent elst)

 

(vl-load-com)

 

;; Returns the polyline DXF list (form an arc or a circle)

(defun arc2pol

(elst seg org / closed alpha delta cen elv rad lay nlst)

(and (= (cdr (assoc 0 elst)) "CIRCLE") (setq closed T))

(setq alpha (if closed

(* pi 2)

(cdr (assoc 51 elst))

)

delta (if closed

(/ alpha seg)

(/ (ang

)

cen (cdr (assoc 10 elst))

elv (caddr cen)

cen (list (car cen) (cadr cen))

rad (cdr (assoc 40 elst))

lay (if org

(assoc 8 elst)

(cons 8 (getvar "CLAYER"))

)

nlst (vl-remove-if-not

(function (lambda (x) (member (car x) '(210 -3))))

elst

)

nlst (cons (cons 10 (polar cen alpha rad)) nlst)

)

(repeat (if closed

(1- seg)

seg

)

(setq

nlst (cons (cons 10

(polar cen (setq alpha (- alpha delta)) rad)

)

nlst

)

)

)

(setq nlst

(cons '(0 . "LWPOLYLINE")

(cons '(100 . "AcDbEntity")

(cons (cons 410 (getvar "CTAB"))

(cons lay

(cons '(100 . "AcDbPolyline")

(cons (cons 90

(if closed

seg

(1+ seg)

)

)

(cons (cons 70

(if closed

1

0

)

)

(cons (cons 38 elv) nlst)

)

)

)

)

)

)

)

)

)

 

;; Returns the polyline DXF list (form a polyline)

(defun pol2pol (elst seg org / cnt closed nlst p0

p1 p2 bu larg inc bdata delta cen rad

alpha n

)

(setq closed (logand 1 (cdr (assoc 70 elst)))

cnt 0

)

(and (= closed 1) (setq p0 (cdr (assoc 10 elst))))

(while elst

(if (= (caar elst) 10)

(progn

(setq p1 (cdar elst)

p2 (cdr (assoc 10 (cdr elst)))

bu (cdr (assoc 42 elst))

)

(cond

((or (= 0 bu)

(and (zerop closed) (null p2))

)

(setq nlst (cons (cadddr elst)

(cons (caddr elst)

(cons (cadr elst)

(cons (car elst) nlst)

)

)

)

)

)

((and p2 (/= 0 bu) (

(setq nlst (cons (caddr elst)

(cons (cadr elst)

(cons (car elst) nlst)

)

)

)

)

(T

(and (not p2) (= closed 1) (setq p2 p0))

(setq larg (cdr (assoc 40 elst))

inc (/ (- (cdr (assoc 41 elst)) larg) seg)

bdata (BulgeData bu p1 p2)

delta (/ (car bdata) seg)

rad (abs (cadr bdata))

cen (caddr bdata)

alpha (angle cen p1)

n 0

cnt (+ cnt seg -1)

)

(while (

(setq nlst (cons

(cons 10

(polar cen

(+ alpha (* delta n))

rad

)

)

nlst

)

nlst (cons (cons 40 larg) nlst)

nlst (cons (cons 41 (setq larg (+ larg inc))) nlst)

nlst (cons '(42 . 0.0) nlst)

n (1+ n)

)

)

)

)

(setq elst (cddddr elst))

)

(setq nlst (cons (car elst) nlst)

elst (cdr elst)

)

)

)

(or org

(setq nlst (subst (cons 8 (getvar "CLAYER")) (assoc 8 nlst) nlst))

)

((lambda (dxf90)

(subst (cons 90 (+ (cdr dxf90) cnt))

dxf90

(reverse (subst '(42 . 0.0) (assoc 42 nlst) nlst))

)

)

(assoc 90 nlst)

)

)

 

;; Main

 

(or (getenv "SegmentsNumberPerCircle")

(setenv "SegmentsNumberPerCircle" "64")

)

(initget 6)

(or (setq mini (getdist "\nMinimal length for a segment: "))

(setq mini 0.5)

)

(initget 6)

(if

(setq seg (getint

(strcat "\nNumber of segments per arc

(getenv "SegmentsNumberPerCircle")

">: "

)

)

)

(setenv "SegmentsNumberPerCircle" (itoa seg))

(setq seg (atoi (getenv "SegmentsNumberPerCircle")))

)

(initget "Yes No")

(if (= "Yes"

(getkword "\nErase source objects ? Yes/No : ")

)

(setq del T)

)

(initget "Current Source")

(if (= "Origine"

(getkword

"\nLayer for new objects [Current/Source] ? : "

)

)

(setq org T)

)

(prompt

"\nSelect objects or ."

)

(and

(or (setq ss (ssget '((0 . "ARC,CIRCLE,LWPOLYLINE"))))

(setq ss (ssget "_X" '((0 . "ARC,CIRCLE,LWPOLYLINE"))))

)

(setq n 0)

(while (setq ent (ssname ss n))

(setq elst (entget ent '("*")))

(if (= (cdr (assoc 0 elst)) "LWPOLYLINE")

((if del

entmod

entmake

) (pol2pol elst seg org)

)

(progn

(entmake (arc2pol elst seg org))

(and del (entdel ent))

)

)

(setq n (1+ n))

)

)

(princ)

)

 

 

;; BulgeData

;; Retourne les données d'un polyarc (angle rayon centre)

(defun BulgeData (bu p1 p2 / alpha rad cen)

(setq alpha (* 2 (atan bu))

rad (/ (distance p1 p2)

(* 2 (sin alpha))

)

cen (polar p1

(+ (angle p1 p2) (- (/ pi 2) alpha))

rad

)

)

(list (* alpha 2.0) rad cen)

)

 

;;; Ang

;;; Retourne l'angle,

Share this post


Link to post
Share on other sites
Lee Mac

Gile... Why so much code! :shock:

Share this post


Link to post
Share on other sites
gile
Gile... Why so much code! :shock:

 

I don't remember, it's an old story.

Maybe for someone who can't access to Visual LISP functions...

Share this post


Link to post
Share on other sites
lpseifert

Since we're showing different flavors...

I think I must have been learning the vlax-curve... functions at the time cuz I have no use for it. Works for the entire length of the curve, including straight sections... oh well.

;;;Creates chords along curve w/ user entered divisions  LPS 2008-11

(defun c:test ();(/ oldecho obj div endpt totlen arclen chrdpt dist newpt)
(vl-load-com)
(setq oldecho (getvar "cmdecho")
     oldsnap (getvar "osmode")
     )
(setvar "cmdecho" 0)
(setvar "osmode" 0)  
(setq ent (entsel "\nPick arc: ")
    obj (vlax-ename->vla-object (car ent))
    div (getint "\nEnter number of chords: ")
    endpt (vlax-curve-getEndPoint obj)
    totlen (vlax-curve-getDistAtPoint obj endpt)
    arclen (/ totlen div)
    chrdpt (vlax-curve-getPointAtDist obj 0)
    dist 0
    )
(repeat div
  (setq newpt(vlax-curve-getPointatDist obj (+ arclen dist)))
  (command "line" chrdpt newpt "")
  (setq dist (+ arclen dist))
  (setq chrdpt newpt)
  );repeat
 (setvar "cmdecho" oldecho)
 (setvar "osmode" oldsnap)
 (princ)
 );defun

Share this post


Link to post
Share on other sites
EricDevault

wow this is getting a lot of attention, this is a great community! on the original lisp routine posted by Lee Mac, i did notice that only one arc can be selected at a time for the command, what we work w/ in our process is usually rectangles w/ 2-4' radius corners that need segmented. In the preset I didn't want the routine to just automatically select all radius corners, as there may be different size radius corners per drawing and different size corners are segmented into different number of segments, i.e. 2' is 5 segments and 4' is 4 segments. I guess im asking if it would be possible to be able to select multiple arcs?

Share this post


Link to post
Share on other sites
Lee Mac

Certainly :)

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:Segs [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ENT EPAR I J INC PTS SS[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Lee Mac  ~  29.01.10[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *doc  [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]*doc[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]        
       *segs [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]*segs[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]10[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] j [b][color=#009900]-1[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_:L"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#a52a2a]"ARC,CIRCLE,*POLYLINE,SPLINE,LINE,ELLIPSE"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#009900]6[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *segs [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]getint[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\nSpecify Number of Segments <"[/color][/b]
                                             [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] *segs[b][color=RED])[/color][/b] [b][color=#a52a2a]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]*segs[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   
   [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] j [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] j[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]vla-StartUndoMark[/color][/b] *doc[b][color=RED])[/color][/b]

     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] inc [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getDistatParam[/color][/b] ent
                    [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getEndParam[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]float[/color][/b] *segs[b][color=RED])[/color][/b][b][color=RED])[/color][/b] i [b][color=#009900]-1[/color][/b][b][color=RED])[/color][/b]
     
     [b][color=RED]([/color][/b][b][color=BLUE]repeat[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] *segs[b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pts [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getPointatDist[/color][/b] ent
                         [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b] inc[b][color=RED])[/color][/b][b][color=RED])[/color][/b] pts[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     
     [b][color=RED]([/color][/b][b][color=BLUE]entmake[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]append[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b]   [b][color=#a52a2a]"LWPOLYLINE"[/color][/b][b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]100[/color][/b] [b][color=#a52a2a]"AcDbEntity"[/color][/b][b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]100[/color][/b] [b][color=#a52a2a]"AcDbPolyline"[/color][/b][b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]90[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]length[/color][/b] pts[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                            [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]70[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]a[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]10[/color][/b] a[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] pts[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     
     [b][color=RED]([/color][/b][b][color=BLUE]entdel[/color][/b] ent[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pts [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]vla-EndUndoMark[/color][/b] *doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Share this post


Link to post
Share on other sites
gilsoto13

This will be great, but you guys must know spl2pl.vlx...

 

That routine is great cause it allow us to choose the segment length... but works with splines only.

 

How difficult would it be to make a similar routine for arcs and circles but allowing us to choose the segment size to divide all the objects selected instead the number of segments for each object?

 

I usually do this manually sometimes when I need to export 3dsolids to a 3dstudio model to render the arcs smoothly as required.

 

It wouldn´t save me lots of time... must say... but I always wondered if this routine will ever exist.

Share this post


Link to post
Share on other sites
Lee Mac

Perhaps something like this? Might need a bit of refining for closed entities:

 

(defun c:Segs (/ CLEN ENT I J PTS SEGNUM SS)
 (vl-load-com) ; Lee Mac  ~  30.01.10

 (setq *doc  (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))        
       *sLen (cond (*sLen) (10.)))

 (if (and (setq j -1 ss (ssget "_:L" '((0 . "ARC,CIRCLE,*POLYLINE,SPLINE,LINE,ELLIPSE"))))
          (not (initget 6))
          (setq *sLen (cond ((getdist (strcat "\nSpecify Segment Length <"
                                              (rtos *sLen) "> : "))) (*sLen))))
   
   (while (setq ent (ssname ss (setq j (1+ j))))
     (vla-StartUndoMark *doc)

     (setq cLen (vlax-curve-getDistAtParam ent
                  (vlax-curve-getEndParam ent)) segNum (fix (/ cLen *sLen)) i -1)

     (or (zerop (rem cLen *sLen)) (setq segNum (1+ segNum)))

     (repeat (1+ segNum)
       (setq pts (cons (cond ((vlax-curve-getPointAtDist ent
                                (* (setq i (1+ i)) *sLen)))
                             ((vlax-curve-getEndPoint ent)))  pts)))
     
     (entmake (append (list (cons 0   "LWPOLYLINE")
                            (cons 100 "AcDbEntity")
                            (cons 100 "AcDbPolyline")
                            (cons 90 (length pts))
                            (cons 70 0))
                      (mapcar (function (lambda (a) (cons 10 a))) pts)))
     
     (entdel ent) (setq pts nil)
     (vla-EndUndoMark *doc)))

 (princ))

Share this post


Link to post
Share on other sites
EricDevault

For some reason i cant PM you Lee Mac. Wanted to ask you a few things.

Share this post


Link to post
Share on other sites
Lee Mac
For some reason i cant PM you Lee Mac. Wanted to ask you a few things.

 

I think you have to have over 10 posts :geek: only 3 more ... o:)

Share this post


Link to post
Share on other sites
EricDevault

oh, gotcha, well i guess i could ask some things in this post, is there a way to combine commands that we do back to back

Share this post


Link to post
Share on other sites
Lee Mac
oh, gotcha, well i guess i could ask some things in this post, is there a way to combine commands that we do back to back

 

Sure, what were you thinking?

Share this post


Link to post
Share on other sites
EricDevault

we have a plugin on our 2007 that has these custom commands, the first is _copyclip select all then _seamslice and the last one is _autonest

Share this post


Link to post
Share on other sites
Lee Mac
we have a plugin on our 2007 that has these custom commands, the first is _copyclip select all then _seamslice and the last one is _autonest

 

You could perform them using a macro if you wish:

 

^C^C_copyclip;_seamslice;_autonest;

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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