Error if selection set is out of view - 0xC0000005 (Access Violation)

Error if selection set is out of view - 0xC0000005 (Access Violation)

Anonymous
Not applicable
1,783 Views
6 Replies
Message 1 of 7

Error if selection set is out of view - 0xC0000005 (Access Violation)

Anonymous
Not applicable

Hello all,

I am working on a lisp to create "wire jumps" on selected polylines, where at every intersection it breaks the vertical line to prevent an overlap. I have it working, for the most part. I'm on AutoCAD 2019.

 

If my selection set (all selected polylines) is completely in view within model space and the code is run: no errors, all is great in the world.

 

If my selection set is partially out of view (zoomed in, part of a polyline with an intersect or a turning vertex not displayed in view), an error will occur. If I step through the code in VLISP this error comes up:
; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on exception

 

I just can't figure it out. It's strange that it only occurs while part of the selection is out of view. I could write in a viewport change at each run but that is rather inefficient.
Any help or direction would be appreciated-

 

 

 

 

;==================================================================================================================================================
;make wire jumps for crossing lines
(defun c:WJ-[wirejump] ( / *error* errmsg _ActiveDoc _StartUndo _EndUndo doc ss gap x _pts a plst ent nobj pint rlst mp1 mp2)
(vl-load-com)
(setq doc  (vla-get-ActiveDocument (vlax-get-acad-object)))
;error & undo handler
(defun *error* ( errmsg )
  (_EndUndo (_ActiveDoc))
  (if (not (wcmatch (strcase errmsg t) "*break,*cancel*,*exit*"))
  (princ (strcat "\n** Error: " errmsg " **")))
  (princ))
  (defun _ActiveDoc nil
      (eval (list 'defun '_ActiveDoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
      (_ActiveDoc))
  (defun _StartUndo ( doc ) (_EndUndo doc)
      (vla-StartUndoMark doc))
  (defun _EndUndo ( doc )
      (if (= 8 (logand 8 (getvar 'UNDOCTL)))
        (vla-EndUndoMark doc)))
(_StartUndo (_ActiveDoc))
;variables
(setq gap 0.5)
(setq
    oldecho (getvar "CMDECHO")
    oldblip (getvar "BLIPMODE")
    oldosm (getvar "OSMODE"))
(setvar "CMDECHO" 0)
(setvar "BLIPMODE" 0)
(setvar "OSMODE" 0)
;jump, jump, jump, jump
(defun _pts (e / pint)
  (setq pint (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget e))))
  (mapcar '(lambda (a plst) (list a plst)) pint (cdr pint)))
(cond	((and (setq ss (ssget ":L" '((0 . "lwpolyline")))) ;ss = selection set
	      ;(setq ss (nentsel pss)) ;this didn't work for 0xC0000005 error
            (> (sslength ss) 1))
       (repeat (setq nobj (sslength ss)) ;nobj = number of objects in selection
               (setq ent (ssname ss (setq nobj (1- nobj)))) ;ent = individual entity name
               (setq rlst (cons (_pts ent) rlst))) ;rlst = growing list of points
       (setq rlst (apply 'append rlst))
       (while	(setq a (car rlst)) ;returns the first element of list
              (setq rlst (cdr rlst)) ;returns list containing all but the first element of the specified list
              (foreach x rlst
                (if (setq pint (inters (car a) (cadr a) (car x) (cadr x))) ;pint = point of intersect
                    (setq plst (cons pint plst))))) ;plst = full list of intersects
       (foreach pint plst
           (if (and (setq mp1 (ssget "c" (list (car pint) ( - (cadr pint) gap)) (list (car pint) ( - (cadr pint) gap)) (list (cons 0 "lwpolyline"))))
                    (setq mp2 (ssget "c" (list (car pint) ( + (cadr pint) gap)) (list (car pint) ( + (cadr pint) gap)) (list (cons 0 "lwpolyline")))))
            (command "_.break" ; we are failing here ; error: Exception occurred: 0xC0000005 (Access Violation); warning: unwind skipped on exception
               (mapcar '+ (list (car pint) ( - (cadr pint) gap) (caddr pint)) '(0 0))
               (mapcar '+ (list (car pint) ( + (cadr pint) gap) (caddr pint)) '(0 0)))
           ))))
;end it
(setvar "CMDECHO" oldecho)
(setvar "BLIPMODE" oldblip)
(setvar "OSMODE" oldosm)
(_EndUndo (_ActiveDoc))
(princ "\n-jumps made-")(princ))
;==================================================================================================================================================

 

 

 

 

0 Likes
Accepted solutions (1)
1,784 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor
(setq ss (nentsel pss)) ;this didn't work for 0xC0000005 error

 

This can not work since nentsel is not a function that creates selection set, and variable pss is also not defined.

In condion statement you have (> (sslength ss) 1)

Read here what nentsel is used for.

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 7

ВeekeeCZ
Consultant
Consultant

That's a known issue - read a caution HERE  on Lee's page. Edit: I was hoping that the same note I'll find HERE , unfortunately not.

 

So either ZOOM Extents prior to (ssget "c") if that's work for you or if the drawing is too large, zoom to a smaller area to make sure it's on-screen. Then you can ZOOM previous.

Yes, it slows things down. Or avoid using (ssget "c/cp/w/wp")... somehow.

 

 

 
0 Likes
Message 4 of 7

Anonymous
Not applicable

@hak_vz  Pardon that line, I should have removed it before posting (it has ; demarked). I found on another forum they used an nentsel to solve the 0xC0000005 error, before I tracked mine down further to being my view range. Experimental place holder to remind myself I tried it.

(> (sslength ss) 1) is to verify more than one PLine is selected.

 

@ВeekeeCZ well darn, there it is. Not the news I was hoping for but manageable to work around it. I originally used a vlax-invoke to get the intersects and it functioned, but it kept forgetting the remaining intersetion points half way through on larger selection sets. Maybe due to it breaking the original selected lines. The ssget never had issues with objects out of view on that one:

(cond
    ((and (setq ss (ssget ":L" '((0 . "lwpolyline"))))
          (> (sslength ss) 1)
          (setq ss (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
          (setq nextss ss))
   (foreach thispnt	ss
       (if (setq pts (apply 'append
			    (mapcar '(lambda (x) (vlax-invoke thispnt 'intersectwith x acextendnone))
				    (setq nextss (cdr nextss))
				    )))
   (while	(caddr pts)
	   (cond ((and (setq XYpnt (list (car pts) (cadr pts)))
                 (setq Dpnt (vlax-curve-getdistatpoint thispnt XYpnt))
                 (setq p1a (vlax-curve-getpointatdist thispnt (+ Dpnt 0)))
                 (setq p2a (vlax-curve-getpointatdist thispnt (- Dpnt 0)))
                 (setq p1 (list (car p1a) ( - (cadr p1a) gap) (caddr p1a)))
                 (setq p2 (list (car p2a) ( + (cadr p2a) gap) (caddr p2a)))
                 )
            (command "_.break" (mapcar '+ p1 '(0 0)) (mapcar '+ p2 '(0 0)))
            ))
	        (setq pts (cdddr pts)))))
    ))

 

Nonethelss, seems a ZOOM-Object ZOOM-Previous might be easiest. I'll move forward with that. Thank you!-

0 Likes
Message 5 of 7

Anonymous
Not applicable

Interestingly enough, just tried it on 2021 and it worked without issues... guess that bug is finally down for the count.

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

It could have something to do with THIS  feature which was added to some update of 2018... with some change in 2019... something like that. Not sure though.

0 Likes
Message 7 of 7

Anonymous
Not applicable

That was it!! SELECTIONOFFSCREEN>2 did the trick. Outstanding, thank you-

0 Likes