EricDevault Posted Thursday at 04:46 PM Posted Thursday at 04:46 PM (edited) I have a lisp routine that works some of the time but the results are not the same every time, looking for some help. You select an edge that you want divided up with marks at a certain interval and select which side of the edge to draw the marks on. sometimes it puts the marks on the correct side but other times it is a mirror opposite of the side selected. (defun C:STEPMARKINGS (/ *Error* ) (while (/= (setq EDGEOFTREAD (car (entsel "\nSelect the edge of the piece where the markings will be added."))) nil) ;(setq EDGEOFTREAD (car (entsel "\nSelect the edge of the piece where the markings will be added."))) (while (= EDGEOFTREAD nil) (alert "Nothing selected. Select the edge of the piece where the markings will be added.") (setq EDGEOFTREAD (car (entsel "\nSelect the edge of the piece where the markings will be added."))) ) (setq OPOINT (getpoint "\nSelect a point inside the piece: ")) (command "offset" "1" EDGEOFTREAD OPOINT "") (setq TREADOFFSET (entlast)) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"ARC") (setq Enttype "ARC") () ) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LINE") (setq Enttype "LINE") () ) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LWPOLYLINE") (setq Enttype "LWPOLYLINE") () ) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"SPLINE") (setq Enttype "SPLINE") () ) (cond ((= Enttype "ARC") ;(alert "The entity you selected is an ARC");used only for diagnostics (setq EDGEOFTREADSTART (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "startpoint")) (setq EDGEOFTREADEND (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "endpoint")) (setq TREADOFFSETSTART (vlax-get(vlax-ename->vla-object TREADOFFSET) "startpoint")) (setq TREADOFFSETEND (vlax-get(vlax-ename->vla-object TREADOFFSET) "endpoint")) ) ((= Enttype "LINE") ;(alert "The entity you selected is a LINE");used only for diagnostics (setq EDGEOFTREADSTART (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "startpoint")) (setq EDGEOFTREADEND (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "endpoint")) (setq TREADOFFSETSTART (vlax-get(vlax-ename->vla-object TREADOFFSET) "startpoint")) (setq TREADOFFSETEND (vlax-get(vlax-ename->vla-object TREADOFFSET) "endpoint")) ) ((= Enttype "LWPOLYLINE") ;(alert "The entity you selected is a POLYLINE");used only for diagnostics (setq EDGEOFTREADSTART (vlax-curve-getstartpoint EDGEOFTREAD)) (setq EDGEOFTREADEND (vlax-curve-getEndPoint EDGEOFTREAD)) (setq TREADOFFSETSTART (vlax-curve-getstartpoint TREADOFFSET)) (setq TREADOFFSETEND (vlax-curve-getEndPoint TREADOFFSET)) ) ((= Enttype "SPLINE") ;(alert "The entity you selected is a SPLINE");used only for diagnostics (setq EDGEOFTREADSTART (vlax-curve-getstartpoint EDGEOFTREAD)) (setq EDGEOFTREADEND (vlax-curve-getEndPoint EDGEOFTREAD)) (setq TREADOFFSETSTART (vlax-curve-getstartpoint TREADOFFSET)) (setq TREADOFFSETEND (vlax-curve-getEndPoint TREADOFFSET)) ) ) (command "line" EDGEOFTREADSTART TREADOFFSETSTART "") (setq MARKING (entlast)) (command "chprop" MARKING "" "LA" "InkMark" "") (command "ERASE" TREADOFFSET "") (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"ARC") (setq Enttype "ARC") () ) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LINE") (setq Enttype "LINE") () ) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LWPOLYLINE") (setq Enttype "LWPOLYLINE") () ) (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"SPLINE") (setq Enttype "SPLINE") () ) (cond ((= Enttype "ARC") ;(alert "The entity you selected is an ARC");used only for diagnostics (vl-load-com) (setq TREADLEN (vla-get-arclength (vlax-ename->vla-object EDGEOFTREAD))) ) ((= Enttype "LINE") ;(alert "The entity you selected is a LINE");used only for diagnostics (vl-load-com) (setq TREADLEN (vla-get-length (vlax-ename->vla-object EDGEOFTREAD))) ) ((= Enttype "LWPOLYLINE") ;(alert "The entity you selected is a POLYLINE");used only for diagnostics (vl-load-com) (setq TREADLEN (vla-get-length (vlax-ename->vla-object EDGEOFTREAD))) ) ((= Enttype "SPLINE") ;(alert "The entity you selected is a SPLINE");used only for diagnostics (vl-load-com) (setq EDGEOFTREADVL (vlax-ename->vla-object EDGEOFTREAD)) (setq TREADLEN (vlax-curve-getDistAtPoint EDGEOFTREADVL (vlax-curve-getEndPoint EDGEOFTREADVL))) ) ) (setq TREADLENFEET (/ TREADLEN 12)) (setq MARKNUMROUGH (/ TREADLENFEET 2 )) (setq MARKNUMROUND (fix (+ MARKNUMROUGH (if (minusp MARKNUMROUGH) -0.5 0.5)))) (setq MARKNUM (+ MARKNUMROUND 2)) (cond ((<= TREADLENFEET 8) (setq MARKNUM 5) ) ) (initcommandversion) (command ".ARRAYPATH" MARKING "" EDGEOFTREAD "AS" "N" "M" "D" "I" MARKNUM "X") (setq LASTMARK (entlast)) (command "ERASE" LASTMARK MARKING "") ) (princ "Marking Complete") ) (defun *Error* ( msg ) (setq ORIGINALERROR *Error*) (setq *Error* ORIGINALERROR) (alert "There was an error. If you pressed escape to exit the routine, just press OK to close this box, and re-run this routine.") (princ "ERROR: You either pressed escape or something didnt work. Try again.") (command "ERASE" MARKING) (setvar 'qaflags 0) (princ msg) ) Edited Thursday at 05:14 PM by EricDevault Quote
GLAVCVS Posted Thursday at 06:19 PM Posted Thursday at 06:19 PM (edited) .The code seems to work fine You should attach an example drawing Edited Thursday at 06:27 PM by GLAVCVS Quote
EricDevault Posted Thursday at 06:42 PM Author Posted Thursday at 06:42 PM 21 minutes ago, GLAVCVS said: .The code seems to work fine You should attach an example drawing I have a drawing attached. And the odd thing is it works sometimes and sometimes not. It is also random on which machine it works on Drawing 3.dwg Quote
BIGAL Posted Friday at 07:29 AM Posted Friday at 07:29 AM If its pline/lines then i would have a good guess at Clockwise v's anti clockwise, it will make stuff go inside or out depending on direction, simple to check for. Also for plines need to use which segment selected not just pt1->pt2 etc. (defun getplineseg ( / elst ename pt param preparam postparam) (setq elst (entsel "\nSelect pline segment: ")) (setq ename (car elst)) (setq pt (cadr elst)) (setq pt (vlax-curve-getClosestPointTo ename pt)) (print (setq param (vlax-curve-getParamAtPoint ename pt)) ) (print (setq preparam (fix param)) ) (print (setq postparam (1+ preparam)) ) (setq pt1 (vlax-curve-getPointAtParam ename preparam) pt2 (vlax-curve-getPointAtParam ename postparam)) ) Quote
GLAVCVS Posted Friday at 07:37 AM Posted Friday at 07:37 AM The options specified in your code calling the 'arraypath' command do not seem to match those that appear in my version of AutoCAD. Could you explain each of them? Quote
EricDevault Posted Friday at 06:12 PM Author Posted Friday at 06:12 PM 10 hours ago, GLAVCVS said: The options specified in your code calling the 'arraypath' command do not seem to match those that appear in my version of AutoCAD. Could you explain each of them? These are the arguments for the standard command line arraypath, see the call (initcommandversion). If you initialize arraypath through lisp it is a different set of arguments that is why I stuck with the command version Quote
EricDevault Posted Friday at 06:16 PM Author Posted Friday at 06:16 PM 10 hours ago, BIGAL said: If its pline/lines then i would have a good guess at Clockwise v's anti clockwise, it will make stuff go inside or out depending on direction, simple to check for. Also for plines need to use which segment selected not just pt1->pt2 etc. (defun getplineseg ( / elst ename pt param preparam postparam) (setq elst (entsel "\nSelect pline segment: ")) (setq ename (car elst)) (setq pt (cadr elst)) (setq pt (vlax-curve-getClosestPointTo ename pt)) (print (setq param (vlax-curve-getParamAtPoint ename pt)) ) (print (setq preparam (fix param)) ) (print (setq postparam (1+ preparam)) ) (setq pt1 (vlax-curve-getPointAtParam ename preparam) pt2 (vlax-curve-getPointAtParam ename postparam)) ) The objects in the example drawing are either lines or arcs. Can you tell me more about clockwise v anti? Does that mean the way the lines and arcs were drawn? Or the orientation of start point and end point? How would I check for that? Quote
BIGAL Posted Saturday at 10:21 PM Posted Saturday at 10:21 PM Easy for lines or plines you pick an end when selecting this implies the start point. You compare the distance to the two ends and flip the pts if necessary. Minimal testing with arcs. (defun swapends (ent / obj) (setq pt3 (cadr ent)) (setq obj (vlax-ename->vla-object (car ent))) (setq start (vlax-curve-getstartPoint obj)) (setq end (vlax-curve-getEndPoint obj)) (setq d1 (distance pt3 end)) (setq d2 (distance pt3 start)) (if (< d1 d2) (progn (setq temp end) (setq end start) (setq start temp) ) ) (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.