TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: SIDESHOWBOB on June 20, 2012, 09:25:34 AM

Title: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB 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?
Title: Re: visual lisp crash calling (command "draworder")
Post by: BlackBox 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
Title: Re: visual lisp crash calling (command "draworder")
Post by: irneb 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 (http://forums.augi.com/showthread.php?130229-Send-objects-%28wipeouts%29-to-back) (with Lee Mac's help of course!)
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB 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.      )
Title: Re: visual lisp crash calling (command "draworder")
Post by: BlackBox 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 (http://forums.augi.com/showthread.php?130229-Send-objects-%28wipeouts%29-to-back) (with Lee Mac's help of course!)

Pure Awesome (http://www.theswamp.org/index.php?topic=41968.msg470842#msg470842).  :kewl:

Title: Re: visual lisp crash calling (command "draworder")
Post by: Lee Mac on June 20, 2012, 09:54:45 AM
Do these crash for you?

http://lee-mac.com/draworderfunctions.html (http://lee-mac.com/draworderfunctions.html)
Title: Re: visual lisp crash calling (command "draworder")
Post by: BlackBox on June 20, 2012, 10:05:12 AM
Do these crash for you?

http://lee-mac.com/draworderfunctions.html (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!
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB 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?

Title: Re: visual lisp crash calling (command "draworder")
Post by: BlackBox 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]
Title: Re: visual lisp crash calling (command "draworder")
Post by: Lee Mac on June 20, 2012, 04:22:43 PM
Do these crash for you?

http://lee-mac.com/draworderfunctions.html (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 (http://lee-mac.com/terms.html) state that you cannot use them within code that you intend to sell for a profit.

Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on June 21, 2012, 09:05:58 AM
Ok no problems (at least now I know how, I can rewrite).  And thanks again!
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB 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?

Title: Re: visual lisp crash calling (command "draworder")
Post by: Lee Mac 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?
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on June 28, 2012, 10:10:47 AM
error: bad argument type: VLA-OBJECT
Title: Re: visual lisp crash calling (command "draworder")
Post by: Lee Mac 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:
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on June 28, 2012, 10:34:14 AM
No, it just says ; error: bad argument type: VLA-OBJECT

I tried loading your code, and modifying your catch all apply function as follows:
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:CatchApply ( _function _params / result )
  2.     (if (not (vl-catch-all-error-p (setq result (vl-catch-all-apply _function _params))))
  3.         result
  4.         (progn (princ result) (princ))
  5.     )
  6. )

...same result
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on June 28, 2012, 10:37:07 AM
And yes, dict receives a value <VLA-OBJECT IAcadDictionary 0bbc89a4>
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on June 28, 2012, 10:39:25 AM
Test with your routines:

Code - Auto/Visual Lisp: [Select]
  1. #<%catch-all-apply-error%>
  2. ; error: bad argument type: VLA-OBJECT
Title: Re: visual lisp crash calling (command "draworder")
Post by: LE3 on June 28, 2012, 11:09:44 AM
might want to give it a try to this function:  VxSetDrawOrder - from one of the old masters in the lispy world...
here:
http://www.menziengineering.ch/Downloads/Download.htm
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on June 29, 2012, 10:50:37 AM
might want to give it a try to this function:  VxSetDrawOrder - from one of the old masters in the lispy world...
here:
http://www.menziengineering.ch/Downloads/Download.htm

Interesting - the same command fails
Code - Auto/Visual Lisp: [Select]
  1. (vla-AddObject ExtDic "ACAD_SORTENTS" "AcDbSortentsTable")
but with a different error message
Code - Auto/Visual Lisp: [Select]
  1. error: Automation Error. AcRxClassName entry is not in the system registry

Title: Re: visual lisp crash calling (command "draworder")
Post by: irneb on July 02, 2012, 02:28:06 AM
Which version of ACad are you using? Or do you use some clone instead? It sounds as if the ActiveX libraries weren't registered on your system. If ACad see if a repair install solves this.
Title: Re: visual lisp crash calling (command "draworder")
Post by: Jürg Menzi on July 02, 2012, 07:35:34 AM
'VxSetDrawOrder' is tested with all Acad versions 2k5 - 2k12,
and 2k13 also... 8-)

Cheers
Title: Re: visual lisp crash calling (command "draworder")
Post by: SIDESHOWBOB on July 02, 2012, 08:30:07 AM
Must be my version of autocad then.  It's a direct link autodesk sent me after I complained the 2010 download was broken.
Title: Re: visual lisp crash calling (command "draworder")
Post by: owenwengerd on July 02, 2012, 10:28:26 AM
The error means that the clas sname is not registered, which means the .arx module is not loaded. Does the DRAWORDER command work? If so, use it to demand load the module before attempting to use it. If not, check your DEMANDLOAD system variable setting.
Title: Re: visual lisp crash calling (command "draworder")
Post by: Lee Mac on July 02, 2012, 11:57:36 AM
The error means that the clas sname is not registered, which means the .arx module is not loaded. Does the DRAWORDER command work? If so, use it to demand load the module before attempting to use it. If not, check your DEMANDLOAD system variable setting.

1+

Otherwise, call this in your routine:

Code: [Select]
(if (not (member "acdorder.arx" (arx)))
    (arxload "acdorder.arx" nil)
)