Sandeep RC Posted June 19 Posted June 19 (edited) Hello, can anybody help me with the lisp routine that can rotate multiple blocks placed at the end of polyline in the direction of polyline? I think this can be done by considering the reference that all the polylines are drawn from center to outward direction. Please see the attached CAD file for reference. drawing 2.dwg Edited June 19 by Sandeep RC Quote
EnM4st3r Posted June 19 Posted June 19 how about placing them anew? made a function like that recently just changed it a bit (defun c:placetest (/ doc sel bname ent amount) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (if (setq sel (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")))) (progn (setq bname "fj") ;; edit -- possibly getstring (if (= bname "") (progn (while (or (not ent)(not (= (cdr (assoc 0 (entget ent))) "INSERT"))) (setq ent (car (entsel "\nSelect Block: "))) ) (setq bname (vla-get-effectivename (vlax-ename->vla-object ent))) ) ) (if (not (tblsearch "Block" bname)) (progn (princ "\nError: Blockname invalid.") (exit))) (vlax-for obj (setq sel (vla-get-activeselectionset doc)) (placeBlk (vla-get-modelspace doc) obj bname) ) (vla-delete sel) ) ) (princ) ) ;| Places a block at the end of a Curve @Param space \<vla-object> Types: Block, ModelSpace, PaperSpace @Param cObj \<vla-object> Curve Object @Param bname \<string> Block Name @Returns ? |; (defun placeBlk (space cObj bname / *error* osmode dist obj rltvAng) (defun *error* (msg) (if osmode (setvar "osmode" osmode)) (princ (strcat "Error: " msg)) (princ) ) (setq osmode (getvar "osmode")) (setvar "osmode" 0) (setq rltvAng 0) (setq dist (vlax-curve-getdistatparam cObj (vlax-curve-getendparam cObj))) (setq pt (vlax-curve-getpointatdist cObj dist)) (vla-insertblock space (vlax-3d-point pt) bname 1 1 1 (+ (get-curve-angle cObj dist) rltvAng)) (setvar "osmode" osmode) ) (defun pauseCmdTillEnd () (while (= 1 (getvar "cmdactive")) (command pause)) ) (defun get-curve-angle (cObj dist / deriv) (setq deriv (vlax-curve-getFirstDeriv cObj (vlax-curve-getParamAtDist cObj dist))) ; get vector (atan (cadr deriv) (car deriv)) ; Calculate the angle of the tangent vector ) Quote
EnM4st3r Posted June 19 Posted June 19 or this would allow you to change the relativ angle for the block placement wich is more like what i originally used (defun c:placetest (/ doc sel bname ent amount rltv) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (if (setq sel (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")))) (progn (setq bname "fj") ;; edit -- possibly getstring (if (= bname "") (progn (while (or (not ent)(not (= (cdr (assoc 0 (entget ent))) "INSERT"))) (setq ent (car (entsel "\nSelect Block: "))) ) (setq bname (vla-get-effectivename (vlax-ename->vla-object ent))) ) ) (if (not (tblsearch "Block" bname)) (progn (princ "\nError: Blockname invalid.") (exit))) (vlax-for obj (setq sel (vla-get-activeselectionset doc)) (setq rltv (placeBlk (vla-get-modelspace doc) obj bname rltv)) ) (vla-delete sel) ) ) (princ) ) ;| Places a block at the end of a Curve @Param space \<vla-object> Types: Block, ModelSpace, PaperSpace @Param cObj \<vla-object> Curve Object @Param bname \<string> Block Name @Param rltvAng \<real> relative angle as real @Returns \<real> relative angle as real |; (defun placeBlk (space cObj bname rltvAng / *error* osmode dist obj ) (defun *error* (msg) (if osmode (setvar "osmode" osmode)) (princ (strcat "Error: " msg)) (princ) ) (setq osmode (getvar "osmode")) (setvar "osmode" 0) (setq dist (vlax-curve-getdistatparam cObj (vlax-curve-getendparam cObj))) (setq pt (vlax-curve-getpointatdist cObj dist)) (if rltvAng (vla-insertblock space (vlax-3d-point pt) bname 1 1 1 (+ (get-curve-angle cObj dist) rltvAng)) (progn (setq obj (vla-insertblock space (vlax-3d-point pt) bname 1 1 1 0)) (setvar "osmode" osmode) (command "_rotate" (vlax-vla-object->ename obj) "" pt) (pauseCmdTillEnd) (setq rltvAng (- (vla-get-rotation obj) (get-curve-angle cObj dist))) (setvar "osmode" 0) ) ) (setvar "osmode" osmode) rltvAng ) (defun pauseCmdTillEnd () (while (= 1 (getvar "cmdactive")) (command pause)) ) (defun get-curve-angle (cObj dist / deriv) (setq deriv (vlax-curve-getFirstDeriv cObj (vlax-curve-getParamAtDist cObj dist))) ; get vector (atan (cadr deriv) (car deriv)) ; Calculate the angle of the tangent vector ) Quote
Sandeep RC Posted June 19 Author Posted June 19 @EnM4st3r Just checked both the codes. The first one is the one i wanted. cheers mate. much appreciated. Tomorrow i will run on my actual file that contains around 2500 plines. Thank a lot once again. 1 Quote
Recommended Posts
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.