maksolino Posted February 27, 2011 Posted February 27, 2011 hello i would like to have this kind of lisp 1.get the mtext that i wont to move 2.get the relative x,y moving coord. (like 100,150) The mtext is deeply in the block so I must 5 times do double click. Thanks Quote
Tharwat Posted February 27, 2011 Posted February 27, 2011 Check this out Buddy. (defun c:Action (/ Block Obj) ;; Tharwat 27. 02. 2011 (vl-load-com) (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object) ) ) (if (and (eq :vlax-false (vla-get-isLayout block)) ; Lee Technique (eq :vlax-false (vla-get-isXref block)) ; Lee Technique ) (vlax-for obj block (if (eq "AcDbMText" (vla-get-objectname obj)) (vla-move obj (vlax-3d-point '(0. 0. 0.)) (vlax-3d-point '(100. 150. 0.)) ) ) ) ) ) (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports ) (princ) ) Tharwat Quote
pBe Posted February 27, 2011 Posted February 27, 2011 or this: (defun c:MovT (/ doc ent_ ent pt1 blk) (vl-load-com) (if (setq ent_ (nentsel "\nSelect MTEXT:")) (progn (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) ent (vlax-ename->vla-object (car ent_)) blk (vla-ObjectIdToObject doc (vla-get-OwnerID ent)) ) (vla-Move ent (vlax-3d-point (setq pt1 (mapcar '+ (last (caddr ent_))(cdr (assoc 10 (entget (car ent_))))))) (vlax-3d-point (getpoint pt1 "\nNew point:"))) (vla-get-Count blk) (vla-update ent) ) ) (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports) ) Quote
Lee Mac Posted February 27, 2011 Posted February 27, 2011 When modifying subentities of a block, you need to bear in mind that the block definition is at defined in the WCS plane at unit scale and zero rotation. Hence if the user selects MText contained in a block with properties other than the block definition, there must be a transformation of the displacement vector to account for the change in Normal/Scale/Rotation (similar to the method implemented here). This will account for all UCS/Views and all Block Scales/Rotations: (defun c:MoveMtextinBlock ( / block doc mat mt p1 p2 sel vec ) (vl-load-com) ;; © Lee Mac 2011 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (if (and (progn (while (progn (setvar 'ERRNO 0) (setq sel (nentselp "\nSelect MText Inside Block: ")) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, Try Again.") ) ( (and (= 4 (length sel)) (eq "MTEXT" (cdr (assoc 0 (entget (car sel)))))) (setq mt (vlax-ename->vla-object (car sel)) block (vlax-ename->vla-object (last (last sel))) ) nil ) ( (princ "\n** Invalid Object Selected **") ) ) ) ) mt ) (setq p1 (getpoint "\nBase Point: ")) (setq p2 (getpoint "\nSecond Point: " p1)) ) (progn (setq mat (LM:Geom->Def block) vec (mxv mat (mapcar '- (trans p2 1 0) (trans p1 1 0))) ) (vla-move mt (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point vec)) (vla-regen doc acAllViewports) ) ) (princ) ) ;;---------------------=={ Geom->Def }==----------------------;; ;; ;; ;; Returns the Transformation Matrix for transforming Block ;; ;; Geometry to the Block Definiton. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; SourceBlock - VLA Block Reference Object ;; ;;------------------------------------------------------------;; ;; Returns: A 3x3 Transformation Matrix ;; ;;------------------------------------------------------------;; (defun LM:Geom->Def ( SourceBlock / norm ang x y z ) ;; © Lee Mac 2010 (vl-load-com) (setq norm (vlax-get SourceBlock 'Normal) ang (- (vla-get-rotation SourceBlock))) (mapcar 'set '(x y z) (mapcar (function (lambda ( prop alt ) (/ 1. (vlax-get-property SourceBlock (if (vlax-property-available-p SourceBlock prop) prop alt) ) ) ) ) '(XEffectiveScaleFactor YEffectiveScaleFactor ZEffectiveScaleFactor) '(XScaleFactor YScaleFactor ZScaleFactor ) ) ) (mxm (list (list x 0. 0.) (list 0. y 0.) (list 0. 0. z) ) (mxm (list (list (cos ang) (sin (- ang)) 0.) (list (sin ang) (cos ang) 0.) (list 0. 0. 1.) ) (mapcar (function (lambda ( e ) (trans e norm 0 t)) ; OCS->WCS ) '((1. 0. 0.) (0. 1. 0.) (0. 0. 1.)) ) ) ) ) (defun mxv ( mat vec ) (mapcar '(lambda ( row ) (apply '+ (mapcar '* row vec))) mat) ) (defun mxm ( m q ) (mapcar (function (lambda ( r ) (mxv (trp q) r))) m) ) (defun trp ( m ) (apply 'mapcar (cons 'list m)) ) I believe the above could be accomplished using the inverse of the matrix returned by the nentselp selection, but I'm not sure that there would be much of a difference in performance to the method I have used above. Quote
alanjt Posted February 27, 2011 Posted February 27, 2011 I didn't realize RefEdit was so many steps. Quote
pBe Posted February 28, 2011 Posted February 28, 2011 I didn't realize RefEdit was so many steps. guess you're right Quote
Lee Mac Posted February 28, 2011 Posted February 28, 2011 I didn't realize RefEdit was so many steps. I'm with you on that one On a more serious note, my code was more for academic purposes (for what its worth) - in reality you would never go down this route, needing a separate program for every modification method... Quote
alanjt Posted February 28, 2011 Posted February 28, 2011 Sadly, this guy's running around using a RefEdit replacement. Quote
Tharwat Posted February 28, 2011 Posted February 28, 2011 Sadly, this guy's running around using a RefEdit replacement. What is the RefEdit related to the thread ? Quote
alanjt Posted February 28, 2011 Posted February 28, 2011 I guess Lee removed his BEdit comment. Look at RefEdit and you'll see it's basically what one would need to accomplish block altered such as this. Quote
Tharwat Posted February 28, 2011 Posted February 28, 2011 I guess Lee removed his BEdit comment. . Right , I have seen that in the message alerts to my Email. . Look at RefEdit and you'll see it's basically what one would need to accomplish block altered such as this. I could not find it in the cad help !!!! Quote
Lee Mac Posted February 28, 2011 Posted February 28, 2011 I guess Lee removed his BEdit comment. Yup - was off the mark and didn't want to add further confusion to this thread. Quote
alanjt Posted February 28, 2011 Posted February 28, 2011 I could not find it in the cad help !!!!Just type the command and try it. Yup - was off the mark and didn't want to add further confusion to this thread. Right on. Quote
maksolino Posted March 1, 2011 Author Posted March 1, 2011 Thanks to All for replay I have one more request for this lisp I would like to have the possibility to select more that one text regards Quote
maksolino Posted March 1, 2011 Author Posted March 1, 2011 In this attachment You can better understand my problem. I have to move the text value of x coordinate upper (in too many sketch-is and also in too many drawings) Thanks sq.dwg 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.