• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

error in using command instruction

  • Thread starter Thread starter tizianost
  • Start date Start date

tizianost

Guest
hi to everyone, I've been writing my first lisp program for a few days to automate monotonous procedures. I think it is useless to say that I came across many difficulties but with so much patience I managed to overcome them... except two:

1) the first problem concerns the use of "command" instruction as if I try to run some non-internal autocad commands (such as those of the express menu) I get an error message as the command does not exist. for precision the expression used by me in the lisp is as follows:

(command "txtexp" (ssname (ssadd ent) 0)


I immediately say nothing changes if I add "_" to the command ("_txtexp")

2)The second problem arises when I try to explode with

(command "_explode" (ssname (ssadd ent) 0)

the following entity

((-1). <nome 7e30f788="" entità:="">) (0 . "hatch") (330 . <nome 7ebfcc10="" entità:="">(a) (a) (a) (b) (b) (b)) (b) (b)) (b) (b) (b) (b) (b)) (b) (b) (b)) (b) (b) (b) (b)) (b) (b)) (b) (b) (b) (b)) (b) (b)) (b) (d))) (d) (d))) (d) (d) (d)) (d) (d) (d))))) (d) (d) (d))) (d) (d) (d) (d)))) (d) (d) (d) (d))) (d) (d) (d) (d)) (d) (d)) (d) (d) (d) (d) (d))))))))) (d) (d) (d) (d) (d) (d) (d) (d) (d) (d))) (d) (d) (d) (


I always get:

_explode
select object:
the object is not in the current space.
search without result.
select object:
"exploded hatch"
1831 _explode
*no valid selection*
requires a point or last/every/group
; error: function canceled

Thank you in advance
Hi.
Titian</nome></nome>
 
I press that of lisp are not an expert but try to see if defining prioma a variable

(setq selection (ssname (ssadd ent) 0)

(command "_explode" selection)
 
Thank you for the answer. the result does not change. I begin to believe that the error is due to some error in the dwg file (created in 1997 and via updated) although the verification function does not detect errors.

Hi.
Titian
 
The error is up when you defined the entity.
You probably used:
(setq ent (entget (entsel)))
instead of
(setq en1 (car (entsel)))
to obtain only the name of the entity en1, to be inserted in your code:
(command "_explode" (ssname (ssadd en1) 0)

but enough
(command "_explode" en1)
 
Thanks for the answer.
I did not use the function that (setq ent (entget (car (entsel)))) as the selection is extended to all drawing
I carry an extract of the code to clarify the situation

(percentage)
(setq explosion 1)
(while (/= exploded 0)
(sevenq exploded)
(setq group (ssget "x")); select all elements of the design
(setq nent (1- (sslength group)));
(setq i 1); prevents endless cycles
(alert "cycle while")
(while (and (> nent -1) (< i 100000) ; cycle for all elements
(setq ent) ; extracts the name of the element
(seq element (entget ent) ; extracts the element "ent" from the database
(setq tipoent (cdr (assoc 0 element)))
(cond; management type entity
(= typeent "hatch")
(if (/= (cdr (assoc 2 element)) "solid")
(progn)
(setq explosion 1)
;(setq selez (sname (ssadd ent) 0)))
(command "_explode" ent)
(print "exploded hatch")
) ;
) ;
)
(or (= tipoent "acad_table")
(=typeent "dimension")
(= typeent "insert")
(= typeent "mline")
) ; scale to explode without problems

(if (and (/= (strcase (cdr) (assoc 2 element)))
(/= (strcase (cdr) (assoc 2 element)))) "proto")
(/= (substrcase (cdr) (assoc 2 element)) 1 3 )"ac_")
(/= (substrcase (cdr) (assoc 2 element)) 1 4 )"acq_")
;(/= (cdr) (assoc 0 element)) (insert))
)
(progn)
(setq selez (sname (ssadd ent) 0)
(command "_explode" selez)
(setq explosion 1)
(print "exploded table-size insert mline")
) ;
) ;
)
(or (= tipoent "image")
(= typeent "point")
(=typeent "ray")
"Region"
(xline)
(= typeent "wipeout")
(= typeent "viewport")
) ; entities to be ignored
(print tipoent)
)

(or (=typeent "text")
(=typeent "mtext")
) ;
; not txtexp
(command "txtexp" (ssname (ssadd ent) 0)))
(setq explosion 1)
(print "exploded text mtext")
)

) ;
(setq nent (1- nent) ; decreases the elements
(seq i (1+ i)); increase the number of cycles made

(print nent)
) ; end of while
) ; end of while
) ;



the thing that leaves me puzzled is that in general the application works... only in particular cases it freezes.

Thank you.
Hi.
Titian
 
I think the incriminated line is this:
(setq ent) ; extracts the name of the element
in fact to explode you have to pass the name of the entity-istanza (that assoc a -1), which is extracted simply with: (setq en1 (car (entsel))), and not the name of the object (that assoc to code 0), which is extracted, e.g., with: (setq en (cdr (assoc 0 (entget en1))).

with regard to the first question, the txtexp command, being a command not internal but built by the user, must be introduced in the original form, i.e.
(command (c:txtexp)); also cannot have arguments.
so it works, although in the end it gives me a mistake, that I will try to find out.

Meanwhile, if you want to study, read this part of the autolisp help.
if an autolisp function is defined with a name of the form c:xxx, it can be issued at the autocad command prompt in the same manner as a built-in autocad command. this is true regardless of whether you define and load the function in vlisp or at the autocad command prompt. you can use this feature to add new commands to autocad or to redefine existing commands.

to use functions as autocad commands, be sure they adhere to the following rules:

the function name must use the form c:xxx (upper- or lowercase characters). the c: portion of the name must always be present; the xxx portion is a command name of your choice. c:xxx functions can be used to override built-in autocad commands. (see redefining autocad commands.)
the function must be defined with no arguments. however, local variables are permitted and it is a good programming practice to use them.
a function defined in this manner can be issued transparently from within any prompt of any built-in autocad command, provided the function issued transparently does not call the command function. (this is the autolisp function you use to issue autocad commands; see the entry on command in the autolisp reference.) when issuing a c:xxx defined command transparently, you must precede the xxx portion with a single quotation mark (').
 
a parentage is missing: (setq elemento (entget ent))As for txtexp is right joseph, you cannot pass arguments as it is an external lisp that once launched requires the selection of texts, that is what happens by launching txtexp on its behalf.

I want Select the texts to explode you can insert (c:txtexp) even without command, in this way throw the lisp, if already loaded, from within your lisp.


If you want to complete everything automatically you can do this:

- make a copy of txtexp.lsp and rename in txtexp1.lsp

- the renamed lisp makes these changes:;ss (ssget fltr)ss(sget "_x"((0. "mtext, text")- eliminates from your lisp the code part inherent in text and mtext, which among other things has an excess bracket (command "txtexp" (ssname (ssadd ent) 0)))- insert (c:txtexp1) between the last two fine_while, i.e. the last line of code


Now it should work, even if you don't return the prompt with reporting the "modification of texts".



notes:

- txtexp1.lsp must already be loaded at the launch of your lisp, otherwise enter at the beginning (load "d:\\\\\\\\txtexp1"), clearly with the right path.

- your lisp is loaded as the parentheses in defect compensate for the excess, although I can't understand how it can work and block "only in particular cases".
 
I thank you for the answers and apologize for my "absence" but putroppo only now I had time to read the mails... this evening I decide to set up the application following your advice.
Thank you.
Hi.
Titian
 
It's nice to see that there are still users interested in autolisp and vlisp programming.
You guys!
remember that where does not come well autolisp you can beg with vlisp...
a greeting to the whole community.

(vl-load-com)(vl-cmdf "_quit")
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top