AAONCAD Posted August 11, 2009 Posted August 11, 2009 I have accesed the original code for a series commands that perform simple operations; they operate fine in Acad 14 but, will not execute in 2010. any recognizable problems? i.e the one listed "MC27" is supposed to change text to read MC27 but it doesn't. (defun c:27 () ;ECN MC27 REV BENDS ADD DECIMALS (6/9/08) (setvar "cmdecho" 0) (setq obj (entsel "\nPick Location :")) (setq a "MC27" ) (setq j (strcat a)) (command "change" obj "" "" "" "" "" "" j)) also I have a PDF attachment showing an option needed through DCL it's 263 kb and I can't attach it through Cad tutor. Will anyone interested in taking a look please email me at mcclain@aaon.com thank you for any reply's Quote
Lee Mac Posted August 11, 2009 Posted August 11, 2009 A few things, There is no need for: (setq j (strcat a)) You are only dealing with one string, hence you don't need to concatenate it. You have not localised your variables, this is not good programming practice, the funciton definition should look something like: (defun c:27 (/ obj a) I would recommend that you use more descriptive variable names, "obj" is OK, but refrain from using single letters. The code will then be easier to read. You will need to use: (car (entsel "\nPick Text: ")) As entsel returns a list with two elements, the first being the entity name and the second being the pick point. I would refrain from using the change command to change your text, instead, look into entmod. IMPORTANT: you have not reset the system variable CMDECHO. Whilst this may not be noticeable too much with CMDECHO, it is very bad practice and can lead to undesired results, especially when using other sys vars. I would use a conditional statement, like the IF function, to allow for a missed pick, or no user input. Use (princ) at the end of the program to exit the program cleanly, i.e. suppress the last function return. Hope this helps, Lee Quote
AAONCAD Posted August 11, 2009 Author Posted August 11, 2009 thank you Lee for your tips. If you would take this code load it and type a string of text(anything) and input 27 into command line and see why it will not change the text to MC27. (defun c:27 (/ obj a) ;ECN MC27 REV BENDS ADD DECIMALS (6/9/08) (setvar "if" 0) (car (entsel "\nPick Location: ")) (setq a ("MC27") (setq j (strcat a) (command "entmod" obj "" "" "" "" "" "" j)) (princ) Quote
CADMASTER1128 Posted August 11, 2009 Posted August 11, 2009 What does it do? It won't work on my computer. Quote
AAONCAD Posted August 11, 2009 Author Posted August 11, 2009 hello, thanks for your interest. My goal is to take any random text string and enter 27 for then command; it the prompts user to pick a point, and then changes text to read MC27 Quote
flowerrobot Posted August 12, 2009 Posted August 12, 2009 Mate nice effort, but i belive lee's ment some thing more like this (defun c:27 (/ ss) (setvar "cmdecho" 0) (While (not ss) ;Entsel lets you only have one shot at selecting and item, So while lets you have as many attemps (setq ss (entget (car (entsel "\nSelect text :"))))) (if (= (cdr (assoc 8 ss)) "text") ;Useing a If statement to make sure the item is text. (entmod ;Entmod is a way of altering entites, (subst (cons 1 "MC27") (assoc 1 ss) ss)) ;I used Subst, to substatue the text already there, (Princ "You did not select text") ) (setvar "cmdecho" 1) ; Turn cmdecho back on. (princ) ) Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 Flower, Entget will return an error if supplied with nil, so your while would not work. "0" is the DXF code for the entity type, not 8 Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 Rather, I was thinking something like this: (defun c:27 (/ ent) (if (and (setq ent (car (entsel "\nPick Text: "))) (wcmatch (cdr (assoc 0 (entget ent))) "*TEXT")) (entmod (subst (cons 1 "MC27") (assoc 1 (entget ent)) (entget ent))) (princ "\n** Object is not Text **")) (princ)) Quote
flowerrobot Posted August 12, 2009 Posted August 12, 2009 Flower, Entget will return an error if supplied with nil, so your while would not work. "0" is the DXF code for the entity type, not 8 Ahh i didnt kno that, I normally would of done while looking for text but didnt cause im wack job if you look at text & mtext they both refer to dxf 8 as text, and so i used that instead of a wcmatch Quote
flowerrobot Posted August 12, 2009 Posted August 12, 2009 Wow, I really am that dumb. I forgot i have reators running to keep all text on text layer. i really cannot belive that nothing fired that 8 is layer, And not some wounderouse dxf group that sum's what it type of item it is. Wow Quote
flowerrobot Posted August 12, 2009 Posted August 12, 2009 You know what i carnt even blame the hang over and lack of coffee I shall go burrow my head in the sand :'( Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 For future reference: http://autodesk.com/techpubs/autocad/acad2000/dxf/ Quote
flowerrobot Posted August 12, 2009 Posted August 12, 2009 thanks for that. Its not that i didnt know 8 is layer, its that well i dont know, I thought it was some randomly new dxf that would fix all my drama's lol Quote
AAONCAD Posted August 12, 2009 Author Posted August 12, 2009 Lee, that's great it worked, thank you also flowerrobot. You have increased drawing efficency by 15% Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 This may increase it further (defun c:27 (/ ss) (vl-load-com) (if (setq ss (ssget '((0 . "*TEXT")))) (mapcar (function (lambda (Obj) (vla-put-TextString Obj "MC27"))) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))) (princ)) Quote
AAONCAD Posted August 12, 2009 Author Posted August 12, 2009 thanks Lee would you be intersted in viewing my screen option s to help determine & update new dcl/vlisp routines? Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 I could take a look, but as Se7en points out - what am I likely to gain from a picture? Quote
CADMASTER1128 Posted August 12, 2009 Posted August 12, 2009 Where would we be without Lee Mac...OH yea, LISP less... haha 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.