Jump to content

using sendCommand


salman

Recommended Posts

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)

)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...