Author Topic: visual lisp crash calling (command "draworder")  (Read 8939 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: 12913
  • 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: 12913
  • 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: 12913
  • 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: 12913
  • 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:

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #15 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

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #16 on: June 28, 2012, 10:37:07 AM »
And yes, dict receives a value <VLA-OBJECT IAcadDictionary 0bbc89a4>

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #17 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

LE3

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #18 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

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #19 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


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: visual lisp crash calling (command "draworder")
« Reply #20 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.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: visual lisp crash calling (command "draworder")
« Reply #21 on: July 02, 2012, 07:35:34 AM »
'VxSetDrawOrder' is tested with all Acad versions 2k5 - 2k12,
and 2k13 also... 8-)

Cheers
« Last Edit: July 02, 2012, 08:06:06 AM by Jürg Menzi »
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

SIDESHOWBOB

  • Guest
Re: visual lisp crash calling (command "draworder")
« Reply #22 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.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: visual lisp crash calling (command "draworder")
« Reply #23 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.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: visual lisp crash calling (command "draworder")
« Reply #24 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)
)