salman Posted May 30, 2010 Share Posted May 30, 2010 I have 2 short lisp programs tst.lsp & cm.lsp tst.lsp simply runs a loop and calls cm.lsp 3 times inside that loop using sendCommand method but the code is not working properly. cm.lsp simply moves the selected object. The issue is that the cm.lsp gets called only once but the loop runs three times if we print an alert statement inside the loop.Please guide what is the problem. (defun c:tst() (vl-load-com) (load "d:/cm.lsp") (setq cad(vlax-get-acad-object)) (setq doc(vla-get-activedocument cad)) (repeat 3 (vla-sendcommand doc "cm\r") ) ) ( defun cm() (setq oldOsMode(getvar "OSMODE")) ; Enable End Point & Nearest object snap. (setvar "OSMODE" 513) (setq basePt (getpoint "Select object to move: ")) (setq ss (ssget basePt)) ; Check for valid selection. (if(= nil ss) (progn (alert "No object selected!") (exit) ) ) (setq objName (ssname ss 0)) (setq objData (entget objName)) (setq objType (cdr (assoc 0 objData))) (if(= objType "INSERT") (setq basePt(cdr(assoc 10 objData))) ) (command "move" objName "" basePt) (setvar "OSMODE" oldOsMode) ) Quote Link to comment Share on other sites More sharing options...
gile Posted May 30, 2010 Share Posted May 30, 2010 Hi, Avoid using SendCommand which is a COM method. Prefer AutoLISP command or vl-cmdf functions. But, while you're calling a LISP function from another one you don't need to use these functions. Instead of (repeat 3 (command (cm))) just write: (repeat 3 (cm)) If you want to loop, the cm fuvtion have to terminate so add a 'pause' at the end of the (command "_move" ...) statement: (command "_move" objName "" basePt pause) Look at the entsel function rather than use the ssget one for a selection by one point. Quote Link to comment Share on other sites More sharing options...
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.