Jump to content

Why should I "select object"?


saim

Recommended Posts

 

 

I'm trying to automate this block exchanging. I put on some global variables the name of the blocks to go, ane the name of the blocks to be putted on their place. Then I select an area and everyone inside that area gets swapped.

 


I got there, the code is a lot amateurish, ir does'n check for errors... but the job gets done.

But for every block to be exchanged, the "select object" request prompts up. Just pressing enter makes the code run smooth... but I don't want it prompted

 

 

 

I have simplified the code to a point that there should be easy to find the problem.

In one line, I get the first element of a selection set. I store it in a global variable, for now.

Then, I try to just show the name of that element.

I'm getting the "select objects" instruction prompted at me. Why? How to avoid it?

Code:

(setq eraseit (ssname (ssget) 0))

ok, this is supposed to ask me for a selection set, the problem comes later

(defun c:tst()
    (trocaumbloco eraseit)
)

this is just a line designed to call the actual code. I could have writting it directly at the command bar.

(defun trocaumbloco (blkout)
    (print blkout) 
)

simple enought, right?  Why does it ask me again to "select objects"?

Edited by saim
Link to comment
Share on other sites

The code you have posted would not (and does not) exhibit the behaviour you have described - the prompt must originate from another part of the code, or as a result of how your code is being evaluated.

Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

Indeed.

I created another file, from scratch, and it really didn't happen again. Must have been some global variables I have left defined from tests... maybe the whole problem will get solved, now that I have cleared it.

I'll test and if the problem remains, I'll try to translate the code and edit this message, posting it.

 

Edit:

Well, I tried to translate and made it worse... there is a syntax error I can't pinpoint right now (probably a variable name or comment syntax). I'll post both codes, the first one, in portuguese is the original, the one in english is more heavilly commented, but has this syntax problem.

 

Original - portuguese

 

(setq nomeentra "Csn1550p") 'default de entrar
(setq nomesai "CS") 'defaul de sair
(defun c:trocablocos( / totblks cont obid tipoob nomebloco )
    (setq totblks (ssget))
    (setq cont 0)
    (repeat (sslength totblks)
        (setq obid (ssname totblks cont)) ; pega a id de cada objeto
        (setq tipoob (definetipo obid))
        (if (= tipoob "INSERT")
            (progn
                (setq nomebloco (definenomeblk obid))
                (if (= nomebloco nomesai)
                    (trocaumbloco nomeentra obid)
                )
            )
        )
        (setq cont (+ 1 cont))
    )
    (princ)
)
(defun trocaumbloco (blkin blkout / ptin rot)
    'blkin é uma variável string
    'blkout é um objeto (entsel)
    (setq ptin (cdr (ASSOC 10 (ENTGET blkout)))) 'pega o ponto de inserção
    (setq rot (cdr (ASSOC 50 (ENTGET blkout)))) 'pega a rotação
    (setq rot (/ rot(/ 3.14159 180))) 'transforma a rotação em graus
    (command "_.-insert" blkin ptin "1" "1" rot)
    (command "erase" blkout "")
)
(defun definetipo(ob / tipoob); retorna o tipo de objeto dado como entrada
    (setq tipoob (CDR(ASSOC 0 (entget ob)))); grava o tipo de objeto, que está referenciado no título 0
    '(print tipoob)
    tipoob
)
(defun definenomeblk(ob / nomeblk); retorna o nome do bloco, cujo objeto foi dado como entrada
    (setq nomeblk (CDR(ASSOC 2 (entget ob)))); grava o tipo de objeto, que está referenciado no título 0
    '(print nomeblk)
    nomeblk
)
(defun c:trocanomes()
    (setq nomeentra
        (cond
            ((getstring (strcat "Nome do bloco que entra <" nomeentra">")))
            (nomeentra)
        )
    )
    (setq nomesai
        (cond
            ((getstring (strcat "Nome do bloco que sai <" nomesai">")))
            (nomesai)
        )
    )
)
(defun c:akuma()
    (alert "Para trocar os blocos: trocablocos\n\nPara mudar quais blocos serão trocados: trocanomes\n\nPara mostrar essa mensagem: akuma")
)
akuma

Translated - with syntax problem

 

(setq nameenter "Csn1550p") 'default name of block to enter
(setq nameleave "CS") 'defaul name of block to leave
(defun c:tradeblocks( / totblks cont obid obkind blkname )
    (setq totblks (ssget)) 'asks user for a selection set
    (setq cont 0) 'starts a counter
    (repeat (sslength totblks)
        (setq obid (ssname totblks cont)) ; gets the id of each object on selection set
        (setq obkind (definekind obid))
        (if (= obkind "INSERT")
            (progn
                (setq blkname (getsblkname obid)) 'gets the name of the current block
                (if (= blkname nameleave)
                    (tradeoneblock nameenter obid) 'creates a new block in place of the old one and deletes the old
                )
            )
        )
        (setq cont (+ 1 cont)) ;rolls the counter
    )
    (princ)
)
(defun tradeoneblock (blkin blkout / ptin rot)
    'blkin is a string variable
    'blkout an object - element of selection set
    (setq ptin (cdr (ASSOC 10 (ENTGET blkout)))) 'gets insertion ponint
    (setq rot (cdr (ASSOC 50 (ENTGET blkout)))) 'gets rotation
    (setq rot (/ rot(/ 3.14159 180))) 'transforms rotation to degrees
    (command "_.-insert" blkin ptin "1" "1" rot)
    (command "erase" blkout "")
)
(defun definekind(ob / obkind); returns the kind of object inputted
    (setq obkind (CDR(ASSOC 0 (entget ob)))); gets the kind of object, referenced under the title 0
    '(print obkind)
    obkind
)
(defun getsblkname(ob / nomeblk); returns the iputted block name
    (setq nomeblk (CDR(ASSOC 2 (entget ob)))); gets the object kind, referenced under the title 2
    '(print nomeblk)
    nomeblk
)
(defun c:changenames()
    (setq nameenter
        (cond
            ((getstring (strcat "Name of the block that enters <" nameenter">")))
            (nameenter)
        )
    )
    (setq nameleave
        (cond
            ((getstring (strcat "Name of the block that leaves <" nameleave">")))
            (nameleave)
        )
    )
)
(defun c:instructions()
    (alert "Para trocar os blocos: tradeblocks\n\nPara mudar quais blocos serão trocados: changenames\n\nPara mostrar essa mensagem: instructions")
)
instructions
Edited by saim
Link to comment
Share on other sites

If the code actually works, then you should change the CMDECHO variable before the (command ...) calls:

(setvar 'cmdecho 0)
(command ...)
(command ...)
; etc.
(setvar 'cmdecho 1)

 

Link to comment
Share on other sites

That didn't harm, but still didn't solve the problem.

I searched what is "cmdecho". The help file says:

"Controls whether prompts and input are echoed during the AutoLISP command function."

I still don't know what that means. What is "echoed"?

 

I got the impression that the "select objects" was being prompted because of the command lines and "echoing" meant "asking user for an input".

If those were both true, your idea should solve the problem, but it seems that at least onde of those impressions is wrong.

Link to comment
Share on other sites

Testing the code in BricsCAD there is an issue with the comments. Some start with ' (single quote). This should be ; (semicolon). After changing this the code works OK.

 

If you use command calls in Lisp code the prompts of those commands need not be presented to the user as your code handles all input. Switching the CMDECHO to zero will hide those prompts.

  • Like 1
Link to comment
Share on other sites

Thanks, it really worked!
I never understood why there are 2 kinds of commands entry, but from now on, I'll use the right one (";").

I'd never thin of removing the comments or changing the initial character. Doing that solved the problem - and many problems that might happen in the future!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...