Author Topic: vla-sendcommand...does it always run last?  (Read 2806 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
vla-sendcommand...does it always run last?
« on: October 19, 2016, 08:39:10 AM »
Like the subject says... regardless of where it is within the program, it always seems to run last. Is this the case? Any tips or tricks to get around this??
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: vla-sendcommand...does it always run last?
« Reply #1 on: October 19, 2016, 08:50:13 AM »
Yes. Basically the CAD program will execute the command when it has finished with any current and pending tasks (including Lisp-expressions).
Just use this instead:
Code: [Select]
(command ...)
(command-s ...)
(vl-cmdf ...)

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: vla-sendcommand...does it always run last?
« Reply #2 on: October 19, 2016, 09:53:10 AM »
Okay then. Maybe it's the code itself that isn't right. I can't get the MESHSMOOTH command to work within a LSP program. Here's my code. I'm extruding rectangles, converting them to surfaces then need to run the MESHSMOOTH command on the surfaces but it always fails. Unless I use vla-sendcommand, but the problem with that is that I need to add code AFTER meshsmooth.

Code - Text: [Select]
  1. (defun C:MeshTest ( / ssSel ssObj1 ssObj ssCnt ssItems)
  2.   (setq ssSel (ssadd))
  3.   (setq ssItems (ssget))
  4.   (setq ssCnt 0)
  5.   (while (< ssCnt (sslength ssItems))
  6.     (setq ssObj1 (ssname ssItems ssCnt))
  7.     (setq ssObj ssObj1)
  8.     (command "extrude" ssObj "" "25" "")
  9.     (command "convtosurface" (entlast) "")
  10.         (vl-cmdf "meshsmooth" (entlast) "")  <--- FAILS HERE. ALWAYS!!
  11.         ;;; MORE CODE TO GO HERE...
  12.     (setq ssCnt (+ ssCnt 1))
  13.   )
  14.   (princ)
  15. )
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

ifncdylan

  • Guest
Re: vla-sendcommand...does it always run last?
« Reply #3 on: October 20, 2016, 01:53:52 AM »
As far as multiple calls of MESHSMOOTH goes, I'm not sure you can achieve it inside a while loop.

However, you could use the while loop to calculate every command that is required to take place and then execute the commands via vla-sendcommand. Tested this below and it works to perform a MESHSMOOTH and then MESHSMOOTHLESS on multiple objects. Technically it could also call any function code you have written which would perform multiple complex lisp operations on an object.

The trick here is that the vla-sendcommand code cannot take an entity as input like vl-cmdf or command, instead, it requires a string only; however you can type variable names into the prompt; so this code attempts to set every object you've selected into it's own variable (obj1, obj2, obj3, ...) and then builds an array of commands to call using the !obj1 or !obj2 reference. Finally, it executes all those commands in sequence.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:MultiSmooth ( / objects objlst varnam varlst varset lst)
  2.   (setq objects (ssget)
  3.         objlst (setq l nil i 0 x (repeat (sslength objects) (progn (setq l (cons (ssname objects i) l) i (1+ i)))) x l)
  4.         varnam (reverse (setq i 0 names nil names (repeat 3 (setq names (cons (strcat "obj" (rtos (setq i (1+ i)) 2 0)) names)))))
  5.         varlst (mapcar 'read varnam)
  6.         varset (mapcar 'set varlst objlst)
  7.         lst nil)
  8.   (foreach obj varnam
  9.     (setq lst (cons (strcat "MESHSMOOTH !" obj "  ") lst)
  10.           lst (cons (strcat "MESHSMOOTHLESS !" obj "  ") lst)
  11.           lst (reverse lst)
  12.           )
  13.     )
  14.   (vla-sendcommand acdoc (LM:lst->str lst "\n"))
  15. )
  16.    
  17. (defun LM:lst->str ( lst del )
  18.     (if (cdr lst)
  19.         (strcat (car lst) del (LM:lst->str (cdr lst) del))
  20.         (car lst)
  21.     )
  22. )
  23.  

ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: vla-sendcommand...does it always run last?
« Reply #4 on: October 20, 2016, 04:24:13 AM »
Okay then. Maybe it's the code itself that isn't right. I can't get the MESHSMOOTH command to work within a LSP program. Here's my code. I'm extruding rectangles, converting them to surfaces then need to run the MESHSMOOTH command on the surfaces but it always fails. Unless I use vla-sendcommand, but the problem with that is that I need to add code AFTER meshsmooth.

Code - Text: [Select]
  1. (defun C:MeshTest ( / ssSel ssObj1 ssObj ssCnt ssItems)
  2.   (setq ssSel (ssadd))
  3.   (setq ssItems (ssget))
  4.   (setq ssCnt 0)
  5.   (while (< ssCnt (sslength ssItems))
  6.     (setq ssObj1 (ssname ssItems ssCnt))
  7.     (setq ssObj ssObj1)
  8.     (command "extrude" ssObj "" "25" "")
  9.     (command "convtosurface" (entlast) "")
  10.         (vl-cmdf "meshsmooth" (entlast) "")  <--- FAILS HERE. ALWAYS!!
  11.         ;;; MORE CODE TO GO HERE...
  12.     (setq ssCnt (+ ssCnt 1))
  13.   )
  14.   (princ)
  15. )

Without this :
Code - Text: [Select]
  1. ;;; MORE CODE TO GO HERE...
  2.  
I doubt that someone will be able to help you... But try your own skills, maybe you'll overcome this problem, but for only this specific situation IMHO...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ahsattarian

  • Newt
  • Posts: 112
Re: vla-sendcommand...does it always run last?
« Reply #5 on: November 01, 2022, 04:08:30 AM »
Try This  :



Code - Auto/Visual Lisp: [Select]
  1. (defun c:a ()
  2.   (setq ss (ssget ":l"))
  3.   (setq txt "")
  4.   (setq method1 1)
  5.   (cond
  6.     ((= method1 1) ;|  One-by-One  |;
  7.      (setq li1 nil)
  8.      (setq n (sslength ss))
  9.      (setq k -1)
  10.      (repeat n (setq k (1+ k)) (setq s (ssname ss k)) (setq li1 (cons s li1)))
  11.      (setq i 0)
  12.      (setq li2 nil)
  13.      (repeat n (setq i (1+ i)) (setq li2 (append li2 (list (strcat "s" (itoa i))))))
  14.      (setq li3 (mapcar 'read li2))
  15.      (setq li4 (mapcar 'set li3 li1))
  16.      (foreach s li2 (setq txt (strcat txt "chprop !" s "  color 2  ")))
  17.     )
  18.     ((= method1 2) ;|  All-Together  |;
  19.      (setq nam (strcat (menucmd "M=$(edtime,$(getvar,date),YYYYMODDHHMMSS)") (itoa (abs (getvar "millisecs")))))
  20.      (command "group" "create" nam "" ss "" "")
  21.      (setq txt (strcat txt "chprop group " nam "  color 2  "))
  22.     )
  23.     ((= method1 3) (setq txt (strcat txt "chprop !ss  color 2  "))) ;|  All-Together  |;
  24.   )
  25. )



..
« Last Edit: November 01, 2022, 08:40:38 AM by ahsattarian »