asos2000 Posted January 4, 2010 Posted January 4, 2010 I am new in lisp whats wrong with is routine please (defun c:harea ()(vl-load-com) (setq har (Entsel "\n Select Hatch: ")) (SETQ PNT (GETPOINT "\n Pick a point: ")) (SETQ HARA (vla-get-area HAR)) (command "text" PNt "" "0" HARA "") ) Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 Quite a lot... Entsel returns a two element list, the first of which is the entity name - you should also allow for a null selection. You should allow for the user not picking the point when using the getpoint function - just a simple "if" statement should do. vla-get-area is only applicable on a VLA-Object that has that property available. You are using it on a list (I assume you meant to use it on the entity name, but this would still need to be converted to a VLA-Object using vlax-ename->vla-object). You can check that the object has the property using vlax-property-available-p. The area returned is a Real, which needs to be converted to a string before making the text. I would recommend using entmake(x) over (command "text"... as the command call can be very unreliable. If you are using the command call, I would recommend prefixing the command with "_." to allow for language compatibility and in case the command has been re-defined. It is good practice to use "princ" at the end of the program for a clean exit. Your variables should also be localised. All this information can be found in the Visual LISP Editor Help files. Lee Quote
asos2000 Posted January 4, 2010 Author Posted January 4, 2010 Thanx LEE for very fast reply what about this (defun c:harea () (vl-load-com) (initget 1) ;Is it to allow for a null selection? (setq har (car (Entsel "\n SELECT hATCH: "))) (SETQ PNT (GETPOINT "\n PICK A POINT: ")) (vlax-ename->vla-object har) (SETQ HARA (vla-get-area HAR)) (rtos hara 2 4) (command "text" pNt "" "0" hara "") (princ) ) Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 More along these lines: (defun c:harea (/ ent pt obj area) (vl-load-com) (if (and (setq ent (car (entsel "\nSelect Object: "))) (setq pt (getpoint "\nPick a Point: "))) (progn (setq obj (vlax-ename->vla-object ent)) (if (vlax-property-available-p obj 'Area) (progn (setq area (rtos (vla-get-Area obj) 2 4)) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 (getvar "TEXTSIZE")) (cons 1 area)))) (princ "\n** Invalid Object Selected **")))) (princ)) The above is not exactly how I would approach it, but it will give you an idea. Lee Quote
asos2000 Posted January 5, 2010 Author Posted January 5, 2010 thanx lee but let me ask you What is deference between entmakex and entmake? How to use the default text style not standard style? Quote
Lee Mac Posted January 5, 2010 Posted January 5, 2010 entmakex will return the newly created enitity name, and so it is more useful if you wish to manipulate the resulting entity. In this case, either may be used. If you do not provide entmake(x) will various DXF group codes, the default values for these are assumed. 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.