Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vlax-curve... functions to obtain points

2 REPLIES 2
Reply
Message 1 of 3
mdhutchinson
325 Views, 2 Replies

vlax-curve... functions to obtain points

I have successfully written an algorithm to return the optimal bounding box (containing rectangle having the smallest possible area) of a closed shape given a closed non-self-intersecting light weight polyline. It works well for shapes that are made of straight line segments. It also works regardless of the UCS that is current and also if the closed shape is rotated away, or is non-parallel to the world xy axis...

Currently however it only returns accurate dimensions when there are no arc segments in the polyline...

... is there some method I might employ to add data through some ingenious use of the vlax-curve functions?... or some other means?
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: mdhutchinson

wrote in message news:5683900@discussion.autodesk.com...
I have successfully written an algorithm to return the optimal bounding box (containing rectangle having the smallest possible area)
of a closed shape given a closed non-self-intersecting light weight polyline. It works well for shapes that are made of straight
line segments. It also works regardless of the UCS that is current and also if the closed shape is rotated away, or is non-parallel
to the world xy axis...

Currently however it only returns accurate dimensions when there are no arc segments in the polyline...

... is there some method I might employ to add data through some ingenious use of the vlax-curve functions?... or some other means?


I assume vla-getboundingbox is not sufficient for your needs.
The following code might be of interest to you if you are looking for a way to generate points on the arc portions of your
polylines.

Regards,

Mel

;;; SelByObj -Gilles Chanteau- 06/10/06
;;; Creates a selection set from an object (circle ellipse or closed
;;; lwpolyline) by Window polygon or Crossing Polygon.
;;;
;;; Arguments :
;;; - ent: ename or vla-object
;;; - opt: selection mode (Cp or Wp)
;;; - fltr: selection filter or nil

(defun SelByObj (ent opt fltr / obj dist n lst prec dist p_lst ss)
(vl-load-com)
(if (= (type ent) 'ENAME)
(setq obj (vlax-ename->vla-object ent))
(setq obj ent
ent (vlax-vla-object->ename ent)
)
)
(cond
((member (vla-get-ObjectName obj)
'("AcDbCircle" "AcDbEllipse")
)
(setq dist (/ (vlax-curve-getDistAtParam
obj
(vlax-curve-getEndParam obj)
)
50
)
n 0
)
(repeat 50
(setq
lst
(cons
(trans
(vlax-curve-getPointAtDist obj (* dist (setq n (1+ n))))
0
1
)
lst
)
)
)
)

((and (= (vla-get-ObjectName obj) "AcDbPolyline")
(= (vla-get-Closed obj) :vlax-true)
)
(setq p_lst
(vl-remove-if-not
'(lambda (x)
(or (= (car x) 10)
(= (car x) 42)
)
)
(entget ent)
)
)
(while p_lst
(setq lst
(cons (trans (append (cdr (assoc 10 p_lst))
(list (cdr (assoc 38 (entget ent))))
)
ent
1
)
lst
)
)
(if (/= 0 (cdadr p_lst))
(progn
(setq prec (1+ (fix (* 25 (sqrt (abs (cdadr p_lst))))))
dist (/ (- (if (cdaddr p_lst)
(vlax-curve-getDistAtPoint
obj
(trans (cdaddr p_lst) ent 0)
)
(vlax-curve-getDistAtParam
obj
(vlax-curve-getEndParam obj)
)
)
(vlax-curve-getDistAtPoint
obj
(trans (cdar p_lst) ent 0)
)
)
prec
)
n 0
)
(repeat (1- prec)
(setq
lst (cons
(trans
(vlax-curve-getPointAtDist
obj
(+ (vlax-curve-getDistAtPoint
obj
(trans (cdar p_lst) ent 0)
)
(* dist (setq n (1+ n)))
)
)
0
1
)
lst
)
)
)
)
)
(setq p_lst (cddr p_lst))
)
)
)
(cond
(lst
(print lst)
(vla-ZoomExtents (vlax-get-acad-object))
(setq ss (ssget (strcat "_" opt) lst fltr))
(vla-ZoomPrevious (vlax-get-acad-object))
ss
)
)
)
Message 3 of 3
_gile
in reply to: mdhutchinson

Hi,

the vla-getBoundingbox function always returns the boundingbox about the WCS.

here's a routine wich draw an object (3dpolyline or box) figuring the the boundingbox of the selected object about the current UCS.

;; Doug C. Broad, Jr.
;; can be used with vla-transformby to
;; transform objects from the UCS to the WCS
(defun UCS2WCSMatrix ()
(vlax-tmatrix
(append
(mapcar
'(lambda (vector origin)
(append (trans vector 1 0 t) (list origin))
)
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 0 1)
)
(list '(0 0 0 1))
)
)
)
;; transform objects from the WCS to the UCS
(defun WCS2UCSMatrix ()
(vlax-tmatrix
(append
(mapcar
'(lambda (vector origin)
(append (trans vector 0 1 t) (list origin))
)
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 1 0)
)
(list '(0 0 0 1))
)
)
)

;; BBOX -Gilles Chanteau-
;; Creates an entity (3D polyline or box) figuring the "bounding box"
;; of the selected object about current UCS.

(defun c:bbox (/ AcDoc Space obj bb minpoint maxpoint pt1 pt2 lst poly
box cen norm)
(vl-load-com)
(setq AcDoc (vla-get-activedocument (vlax-get-acad-object))
Space (if (= (getvar "CVPORT") 1)
(vla-get-PaperSpace AcDoc)
(vla-get-ModelSpace AcDoc)
)
)
(vla-startUndoMark AcDoc)
(while (not (setq obj (car (entsel)))))
(setq obj (vlax-ename->vla-object obj))
(vla-TransformBy obj (UCS2WCSMatrix))
(setq bb (vl-catch-all-apply
'vla-getboundingbox
(list obj
'minpoint
'maxpoint
)
)
)
(if (vl-catch-all-error-p bb)
(progn
(princ
(strcat "; erreur: " (vl-catch-all-error-message bb))
)
(vla-TransformBy obj (WCS2UCSMatrix))
(vla-endUndoMark AcDoc)
)
(progn
(setq pt1 (vlax-safearray->list minpoint)
pt2 (vlax-safearray->list maxpoint)
)
(if (or (equal (car pt1) (car pt2) 1e-007)
(equal (cadr pt1) (cadr pt2) 1e-007)
(equal (caddr pt1) (caddr pt2) 1e-007)
)
(progn
(cond
((equal (car pt1) (car pt2) 1e-007)
(setq lst (list pt1
(list (car pt1) (cadr pt1) (caddr pt2))
pt2
(list (car pt1) (cadr pt2) (caddr pt1))
)
)
)
((equal (cadr pt1) (cadr pt2) 1e-007)
(setq lst (list pt1
(list (car pt1) (cadr pt1) (caddr pt2))
pt2
(list (car pt2) (cadr pt1) (caddr pt1))
)
)
)
((equal (caddr pt1) (caddr pt2) 1e-007)
(setq lst (list pt1
(list (car pt1) (cadr pt2) (caddr pt1))
pt2
(list (car pt2) (cadr pt1) (caddr pt1))
)
)
)
)
(setq box
(vlax-invoke Space 'add3dPoly (apply 'append lst))
)
(vla-put-closed box :vlax-true)
)
(progn
(setq cen (mapcar '(lambda (x y) (/ (+ x y) 2)) pt1 pt2)
pt2 (mapcar '- pt2 pt1)
box (vla-addBox
Space
(vlax-3d-point cen)
(car pt2)
(cadr pt2)
(caddr pt2)
)
)
)
)
(if (= (vla-get-ObjectName obj) "AcDbText")
(progn
(setq norm (vlax-get obj 'Normal)
)
(vla-Move
box
(vlax-3d-point (trans '(0 0 0) norm 0))
(vlax-3d-point
(trans
(list
0
0
(caddr
(trans (vlax-get obj 'InsertionPoint)
0
norm
)
)
)
norm
0
)
)
)
)
)
(mapcar '(lambda (x) (vla-TransformBy x (WCS2UCSMatrix)))
(list obj box)
)
)
)
(vla-endUndoMark AcDoc)
(princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost