Author Topic: AutoCAD command rejected:  (Read 4120 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 723
AutoCAD command rejected:
« on: January 24, 2021, 03:11:31 AM »
I gave a complex lisp routine to a friend of mine.

It uses ACAD2021...

And in a lot of situations,
something that was working perfectly in ACAD2006,
now doesn't work !

The most frequent issue is that
some very simple instructions
don't work !

(vl-cmdf "explode" (car (entsel)))
(vl-cmdf "_.-explode" (car (entsel)))
(vl-cmdf "_.-ucs" "origin" (getpoint))
(command "_.-ucs" "origin" (getpoint))
(command "_.-erase" (ssget)"")

And ACAD says :
AutoCAD command rejected:

It is not possible to put the code here.
It is too much long and complex.

I would like to understand what could be the cause,
also because the same code,
in ACAD 2021, used in another (simpler) context works!


Any suggestion ?

d2010

  • Bull Frog
  • Posts: 323
Re: AutoCAD command rejected:
« Reply #1 on: January 24, 2021, 03:41:26 AM »
Always , I use this routine "dfn_cmd_canceld: for calibrate between commands.
;;Inf:You must be sure the command is not active
;;rem:    Send cancel to current command
;;Out:rr:(nil. eroare a ramas o comanda in executie)
;;rem:       (else.ok, last command active)
Code: [Select]
(defun dfn_cmd_canceld( / $rr cx dx ch) 
  (setq;|a6765|;
ch (quote INT)
cx "CMDACTIVE"
dx (getvar cx)
dx (if (/= (type dx) ch) 0 (boole 1  dx 1))) (progn (while (>  dx 0) (setq;|a6901|;
dx (getvar cx)
dx (boole 1  dx 1)) (setq;|a6947|;
$rr (command "")))) (setq;|a6971|;
$rr (getvar "CMDNAMES")) (terpri)
$rr)
;;Bug: for autocad2007 you use command("");
;;Old: version command("\\");
;;(asserte "A312")
Code: [Select]
(setq winhelp "I insert before the execute explode or __.explode")
(dfn_cmd_canceld)
(vl-cmdf "explode" (car (entsel)))
(dfn_cmd_canceld)
(vl-cmdf "_.-explode" (car (entsel)))
(dfn_cmd_canceld)
(vl-cmdf "_.-ucs" "origin" (getpoint))
(dfn_cmd_canceld)
(command "_.-ucs" "origin" (getpoint))

« Last Edit: January 24, 2021, 04:32:39 AM by d2010 »

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #2 on: January 24, 2021, 04:21:45 AM »
Before to use COMMAND or VL-CMDF
I check the value of "cmdactive"
(getvar "cmdactive")
and it returns 0 (zero)
. . .
This means that the problem is not this.
. . .
if I copy and paste this instruction in the COMMAND LINE
(setq vlc (vl-cmdf "explode" entity-name) )
it works !

But from the LISP routine,
the same code, with the same entity-name,
doesn't work !

WHY ?

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #3 on: January 24, 2021, 04:23:08 AM »
is there a "special" system variable that handles this behaviour ?

d2010

  • Bull Frog
  • Posts: 323
Re: AutoCAD command rejected:
« Reply #4 on: January 24, 2021, 04:29:01 AM »
is there a "special" system variable that handles this behaviour ?
Always you must detect when "(setq vlc (vl-cmdf "explode" entity-name) )" Fail.
(if (= vlc FAILED) (alert "Explode=Fail"))
Other Method You check in BrisCAd with same.dwg, If BrisCAd workfine then
Acad-is-Failed. not your-lisp.
https://youtu.be/WvOXPe_WlJw?list=RDWvOXPe_WlJw
« Last Edit: January 24, 2021, 04:32:54 AM by d2010 »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: AutoCAD command rejected:
« Reply #5 on: January 24, 2021, 05:12:13 AM »
is there a "special" system variable that handles this behaviour ?
For explode:
(if BricsCAD (command "_.EXPLODE" SelSet) (command "_.EXPLODE" SelSet ""))

kpblc

  • Bull Frog
  • Posts: 396
Re: AutoCAD command rejected:
« Reply #6 on: January 25, 2021, 12:01:54 AM »
Perhaps the entity you select couldn't be exploded. Try to explode it manually.
P.S. Divide you code to some simple functions and don't forget about documentation.
P.P.S. I didn't check this code
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _kpblc-explode (ent / err res)
  3.                       ;|
  4. *    Try to explode entity
  5. *    Returns list of entities or nil in error
  6. *    Doesn't check layer status (layer of entity should be thawed and unlocked)
  7. *    Call
  8. (_kpblc-explode (car (entsel)))
  9. (_kpblc-explode (vlax-ename->vla-object (car(entsel))))
  10. |;
  11.   (if (= (type ent) 'ename)
  12.     (setq ent (vlax-ename->vla-object (car (entsel))))
  13.   ) ;_ end of if
  14.   (if (and (= (type ent) 'vla-object) (not (vlax-erased-p ent)))
  15.     (if (vlax-method-applicable-p ent 'explode)
  16.       (if (vl-catch-all-error-p (setq err (vl-catch-all-apply (function (lambda () (vla-explode ent))))))
  17.         (progn (princ (strcat "\nExplode error : " (vl-catch-all-error-message err))))
  18.         (progn (setq res (vlax-safearray->list (vlax-variant-value err))) (vla-erase ent) res
  19. ;; added res to return correct datas
  20. )
  21.       ) ;_ end of if
  22.       (progn (princ "\nCouln'd be exploded") nil)
  23.     ) ;_ end of if
  24.   ) ;_ end of if
  25. ) ;_ end of defun
« Last Edit: January 25, 2021, 04:15:57 AM by kpblc »
Sorry for my English.

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #7 on: January 25, 2021, 12:49:15 AM »
if I use vla-explode
it works . . .

And however, the same code works if I paste it in the command line

And the same thing happens for other commands . . .


and the same code works perfectly in acad2006 !
« Last Edit: January 25, 2021, 12:56:53 AM by domenicomaria »

kpblc

  • Bull Frog
  • Posts: 396
Re: AutoCAD command rejected:
« Reply #8 on: January 25, 2021, 12:57:55 AM »
Actually I prefer do not use command methods.
Sorry for my English.

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #9 on: January 25, 2021, 05:20:51 AM »
(setq origin(getpoint) )
(alert (itoa (getvar "cmdactive" ) ) ) ; [ it returns 0 ! ]
(command "ucs" "origin" origin)

AutoCAD command rejected: "ucs"

why ?

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #10 on: January 25, 2021, 05:57:10 AM »
any suggestion to change ucs origin
via VLA-XXX ?

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #11 on: January 25, 2021, 07:00:37 AM »
(setq *ThisDrawing* (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq *wcs* (vla-get-ActiveUCS *ThisDrawing*))

Automation Error. Null object ID

on the PC of my friend with ACAD2021 !

Why ?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: AutoCAD command rejected:
« Reply #12 on: January 25, 2021, 11:24:02 AM »
(setq *ThisDrawing* (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq *wcs* (vla-get-ActiveUCS *ThisDrawing*))

Automation Error. Null object ID

on the PC of my friend with ACAD2021 !

Why ?
About UCS:
Code: [Select]
Comando: (setq *ThisDrawing* (vla-get-ActiveDocument (vlax-get-acad-object)))
#<VLA-OBJECT IAcadDocument 0000000030d84668>

Comando: (setq *wcs* (vla-get-ActiveUCS *ThisDrawing*))
; errore: Errore di automazione. ID dell'oggetto Null.
Try: create a new UCS >>> WITH NAME then try again (setq *wcs* (vla-get-ActiveUCS *ThisDrawing*))...



kpblc

  • Bull Frog
  • Posts: 396
Re: AutoCAD command rejected:
« Reply #13 on: January 25, 2021, 11:31:13 AM »
(setq origin(getpoint) )
(alert (itoa (getvar "cmdactive" ) ) ) ; [ it returns 0 ! ]
(command "ucs" "origin" origin)

AutoCAD command rejected: "ucs"

why ?
Does _.ucs command have _origin option?
Code: [Select]
Command: _UCS

Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>:
Try this code to change UCS origin:
Code - Auto/Visual Lisp: [Select]
  1. (defun t1 (/ pt sysvar)
  2.   (if (setq pt (getpoint "\nNew origin for current CS : "))
  3.     (progn (setq sysvar (vl-remove nil
  4.                                    (mapcar (function (lambda (x / temp)
  5.                                                        (if (setq temp (getvar (car x)))
  6.                                                          (progn (if (cdr x)
  7.                                                                   (setvar (car x) (cdr x))
  8.                                                                   ) ;_ end of if
  9.                                                                 (cons (car x) temp)
  10.                                                                 ) ;_ end of progn
  11.                                                          ) ;_ end of if
  12.                                                        ) ;_ end of lambda
  13.                                                      ) ;_ end of function
  14.                                            '(("sysmon" . 0) ("cmdecho" . 0) ("menuecho" . 0) ("nomutt" . 1) ("osmode" . 0))
  15.                                            ) ;_ end of mapcar
  16.                                    ) ;_ end of vl-remove
  17.                  ) ;_ end of setq
  18.            (vl-cmdf "_.ucs" pt "")
  19.            (foreach item sysvar (setvar (car item) (cdr item)))
  20.            (princ)
  21.            ) ;_ end of progn
  22.     ) ;_ end of if
  23.   ) ;_ end of defun
Sorry for my English.

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: AutoCAD command rejected:
« Reply #14 on: January 25, 2021, 11:56:44 AM »
Does _.ucs command have _origin option?

Yes.
It has an origin option.
But it is hidden !
Try to enter : UCS  origin . . .