Autocad doesn't read my l
Hellow, i'm trying to write a very simple code from scratch, i want it to read the angle position and width of a mtext. and if the angle is 0 (means the text is horizontal), then he performs a couple of replacements in code groups.This is what I've manage to do:
(defun c:ter2 ( / entitysel enty position angle newposition newangle substituteangle substituteposition)(setq entitysel(car (entsel)) enty(entget entitysel) angle(assoc 50 enty) position (assoc 10 enty) mtextwidth (assoc 41 enty))(if(= angle 0) (setq newposition '(10 . (cadr(position)) (- caddr(position) 0.25)) ;gets the coordinate x and y and for y lowers 0.25, all of this in the variable newposition substituteposition (subst newposition position enty) ;defines something like a "method" that entmod will apply. ) (entmod substituteposition) ;replaces the position)(princ))
I know i can limit the object to mtext and i will implement a ssget later. But for now what i wanna know is why can't this code perform as i think he should, replacing the positioning of my text when he is horizontal does it have to do with scope? maybe variable angle only has meaning inside the first setq parameters? but that would be dumb I would instead make use of the vla-get-TextRotation function.
(if (= (vla-get-TextRotation (vlax-ename->vla-object enty)) 0)Put rest of code) This was just a quick code writing so I'm sorry if there is a mistake. Perhaps something like this:
(defun c:ter2 ( / entitysel enty position _angle newposition newangle substituteangle substituteposition)(setq entitysel(car (entsel)) enty(entget entitysel) _angle(cdr (assoc 50 enty)) position (assoc 10 enty) mtextwidth (cdr (assoc 41 enty)))(if (= _angle 0) (progn (setq newposition (cons 10 (list (cadr position) (- (caddr position) 0.25))) ;gets the coordinate x and y and for y lowers 0.25, all of this in the variable newposition substituteposition (subst newposition position enty) ;defines something like a "method" that entmod will apply. ) (entmod substituteposition) ;replaces the position ) )(princ))
Hope this helps
Henrique First of all, 'angle' is reserved word
Secondary, you forgot progn:
(vl-load-com)(defun c:ter2 (/ ent ins) (if (= (type (setq ent (vl-catch-all-apply (function (lambda () (ssget "_+.:S:E:L" '((0 . "MTEXT"))) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of type 'pickset ) ;_ end of = (progn (setq ent (vlax-ename->vla-object (ssname ent 0)) ins (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint ent))) ) ;_ end of setq (if (equal (vla-get-rotation ent) 0. 1e-3) (vla-put-insertionpoint ent (vlax-3d-point (list (car ins) (- (caddr ins)) 0.25))) ) ;_ end of if ) ;_ end of progn ) ;_ end of if ) ;_ end of defun
Ah, already answered:)
页:
[1]