- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone!
Beginner here, and I'm stuck. I am trying to create a lisp where I want to find all arcs and/or arc segments (in all sort of polylines).
So basically the program should do this:
The user enters a radius, and then gets to select which objects to be included in the selection set. The lisp goes through all arcs and arc segments in the selection set, and for every instance where the arc/arc segment has equal radius to the user specified radius the lisp somehow shows that the given arc/arc segment is a match (I haven't figured how the lisp should show it, but for example it could create a circle around each arc/arc segment that is a match as I've coded it now).
I have tried writing my own code as well as copy/pasting from different lisps I have found, but there seems to be a problem. For arcs it works perfectly, but when I am trying to find the radius of an arc segment of a *polyline the lisp fails: "Error: ActiveX Server returned the error: unknown name: "RADIUS" ". The polyline gets exploded but I believe fails to execute the test if the current segment of the polyline is an arc. Is my lisp trying to find the radius of a line or why does it not find the radius of the arc segments?
Any help is appreciated!
(defun c:ksr
(/ *error*)
(defun *error* (msg)
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ (strcat "\nError: " msg))
)
(if acdoc
(vla-endundomark acdoc)
)
(princ)
)
(defun LM:roundm ( n m )(* m (atoi (rtos (/ n (float m)) 2 0))))
;(setq selectedRadius (getreal"\nEnter radius: "))
(setq selectedRadius 15) ;for testing only to avoid having to type in radius every test
(print selectedRadius) ;just to see if the lisp manages to function this far
(prompt "\nSelect objects in layer M-DEC---E1N")
(setq ss (ssget '((0 . "ARC,LWPOLYLINE,POLYLINE,2DPOLYLINE,3DPOLYLINE") (8 . "M-DEC---E1N"))) i -1)
(print ss) ;just to see if the lisp manages to function this far
(while (< (setq i (1+ i)) (sslength ss))
(setq to (vlax-ename->vla-object (ssname ss i)))
(cond
((= (vlax-get to 'objectname) "AcDbArc")
;insert code what happens if object is arc
;(print "arc") ;just for testing to check what happens when the condition is true
(setq objectRadius (LM:roundm (vlax-get to 'radius) 0.05)
objectStartPoint (vlax-get to 'startpoint)
objectEndPoint (vlax-get to 'endpoint)
)
(if
(= selectedRadius objectRadius)
;(entmake '((0 . "CIRCLE") (62 . 1) (10 (vlax-get to 'startpoint)) (40 . 1.0)))
(command "circle" "2p" objectStartPoint objectEndPoint)
)
);end condition arc
((or (= (vlax-get to 'objectname) "AcDbPolyline")(= (vlax-get to 'objectname) "AcDb2dPolyline")(= (vlax-get to 'objectname) "AcDb3dPolyline"))
(setq olst (vlax-invoke to 'explode))
(foreach eo olst
(cond
((= (vlax-get eo 'objectname) "AcDbArc")
(if
(= (vlax-get eo 'objectname) "AcDbArc")
(setq objectRadius (LM:roundm (vlax-get to 'radius) 0.05)
objectStartPoint (vlax-get to 'startpoint)
objectEndPoint (vlax-get to 'endpoint)
)
)
(if
(= selectedRadius objectRadius)
(command "circle" "2p" objectStartPoint objectEndPoint)
)
)
)
)
(mapcar 'vla-delete olst)
);end condition arc segment
);end cond
); end while
(princ)
);end
Solved! Go to Solution.