Author Topic: vla-SendCommand  (Read 726 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Bull Frog
  • Posts: 235
vla-SendCommand
« on: February 16, 2021, 03:58:50 PM »
I am trying to use vla-SendCommand
. . .
I want insert a block

The name of block contains spaces

(vla-SendCommand
(:ACTIVE_DOCUMENT)
"insert\r[ pianta - wc - vaso handicappati ] \rX\r1.000000000000000\rY\r1.000000000000000\rZ\r1.000000000000000\r
R\r0.000000000000000\r97.00425524590635,278.3699102983844,0.000000000000000\r")

does not work !

why ?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1189
  • Marco
Re: vla-SendCommand
« Reply #1 on: February 18, 2021, 10:48:31 AM »
Not tested…

Code: [Select]
(vla-SendCommand
(:ACTIVE_DOCUMENT)
"insert\r\"[ pianta - wc - vaso handicappati ]\" \rX\r1.000000000000000\rY\r1.000000000000000\rZ\r1.000000000000000\r
R\r0.000000000000000\r97.00425524590635,278.3699102983844,0.000000000000000\r")

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #2 on: February 18, 2021, 01:42:58 PM »
this happens, with your modified code
« Last Edit: February 18, 2021, 01:51:09 PM by domenicomaria »

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #3 on: February 18, 2021, 01:50:01 PM »
I solved this issue in this way :

Define a DEFUN internally to the main defun, that does everything :
(defun C:IB-COMMAND ()
   (vl-cmdf "insert"  current-block-name "x" 1.0 "y" 1.0 "z" 1.0 "r" 0.0 DropPoint)
)
Where current-block-name and DropPoint
are global for the internal defun and local for the main defun.

Use dcl-sendstring  in this way :
(dcl-sendstring "IB-COMMAND")


. . . on the Drag&Drop event,
from a MODELESS form
of an OpenDCL dialog . . .
« Last Edit: February 19, 2021, 05:07:47 AM by domenicomaria »

BIGAL

  • Swamp Rat
  • Posts: 674
  • 30 + years of using Autocad
Re: vla-SendCommand
« Reply #4 on: February 18, 2021, 06:12:27 PM »
Can use normal (command "-insert" with vl-cmdf probably want -insert as well
Code: [Select]
(command "-insert" "a b c d e" (getpoint) 1 1 0)

(setq bname "a b c d e")
(command "-insert" bname pt 1 1 0)

(vl-cmdf "insert  current-block-name Droppoint 1.0 1.0 1.0 0.0") not tested
A man who never made a mistake never made anything

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1189
  • Marco
Re: vla-SendCommand
« Reply #5 on: February 19, 2021, 02:42:15 AM »
this happens, with your modified code
Tested:
Code: [Select]
Comando: (vla-SendCommand
(_> (vla-get-activedocument (vlax-get-acad-object))
(_> (strcat
((_>  "_-insert \"[ pianta - wc - vaso handicappati ]\" \rX\r1.000000000000000\rY\r1.000000000000000\rZ\r1.000000000000000\r"
((_>  "R\r0.000000000000000\r97.00425524590635,278.3699102983844,0.000000000000000\r"
((_> )
(_> )
nil


Comando: _-insert Digitare nome del blocco o [?]: "[ pianta - wc - vaso handicappati ]"


Unità: Senza unità   Conversione:         1
Specificare punto di inserimento o [puntoBase/Scala/X/Y/Z/Ruota]: X
Specificare fattore di scala X <1>: 1.000000000000000
Specificare punto di inserimento o [puntoBase/Scala/X/Y/Z/Ruota]: Y
Specificare fattore di scala Y <1>: 1.000000000000000
Specificare punto di inserimento o [puntoBase/Scala/X/Y/Z/Ruota]: Z
Specificare fattore di scala Z <1>: 1.000000000000000
Specificare punto di inserimento o [puntoBase/Scala/X/Y/Z/Ruota]: R


Specificare angolo di rotazione <0.00>: 0.000000000000000
Specificare punto di inserimento o [puntoBase/Scala/X/Y/Z/Ruota]: 97.00425524590635,278.3699102983844,0.000000000000000

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #6 on: February 19, 2021, 03:08:07 AM »
Marco, it works.

However
(setq x-block-name "MY BLOCK NAME WITH SPACES")
(defun C:IB ()   
   (command "_-insert" x-block-name "X" 1.0 "Y" 1.0 "Z" 1.0 "R" 0.0 '(0.0 0.0 0.0) )
)

(vla-SendCommand (vla-get-activedocument (vlax-get-acad-object) ) "IB\n" )

(dcl-sendstring "IB\n")

works too.
without a little bit complex STRCAT . . .
. . .
Because we have to create the STRING to SEND at RUN TIME
. . .


« Last Edit: February 19, 2021, 03:13:35 AM by domenicomaria »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1189
  • Marco
Re: vla-SendCommand
« Reply #7 on: February 19, 2021, 06:25:12 AM »
<clip>
without a little bit complex STRCAT . . .
<clip>
It was an example for the long string...
Code: [Select]
Without strcat
(vla-SendCommand
 (vla-get-activedocument (vlax-get-acad-object))
  "_-insert \"[ pianta - wc - vaso handicappati ]\"\nX 1.0 Y 1.0 Z 1.0 R 0.0 0.0,0.0,0.0\n"
)
Code: [Select]

Without defun
(setq bn "\"[ pianta - wc - vaso handicappati ]\"")
(vla-SendCommand
 (vla-get-activedocument (vlax-get-acad-object))
  (strcat "_-insert " bn "\nX 1.0 Y 1.0 Z 1.0 R 0.0 0.0,0.0,0.0\n")
)

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #8 on: February 19, 2021, 02:35:12 PM »
i want mean :

Code - Auto/Visual Lisp: [Select]
  1. (setq block-name "albero-03"
  2.                 X-scale-factor 1.30
  3.                 y-scale-factor 1.30
  4.                 z-scale-factor 1.00
  5.                 r-angle       45.0
  6.                 ins-pt       (list 2.343 4.654 5.564)
  7. )
  8.  
  9.         "_-insert "
  10.         "\""
  11.         block-name
  12.         "\""
  13.         "\nX"
  14.         (rtos X-scale-factor 2 9)
  15.         "\nZ"
  16.         (rtos Y-scale-factor 2 9)
  17.         "\nZ"
  18.         (rtos Z-scale-factor 2 9)
  19.         "\nR"
  20.         (rtos r-angle 2 9)
  21.         "\n"
  22.         (rtos (car ins-pt) 2 9)
  23.         ","
  24.         (rtos (cadr ins-pt) 2 9)
  25.         ","
  26.         (rtos (caddr ins-pt) 2 9)
  27.         "\n"
  28. )
  29.  
  30. "_-insert \"albero-03\"\nX1.300000000\nZ1.300000000\nZ1.000000000\nR45.000000000\n2.343000000,4.654000000,5.564000000\n"
  31.  

this is a "long" string to create at run time.

While if we create a defun
we send the defun name instead of this "long" string . . .
. . .
it is more simple

BIGAL

  • Swamp Rat
  • Posts: 674
  • 30 + years of using Autocad
Re: vla-SendCommand
« Reply #9 on: February 19, 2021, 08:05:32 PM »
I am still a bit confused as to why your even using send-command it is not necessary and over complicated, as I posted using command method, you can also use vla-insertblock or a entmake method. Just google examples took like 3 seconds to find.
A man who never made a mistake never made anything

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #10 on: February 20, 2021, 12:28:30 AM »
BIGAL
I am still a bit confused too !
Because you are right !
It works however !

I was sure that in a Drag&Drop (drop in ACAD or BCAD) event defun,
I needed to use dcl-sendstring or vla-SendCommand . . .

This because, recently, in another situation
(but now I don't remember what )
the only working solution
has been dcl-sendstring . . .

And now, I was trying to use vla-SendCommand instead of dcl-sendstring,
because I was trying to connect an OpenDCL event (from a ModeLess form)
with a CAD command.
. . .
Thank you

ciao

« Last Edit: February 20, 2021, 07:45:43 AM by domenicomaria »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1189
  • Marco
Re: vla-SendCommand
« Reply #11 on: February 20, 2021, 03:16:51 PM »
this is a "long" string to create at run time.
Code: [Select]
(setvar 'LUPREC 8)
(setq
  bn "\"albero - 03  S\""
  Xs (rtos 1.30333    2)
  Ys (rtos 1.30111    2)
  Zs (rtos 1.00222    2)
  Ra (rtos 45.0       2)
  Xp (rtos 2.12345678 2)
  Yp (rtos 4.12345678 2)
  Zp (rtos 5.12345678 2)
)
(strcat "_-insert " bn "\nX " Xs " Y " Ys " Z " Zs " R " Ra " " Xp "," Yp "," Zp "\n")
=>> "_-insert \"albero - 03  S\"\nX 1.30333 Y 1.30111 Z 1.00222 R 45 2.12345678,4.12345678,5.12345678\n"

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #12 on: February 20, 2021, 11:05:28 PM »
maybe (setvar 'dimzin 0) is the best choice for RTOS . . .

(defun LM:rtos ( real units prec / dimzin result )
    (setq dimzin (getvar 'dimzin))
    (setvar 'dimzin 0)
    (setq result (vl-catch-all-apply 'rtos (list real units prec)))
    (setvar 'dimzin dimzin)
    (if (not (vl-catch-all-error-p result))
        result
    )
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1189
  • Marco
Re: vla-SendCommand
« Reply #13 on: February 21, 2021, 04:03:01 AM »
Yess... I have this:
Code: [Select]
(defun ALE_RtoS_DZ8 (ReaVal / CurDZn OutVal)
  (if (= 8 (setq CurDZn (getvar "DIMZIN"))) (setq CurDZn nil) (setvar "DIMZIN" 8))
  (setq OutVal (rtos ReaVal 2))
  (and CurDZn (setvar "DIMZIN" CurDZn))
  OutVal
)
Edit: LM:rtos: (Lee Mac) do not suppress leading zeros:
Motivation
The result of evaluating the AutoLISP rtos function is dependent upon the current value of the DIMZIN System Variable, in addition to the values of both the LUNITS & LUPREC System Variables. This subtle dependency can lead to inconsistencies arising when programs are used across drafting environments in which these System Variables differ in value… etc.
See: Source at http://www.lee-mac.com/consistentrtos.html

domenicomaria

  • Bull Frog
  • Posts: 235
Re: vla-SendCommand
« Reply #14 on: February 21, 2021, 02:33:33 PM »
yes !