TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: domenicomaria on January 24, 2021, 03:11:31 AM

Title: AutoCAD command rejected:
Post by: domenicomaria 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 ?
Title: Re: AutoCAD command rejected:
Post by: d2010 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))

Title: Re: AutoCAD command rejected:
Post by: domenicomaria 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 ?
Title: Re: AutoCAD command rejected:
Post by: domenicomaria on January 24, 2021, 04:23:08 AM
is there a "special" system variable that handles this behaviour ?
Title: Re: AutoCAD command rejected:
Post by: d2010 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 (https://youtu.be/WvOXPe_WlJw?list=RDWvOXPe_WlJw)
Title: Re: AutoCAD command rejected:
Post by: Marc'Antonio Alessi 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 ""))
Title: Re: AutoCAD command rejected:
Post by: kpblc 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
Title: Re: AutoCAD command rejected:
Post by: domenicomaria 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 !
Title: Re: AutoCAD command rejected:
Post by: kpblc on January 25, 2021, 12:57:55 AM
Actually I prefer do not use command methods.
Title: Re: AutoCAD command rejected:
Post by: domenicomaria 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 ?
Title: Re: AutoCAD command rejected:
Post by: domenicomaria on January 25, 2021, 05:57:10 AM
any suggestion to change ucs origin
via VLA-XXX ?
Title: Re: AutoCAD command rejected:
Post by: domenicomaria 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 ?
Title: Re: AutoCAD command rejected:
Post by: Marc'Antonio Alessi 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*))...


Title: Re: AutoCAD command rejected:
Post by: kpblc 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
Title: Re: AutoCAD command rejected:
Post by: domenicomaria 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 . . .
Title: Re: AutoCAD command rejected:
Post by: domenicomaria on January 25, 2021, 12:13:55 PM
Quote
Try: create a new UCS >>> WITH NAME then try again (setq *wcs* (vla-get-ActiveUCS *ThisDrawing*))...

Grazie Marco.
Title: Re: AutoCAD command rejected:
Post by: Marc'Antonio Alessi on January 25, 2021, 12:48:15 PM
Quote
Try: create a new UCS >>> WITH NAME then try again (setq *wcs* (vla-get-ActiveUCS *ThisDrawing*))...

Grazie Marco.
Prego  :)
Title: Re: AutoCAD command rejected:
Post by: domenicomaria on January 27, 2021, 04:27:10 AM
I understand what the problem is.


I'm trying to create my own MENU, for my commands,
with an OpenDCL palette . . .

So I send to Acad, all the commands, from this menu . . .

But continuosly ACAD says "AutoCAD command rejected: . . ."

The solution is
that I have to set in OpenDCL
the property of the buttons "Event Invoke"
to asynchronicus and
NOT to synchronicus ! ! !

I hope this will help to who will find the same problem !

Thanks to all.

Ciao
Title: Re: AutoCAD command rejected:
Post by: d2010 on January 27, 2021, 06:46:06 AM
Does _.ucs command have _origin option?
Can you test the "Expert"-variabile together ?"
Code: [Select]
(setq vars (list  "CMDECHO")) (mapcar 'setvar vars '(0))
 (command ".expert" (getvar "expert"))  ;; dummy command
 (vl-cmdf "_.pline" "_non" (getpoint)))
Title: Re: AutoCAD command rejected:
Post by: domenicomaria on January 29, 2021, 02:19:22 AM
Quote
Does _.ucs command have _origin option?
Quote
Can you test the "Expert"-variabile together ?"

I took a look to the EXPERT system variable

It can be set to 0 until 5.

But never the UCS command shows the option "origin".

But it exists, works and is HIDDEN.
Title: Re: AutoCAD command rejected:
Post by: Marc'Antonio Alessi on January 29, 2021, 07:41:13 AM
Quote
Does _.ucs command have _origin option?
Quote
Can you test the "Expert"-variabile together ?"

I took a look to the EXPERT system variable

It can be set to 0 until 5.

But never the UCS command shows the option "origin".

But it exists, works and is HIDDEN.
The "origin" request is implied in the prompt itself, probably the option is hidden for a backward compatibility issue…

Code: [Select]
Nome UCS corrente: *GLOBALE*
Specificare origine dell'UCS o [Faccia/con NOme/OGgetto/Precedente/Vista/Globale/X/Y/Z/Asse-z] <Globale>: _origin
Specificare nuovo punto di origine <0,0,0>:

BricsCAD
: UCS
Specify origin of UCS or [Face/NAmed/Entity/Previous/View/X/Y/Z/Z Axis/Move/World] <World>:_origin
Origin point <0,0,0>
Title: Re: AutoCAD command rejected:
Post by: domenicomaria on January 29, 2021, 08:36:51 AM
Quote
The "origin" request is implied in the prompt itself,
probably the option is hidden for a backward compatibility issue…

yes
it is so