0 Members and 1 Guest are viewing this topic.
;; http://forums.autodesk.com/autodesk/attachments/autodesk/130/225916/1/Bulge-Center.txt;by Fatty The Old Stupid Horse;; helper functions ;;;; group list in sublists (defun group-by-num (lst num / ls ret) (if (= (rem (length lst) num ) 0) (progn (setq ls nil) (repeat (/ (length lst) num) (repeat num (setq ls (cons (car lst) ls) lst (cdr lst))) (setq ret (append ret (list (reverse ls))) ls nil))) )ret );+ ;get polyline vertices (defun get-vexs (pline_obj / verts) (setq verts (vlax-get pline_obj 'Coordinates) verts (cond ((wcmatch (vlax-get pline_obj 'Objectname ) "AcDb2dPolyline,AcDb3dPolyline") (group-by-num verts 3) ) ((eq (vlax-get pline_obj 'Objectname ) "AcDbPolyline") (group-by-num verts 2) ) (T nil) ) ) );+;; get bulge radius;; math by Juergen Menzi(defun get-radii (p1 p2 bulge) (abs (/ (distance p1 p2) 2 (sin (/ (* 4 (atan (abs bulge))) 2)))) ;; crashed here from lack of arc selection );+;;get segment arc center;;math by John Uhden(defun get-segm-center (pline p1 p2 bulge / cpt midc midp rad)(setq rad (get-radii p1 p2 bulge) midp (vlax-curve-getpointatparam pline (+ (fix (vlax-curve-getparamatpoint pline p1)) 0.5)) midc (mapcar (function (lambda (x y)(/ (+ x y) 2))) p1 p2) cpt (trans (polar midp (angle midp midc) rad) 0 1))cpt);+;main part;; Vertex of Polyline Arc Segment:(defun C:SAP (/ *error* bpt bulg cent coors ent ept pln rad segm snap_pt spt) ;; (vl-load-com) (setq pln (vlax-ename->vla-object (car (setq ent (entsel "\n Polyline Vertex of Polyline Arc Segment:\n Select Arc of Polyline:")) )))(setq snap_pt (trans (cadr ent) 1 0) bpt (vlax-curve-getclosestpointto pln snap_pt))(if (eq (vla-get-Closed pln) :vlax-false) (setq coors (get-vexs pln)) (progn (setq coors (get-vexs pln)) (setq coors (append coors (list (car coors))))))(setq segm (fix (vlax-curve-getparamatpoint pln bpt)) spt (nth segm coors) ept (nth (1+ segm) coors) bulg (vla-getbulge pln segm) rad (get-radii spt ept bulg) cent (trans (get-segm-center pln spt ept bulg) 1 0)) (princ (strcat " Radius: " (rtos rad)))(if (= bulg nil) (princ "\n Straight Segment Selected.") ) (if (not (= bulg nil)) (progn ;TesT Adds circle from arc selected; (vlax-invoke (vla-get-modelspace ; (vla-get-activedocument ; (vlax-get-acad-object))) ; 'Addcircle cent rad) (vlax-invoke (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) 'AddLightWeightPolyline (apply 'append (mapcar (function (lambda(x) (list (car x)(cadr x)))) (list spt cent ept))) ) ;; end of ) ;; end of progn ) ;; end of if (princ) ) ;; end of sap
(vl-load-com) ;; https://www.theswamp.org/index.php?topic=42162.msg473601#msg473601(defun c:pac ( / e ent pt p p1 p2 bulge rad cen fpt) (setq e (entsel "\nPick Poly-ARC for Center + <Cal-Data>")) (setq ent (car e) pt (cadr e)) (setq p (vlax-curve-getclosestpointto ent pt)) (setq p1 (vlax-curve-getpointatparam ent (float (fix (vlax-curve-getparamatpoint ent p))))) (setq p2 (vlax-curve-getpointatparam ent (float (1+ (fix (vlax-curve-getparamatpoint ent p)))))) (setq bulge (vla-getbulge (vlax-ename->vla-object ent) (float (fix (vlax-curve-getparamatpoint ent p))))) (setq rad (/ (distance p1 p2) (* 2 (sin (* 2 (atan bulge)))))) (setq cen (polar p1 (+ (angle p1 p2) (- (/ pi 2.0) (* 2 (atan bulge)))) rad)) ;(alert (strcat "\nRadius of arc is : " (rtos (abs rad)) ; "\nCenter of arc is : " (rtos (car cen)) "," (rtos (cadr cen)) "," (rtos (caddr cen)) ; "\nAngle of arc is : " (rtos (cvunit (* 4 (atan bulge)) "radians" "degrees")))) (princ (strcat "\nRadius of ARC is : " (rtos (abs rad)) "\nCenter of ARC is : " (rtos (car cen)) "," (rtos (cadr cen)) "," (rtos (caddr cen)) "\nAngle of ARC is : " (rtos (cvunit (* 4 (atan bulge)) "radians" "degrees"))"\n")) (setq fpt (strcat (rtos (car cen) 2 15) "," (rtos (cadr cen) 2 15) "," (rtos (caddr cen) 2 15)) ) (vl-cmdf "_point" fpt) (princ))
Hoping to find a solution [I've tried ] to filter, or something, a selection of a poly-arc to get the center and radius. This code gets it but errors-out when not picking an arc segment. Additionally a loop to solve the selection and multiple use of it would be helpful. ANY ideas/changes to this lsp I found will be appreciated!Code: [Select];; http://forums.autodesk.com/autodesk/attachments/autodesk/130/225916/1/Bulge-Center.txt;by Fatty The Old Stupid Horse;; helper functions ;;;; group list in sublists (defun group-by-num (lst num / ls ret) (if (= (rem (length lst) num ) 0) (progn (setq ls nil) (repeat (/ (length lst) num) (repeat num (setq ls (cons (car lst) ls) lst (cdr lst))) (setq ret (append ret (list (reverse ls))) ls nil))) )ret );+ ;get polyline vertices (defun get-vexs (pline_obj / verts) (setq verts (vlax-get pline_obj 'Coordinates) verts (cond ((wcmatch (vlax-get pline_obj 'Objectname ) "AcDb2dPolyline,AcDb3dPolyline") (group-by-num verts 3) ) ((eq (vlax-get pline_obj 'Objectname ) "AcDbPolyline") (group-by-num verts 2) ) (T nil) ) ) );+;; get bulge radius;; math by Juergen Menzi(defun get-radii (p1 p2 bulge) (abs (/ (distance p1 p2) 2 (sin (/ (* 4 (atan (abs bulge))) 2)))) ;; crashed here from lack of arc selection );+;;get segment arc center;;math by John Uhden(defun get-segm-center (pline p1 p2 bulge / cpt midc midp rad)(setq rad (get-radii p1 p2 bulge) midp (vlax-curve-getpointatparam pline (+ (fix (vlax-curve-getparamatpoint pline p1)) 0.5)) midc (mapcar (function (lambda (x y)(/ (+ x y) 2))) p1 p2) cpt (trans (polar midp (angle midp midc) rad) 0 1))cpt);+;main part;; Vertex of Polyline Arc Segment:(defun C:SAP (/ *error* bpt bulg cent coors ent ept pln rad segm snap_pt spt) ;; (vl-load-com) (setq pln (vlax-ename->vla-object (car (setq ent (entsel "\n Polyline Vertex of Polyline Arc Segment:\n Select Arc of Polyline:")) )))(setq snap_pt (trans (cadr ent) 1 0) bpt (vlax-curve-getclosestpointto pln snap_pt))(if (eq (vla-get-Closed pln) :vlax-false) (setq coors (get-vexs pln)) (progn (setq coors (get-vexs pln)) (setq coors (append coors (list (car coors))))))(setq segm (fix (vlax-curve-getparamatpoint pln bpt)) spt (nth segm coors) ept (nth (1+ segm) coors) bulg (vla-getbulge pln segm) rad (get-radii spt ept bulg) cent (trans (get-segm-center pln spt ept bulg) 1 0)) (princ (strcat " Radius: " (rtos rad)))(if (= bulg nil) (princ "\n Straight Segment Selected.") ) (if (not (= bulg nil)) (progn ;TesT Adds circle from arc selected; (vlax-invoke (vla-get-modelspace ; (vla-get-activedocument ; (vlax-get-acad-object))) ; 'Addcircle cent rad) (vlax-invoke (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) 'AddLightWeightPolyline (apply 'append (mapcar (function (lambda(x) (list (car x)(cadr x)))) (list spt cent ept))) ) ;; end of ) ;; end of progn ) ;; end of if (princ) ) ;; end of sap
Breaking news.. Open polyline with arc segments prefer to decline their center osnap BUT when polyline is closed, it seems to work better!! One I must remember to put in my mental SSD.