Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
safcadd08
Posts: 49
Registered: ‎10-06-2008
Message 1 of 9 (131 Views)

Error Chech

131 Views, 8 Replies
06-12-2012 10:21 PM

Helllo,

If Ii have a few block on the scree, and I would like to pick them, but I'm running a block counter at the sametime. How would I go about making sure the block gets picked and the counter does not advance?

 

Thanks,

Steve

Distinguished Mentor
Moshe-A
Posts: 738
Registered: ‎09-14-2003
Message 2 of 9 (129 Views)

Re: Error Chech

06-12-2012 10:50 PM in reply to: safcadd08

Steve,

 

how can you pick objects (your blocks)  while 'counter' is running?

 

what's this 'counter' is?  an AutoLISP command?

 

what is your goal?

 

Moshe

 

 

Active Contributor
safcadd08
Posts: 49
Registered: ‎10-06-2008
Message 3 of 9 (126 Views)

Re: Error Chech

06-12-2012 11:16 PM in reply to: Moshe-A
Hello, If I pick, the counter will advance even if I miss the block...Is their a better way to do this? Thanks for the reply. Steve
*Expert Elite*
Kent1Cooper
Posts: 5,264
Registered: ‎09-13-2004
Message 4 of 9 (106 Views)

Re: Error Chech

06-13-2012 05:47 AM in reply to: safcadd08

safcadd08 wrote:
....If I pick, the counter will advance even if I miss the block...Is their a better way to do this? ....

Try something that will ask again if you miss, such as this, using a combination of selection-method codes that Lee Mac called to my attention [one part of which is not documented in the AutoLISP Reference].  It makes (ssget) work like individual-object selection, similar to (entsel) but with the possibility of filtering:

 

(while

  (not

    (setq blk (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))))

    (prompt "\nNothing selected, or not a Block -- try again:"))

  )

)

 

And once that has been satisfied, then advance the counter.  You can get more sophisticated with the use of the ERRNO System Variable, so that you can end it with Enter or space [with the above, those will also result in its asking you to try again, and only Escape will end it].  Seeing the routine that includes the counter would make it easier to know whether that's needed, and to suggest how to integrate something like this into it.

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,264
Registered: ‎09-13-2004
Message 5 of 9 (102 Views)

Re: Error Chech

06-13-2012 06:31 AM in reply to: Kent1Cooper

Kent1Cooper wrote:
.... 

(while

  (not

    (setq blk (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))))

    (prompt "\nNothing selected, or not a Block -- try again:"))

  )

)

....


Sorry [too late to Edit my previous message] -- that should be:
 

(while
  (not (setq blk (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))))
  (prompt "\nNothing selected, or not a Block -- try again:")
)
 

You can also get more sophisticated in other ways, such as eliminating Xrefs, or Blocks on locked Layers, or not add to the count Blocks that were already selected, as well as the usual error handling, etc.

Kent Cooper
Active Contributor
safcadd08
Posts: 49
Registered: ‎10-06-2008
Message 6 of 9 (90 Views)

Re: Error Chech

06-13-2012 08:54 AM in reply to: Kent1Cooper
Hello Kent and All, Here is the code I want to erro check: ================================================== (command "_erase" "c" "26.97,27.39" "17,26.34" "") ;Erace line of text (command "-insert" "of21" "26.23,26.82" "" "" "") ;Insert a new line of text (command "-insert" "00" "29.06,26.81" "" "" "") ;Inserts first number in counter (setq c1 0) ;Sets counter to zero (repeat 21 (setq c1 (+ c1 1)) ;Add 1 to counter ; ;=================This section of code by Tharwat================= (if (and (setq ss (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))) (> (sslength ss) 0) ) (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i)))) (setq sn1 sn) (if (< (length s) 21) (setq s (cons (cdr (assoc 2 (entget sn))) s)) ) (entdel sn) ) ) ;==================================================== (setq s1 (car s)) ;Converts a list to string by Kent Cooper ; ====================This code inserts first block ================================= (if (= c1 1) (progn (command "-insert" s1 "92.68,15.79" "" "" "") (command "_erase" "c" "29.68,27.55" "28.39,27.20" "") (command "-insert" "01" "29.06,26.81" "" "" "") ) ) ;====================================================== If the selection misses for block s1, : How would I check for that? Thanks, Steve
*Expert Elite*
Kent1Cooper
Posts: 5,264
Registered: ‎09-13-2004
Message 7 of 9 (88 Views)

Re: Error Chech

06-13-2012 09:12 AM in reply to: safcadd08

safcadd08 wrote:
Hello, If I pick, the counter will advance even if I miss the block...Is their a better way to do this? Thanks for the reply. Steve

Before looking at your latest, since I came up with the attached, here it is.  But it occurs to me to wonder [maybe this will be apparent in your latest post that I haven't looked into yet]:  do you want to pick them one at a time so that it matters if you miss, or would you also like to be able to select them by window/crossing/wp/cp/fence methods?  In some ways the latter would be easier, but the attached assumes the former because of your wording above.

Kent Cooper
Active Contributor
safcadd08
Posts: 49
Registered: ‎10-06-2008
Message 8 of 9 (87 Views)

Re: Error Chech

06-13-2012 09:15 AM in reply to: Kent1Cooper
Hello, The selection is one at a time, so each block pick will need to be checked. Thanks, Steve
*Expert Elite*
Kent1Cooper
Posts: 5,264
Registered: ‎09-13-2004
Message 9 of 9 (86 Views)

Re: Error Chech

06-13-2012 09:47 AM in reply to: safcadd08

safcadd08 wrote:
....

(if (and (setq ss (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))) (> (sslength ss) 0) )

  (repeat (setq i (sslength ss))....

;Converts a list to string by Kent Cooper ;

....

 

If the selection misses for block s1, : How would I check for that? Thanks, Steve


Hard to say as it appears here, but I pasted it into Notepad and sorted it some, and I don't understand a few things.

 

It seems to be missing a right parenthesis somewhere, but I'm not positive.

 

There are a few mystery characters as it comes up in Notepad, so I wonder whether I'm missing something.

 

The sn1 variable doesn't appear to be used for anything, and I'm not sure about the need for the c1 variable.

 

The reference to me doesn't seem to be about anything that's going on in the code.

 

This part:

  (if (and (setq ss (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))) (> (sslength ss) 0))
    (repeat (setq i (sslength ss))

doesn't make much sense to me.  The :smileyfrustrated: is for single-object selection, so (sslength ss) should always be 1, so there doesn't seem to be much point in the (repeat) function and the i counter variable.

 

As to your question at the end, I don't see how the selection set can miss for block s1, since it looks like s1 is the first block name in a list, and nothing's going into that list unless it is found in the (ssget) function.  Do you mean if nothing is found at the point of (ssget) selection, well before the s1 variable is set?  If that's the case, you could put a prompt as an 'else' argument to complement the (repeat) function that is the 'then' argument to the (if) function, something like this:
 

  (if (and (setq ss (ssget "_+.:smileyfrustrated::E" '((0 . "INSERT")))) (> (sslength ss) 0))
    (repeat (setq i (sslength ss))

      .....

    ); end repeat

    (prompt "\nNo Block selected."); else

  ); end if

Kent Cooper

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community