TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fabricio28 on May 21, 2014, 10:11:27 AM
-
Hi guys,
I wanna make a little modification in that code.
Instead of select text, I'd like to select a attribute.
Can anybody help me out please?
(defun c:t3 (/ txt1 txt2 txt3 pkt1)
(setq txt1 (entsel "Select first text : "))
(setq txt2 (entsel "Select second text : "))
(setq txt3
(strcat
(rtos (- (atof (cdr (assoc 1 (entget (car txt1)))))
(atof (cdr (assoc 1 (entget (car txt2)))))
) 2 2 ) ) )
(if (and (setq pkt1 (getpoint "Where to place difference ? : "))
(if (> (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE")))) 0)
(command "_.TEXT" pkt1 "" txt3)
(command "_.TEXT" pkt1 "" "" txt3)
))
(princ)
)
)
Thank in advance
-
Try nentsel instead of entsel.
-
wow :ugly: me lol
Just Simple!!
Thank you very much roy!!!
May ask you one more thing?
I'd like to add sum symbol (+) for positive.
Because I'm working with (+) to fill and (-) to cut
Thank you
-
(setq result (- ... ...))
(strcat (if (>= result 0) "+" "") (rtos result 2 2))
-
Finally
(defun c:t3 (/ result txt1 txt2 txt3 pkt1)
(setq txt1 (nentsel "Select first text : "))
(setq txt2 (nentsel "Select second text : "))
(setq result (- (atof (cdr (assoc 1 (entget (car txt1)))))
(atof (cdr (assoc 1 (entget (car txt2)))))
)
)
(setq txt3 (strcat (if (> result 0) "+" "") (rtos result 2 2)))
(if
(and (setq pkt1 (getpoint "Where to place difference ? : "))
(if (> (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE")))) 0)
(command "_.TEXT" pkt1 "" txt3)
(command "_.TEXT" pkt1 "" "" txt3)
)
)
(princ)
)
)
Thank you very much roy :-D
-
2nd option...
Why that code isn't working?
(defun c:t3 ()
(setq txt1 (car(entsel"\nSelecione o primeiro texto :")))
(setq txt1 (atof(cdr(assoc 1(entget txt1)))))
(setq txt2 (car(entsel"\nSelecione o segundo texto :")))
(setq txt2 (atof(cdr(assoc 1(entget txt2)))))
(setq txt3 (- txt1 txt2))
(if (>= txt3 0)
(setq txt4 (strcat "+"(rtos txt3)))
(setq txt4 (rtos txt3))
)
(setq p1 (getpoint "\nInforme o local do texto da diferença :"))
(command "text" p1 "" "" txt4 "")
)
-
Why have you added the extra enter here?:
(command "text" p1 "" "" txt4 "")
It should be:
(command "text" p1 "" "" txt4)
-
Hi roy,
I've noticed that mistake and I fixed it.
But the problem is when I pick the atributte
Alert:ERRO : bad argument type: stringp nil
Thank in advance
-
hi i noticed the the 2nd code not nentsel??
thx
since i'm still new here, so also wanna practice & learn
i hope this can be applied for TEXT, MTEXT & ATTRIB
;24/05/14 hp#006
(defun t-t (et1 et2 / tx1 tx2 ans) ; argument: text entity
(if (and et1 et2)
(if (and
(member 1(setq tx1(assoc 1 (entget (car et1)))))
(member 1(setq tx2(assoc 1 (entget (car et2))))))
(progn
(setq ans(- (atof (cdr tx1))
(atof (cdr tx2))))
(strcat (if (> ans 0) "+" "")
(rtos ans 2 2))
)
);if
)
)
(defun c:test (/ str pt)
(if
(setq str (t-t (nentsel "\nSelecione o primeiro texto : ")
(nentsel "\nSelecione o segundo texto : ")))
(setq pt (getpoint "\nInforme o local do texto da diferença : "))
); if
(if pt
(if (> (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE")))) 0)
(command "_.TEXT" pt "" str)
(command "_.TEXT" pt "" "" str)
);if txh
);if pt
(princ)
)
;p/s: however i prefer entmake for text coding.
-
@ hanhphuc:
You are right to check for correct user input but you should have another look at the way you use (if). It can be simplified. And I would not create a sub-function like your (t-t) function.
(defun c:t3 ( / oldOsmode pt result txt1 txt2)
(if
(and
(setq txt1 (car (nentsel "\nSelecione o primeiro texto: ")))
(setq txt1 (cdr (assoc 1 (entget txt1))))
(setq txt2 (car (nentsel "\nSelecione o segundo texto: ")))
(setq txt2 (cdr (assoc 1 (entget txt2))))
(setq pt (getpoint "\nInforme o local do texto da diferença: "))
)
(progn
(setq result (rtos (- (atof txt1) (atof txt2)) 2 2))
(if (> (read result) 0) (setq result (strcat "+" result)))
(setq oldOsmode (getvar 'osmode))
(setvar 'osmode 0)
(if (> (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE")))) 0)
(command "_.text" pt "" result)
(command "_.text" pt "" "" result)
)
(setvar 'osmode oldOsmode)
)
)
(princ)
)
-
Roy I would go a step further & add a String test for each object.
-
Roy I would go a step further & add a String test for each object.
According to the DXF docs gc 1 is the 'Primary text value for an entity'. If that is true checking for gc 1 would already accomplish that. Another thing would be checking for valid numerical strings.
-
Oops, sorry Roy.
-
Oops, sorry Roy.
No problem.
-
@roy_043 : Thank you for pointing irrelevant in (if & t-t) coding. i appreciate this improved my coding practice though just a single advice :-)