
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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))
;==================================================================================================================================================
Solved! Go to Solution.