Author Topic: visual lisp crash calling (command "draworder")  (Read 8947 times)

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Guest
visual lisp crash calling (command "draworder")
« on: June 20, 2012, 09:25:34 AM »
As stated in the title, autocad completely locks up (and I have to kill it) after calling
Code - Auto/Visual Lisp: [Select]
  1. (command "draworder" selectionset "" "b")

from my lisp.

(As an aside, I hope this is the right command to put the ith selection set to the back - but can't find documentation on how to call this anywhere - any pointers appreciated!)

Mainly though has anyone experienced a crash here, what might I be doing wrong?  Does calling entmod invalidate selection sets?

BlackBox

  • King Gator
  • Posts: 3770
Re: visual lisp crash calling (command "draworder")
« Reply #1 on: June 20, 2012, 09:32:06 AM »
** Post Corrected **

Draworder is a LISP Command (as in Defun c:* ...), and _not_ a .NET CommandMethod Method (I believe this terminology applies to ObjectARX defined commands as well, not sure?).

More accurately, c:DRAWORDER the DRAWORDER Command is supplied a selection set, and an option (i.e., back, front, etc.) by a LISP sub-function named AI_DRAWORDER which acts upon the currently selected items within your drawing (implied selection)... Or prompts the user to create a selection set.

Instead, consider:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Back ()
  2.   (if (sssetfirst nil (ssget))
  3.     (ai_draworder "_b"))
  4.   (princ))
  5.  

** Note - As AI_DRAWORDER calls the DRAWORDER Command, it cannot be incorporated into any ObjectDBX functionality.

HTH
« Last Edit: June 20, 2012, 12:54:22 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: visual lisp crash calling (command "draworder")
« Reply #2 on: June 20, 2012, 09:47:43 AM »
Otherwise, try using the ActiveX methods to modify object order. For an example see the code I used in post #4 here (with Lee Mac's help of course!)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #3 on: June 20, 2012, 09:49:03 AM »
Tried the code you provided; it crashes in just the same way.

Interestingly it doesn't crash when called manually from the lisp console, only within the script.

What is ObjectDBX functionality, am I unwittingly trying to use it if I'm writing lisp?
Code - Auto/Visual Lisp: [Select]
  1.      (setq i 0)
  2.      (while (< i numsteps)
  3.        (progn
  4.                (princ (sslength (nth i selectionsets)))
  5.                (princ "\n")
  6.                (princ (nth i selectionsets))
  7.                (princ "\n")
  8.                (if (sssetfirst nil (nth i selectionsets)) (ai_draworder "_b"))
  9.                (setq i (+ i 1))
  10.        )
  11.      )

BlackBox

  • King Gator
  • Posts: 3770
Re: visual lisp crash calling (command "draworder")
« Reply #4 on: June 20, 2012, 09:54:27 AM »
Otherwise, try using the ActiveX methods to modify object order. For an example see the code I used in post #4 here (with Lee Mac's help of course!)

Pure Awesome.  :kewl:

"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: visual lisp crash calling (command "draworder")
« Reply #5 on: June 20, 2012, 09:54:45 AM »

BlackBox

  • King Gator
  • Posts: 3770
Re: visual lisp crash calling (command "draworder")
« Reply #6 on: June 20, 2012, 10:05:12 AM »
Do these crash for you?

http://lee-mac.com/draworderfunctions.html

Firstly - Most excellent, Lee... I had not come across the MoveTo* Methods before.

That said, while the code does not bomb, I am having trouble with selecting entities through an active PViewport, due to (cons 410 (getvar 'ctab)). I can obviously correct this, but just thought I'd share in the event you wanted to update source code on your website.

Again, many thanks - Cheers!
"How we think determines what we do, and what we do determines what we get."

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #7 on: June 20, 2012, 10:18:33 AM »
Lee, those work, thank you!  Am I allowed to use them in commercial code?

On a related note I am finding that (regen) crashes autocad too, not the first time it is called within the script but the second.  Is there a way around this?


BlackBox

  • King Gator
  • Posts: 3770
Re: visual lisp crash calling (command "draworder")
« Reply #8 on: June 20, 2012, 10:37:31 AM »
[OffTopic]

Lee -

No obligation of course, but if I may, for your consideration:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;;;--------------------------------------------------------------------;
  3. (defun c:TOP ( / ss)
  4.   (if (setq ss (ssget)) (LM:MoveToTop (LM:acDoc) ss)) (princ))
  5. ;;;--------------------------------------------------------------------;
  6. (defun c:BOTTOM ( / ss)
  7.   (if (setq ss (ssget)) (LM:MoveToBottom (LM:acDoc) ss)) (princ))
  8. ;;;--------------------------------------------------------------------;
  9. (defun LM:acDoc ()
  10.   (cond (acDoc)
  11.  

... As precluding entities on locked layers is not necessary, given that AI_DRAWORDER works with locked layers as well. This also allows for selection through an active PViewport.

** Edit - Forgot to express my dissapointment with LISP; not being able to add vla-Start/End*UndoMark is frustrating.

** Note - Attribution of LM:acDoc is for pseudo purposes, and shall be used at LM's discretion only.

[/OffTopic]
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: visual lisp crash calling (command "draworder")
« Reply #9 on: June 20, 2012, 04:22:43 PM »
Do these crash for you?

http://lee-mac.com/draworderfunctions.html

Firstly - Most excellent, Lee... I had not come across the MoveTo* Methods before.

That said, while the code does not bomb, I am having trouble with selecting entities through an active PViewport, due to (cons 410 (getvar 'ctab)). I can obviously correct this, but just thought I'd share in the event you wanted to update source code on your website.

[OffTopic]

Lee -

No obligation of course, but if I may, for your consideration:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;;;--------------------------------------------------------------------;
  3. (defun c:TOP ( / ss)
  4.   (if (setq ss (ssget)) (LM:MoveToTop (LM:acDoc) ss)) (princ))
  5. ;;;--------------------------------------------------------------------;
  6. (defun c:BOTTOM ( / ss)
  7.   (if (setq ss (ssget)) (LM:MoveToBottom (LM:acDoc) ss)) (princ))
  8. ;;;--------------------------------------------------------------------;
  9. (defun LM:acDoc ()
  10.   (cond (acDoc)
  11.  

... As precluding entities on locked layers is not necessary, given that AI_DRAWORDER works with locked layers as well. This also allows for selection through an active PViewport.

** Edit - Forgot to express my dissapointment with LISP; not being able to add vla-Start/End*UndoMark is frustrating.

** Note - Attribution of LM:acDoc is for pseudo purposes, and shall be used at LM's discretion only.

[/OffTopic]

Thank you Renderman for your appreciation and suggestions! The functions on that page are relatively old now (they still use my old code formatting style), so I shall look to update them over the coming days when I get some time; I shall definitely keep your suggestions in mind when doing so.  :-)

Lee, those work, thank you!  Am I allowed to use them in commercial code?

You may use them in code used within your own organisation, but my terms state that you cannot use them within code that you intend to sell for a profit.


SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #10 on: June 21, 2012, 09:05:58 AM »
Ok no problems (at least now I know how, I can rewrite).  And thanks again!

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #11 on: June 28, 2012, 09:50:05 AM »
Lee, the command

(vla-AddObject dict "ACAD_SORTENTS" "AcDbSortentsTable")

fails for me in Autocad 2010.  I think this affects your sortents routines too - they seem to handle it by failing silently.  Is there a way to change drawing order pre 2010?


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: visual lisp crash calling (command "draworder")
« Reply #12 on: June 28, 2012, 09:58:30 AM »
Lee, the command

(vla-AddObject dict "ACAD_SORTENTS" "AcDbSortentsTable")

fails for me in Autocad 2010.  I think this affects your sortents routines too - they seem to handle it by failing silently.

Upon changing my 'LM:CatchApply' function to print the resultant error message should an exception occur, I do not receive any error when testing in AutoCAD 2010 and the draw order operation is successful.

What error message do you receive when the AddObject method fails?

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #13 on: June 28, 2012, 10:10:47 AM »
error: bad argument type: VLA-OBJECT

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: visual lisp crash calling (command "draworder")
« Reply #14 on: June 28, 2012, 10:30:27 AM »
error: bad argument type: VLA-OBJECT

I'm assuming you mean:

Code: [Select]
error: bad argument type: VLA-OBJECT nil
Since errors of this nature usually include the value supplied to the function in place of the required argument.

Is the variable 'dict' defined in your rewrite of my code?  :roll: