pondpepo9 Posted September 17 Posted September 17 "Could you please help me modify this exceed code to work with AutoCAD 2024 LT?" Quote
Saxlle Posted September 17 Posted September 17 (edited) Hi @pondpepo9, Try with this modification. (defun c:spl2pl ( / ss i ent ss3 ss2 obj cpcount j ) (princ "\n Select spline to convert to pline : ") (setq ss (ssget '((0 . "SPLINE")))) (setq i 0) (setq ss3 (ssadd)) (repeat (sslength ss) (setq ent (ssname ss i)) (command "_explode" ent "") (setq ss2 (ssget "_P")) (setq j 0) (repeat (sslength ss2) (setq ent2 (ssname ss2 j)) ;;; (setq obj (vlax-ename->vla-object ent2)) -> Autocad 2024 LT doesn't support a "vla-, vlax-, and vlr- functions" (setq cpcount (cdr (assoc 73 (entget ent2)))) ;; this will replace code from above and bottom ;;; (setq cpcount (vlax-get-property obj 'Numberofcontrolpoints)) -> there is a "vlax-" function (command "_SPLINEDIT" ent2 "_P" cpcount "") (ssadd (entlast) ss3) (setq j (+ j 1)) ) (setq i (+ i 1)) ) (if (> (sslength ss3) 1) (progn (command "_pedit" "_M" ss3 "" "J" "0" "") ) (progn (command "_pedit" ss3 "") ) ) (princ) ) Best regards. Edited September 17 by Saxlle 1 Quote
Steven P Posted September 17 Posted September 17 What are the spine shapes like? You might save a few minutes with a LISP on a simple shape but sometimes drawing over it will give you more accurate and better results. To do this well you need to convert the spline to exploded polylines - short straight lines, to assess which of these lines form arcs and curves, replace these arc and curve chords with arcs, combine the whole lot to a polyline.. which is quite a lot. Arcs are the trickiest to assess, the original drawing might have been polyline converted to splines so the arcs are consistent throughout, some are drawn as splines and the radius changes through the curve.... trickier! However the above LISP will give a fair estimation. 1 Quote
marko_ribar Posted September 17 Posted September 17 @Saxlle This line : (command "_pedit" "_M" ss3 "" "J" "0" "") won't work well if you don't set before it : (setvar (quote peditaccept) 1) I always use setting it before with (setq pea (getvar (quote peditaccept))) => (setvar (quote peditaccept) 1) And at the end resetting it to starting value : (setvar (quote peditaccept) pea) 1 Quote
Saxlle Posted September 17 Posted September 17 You're right @Steven P, it can be difficult to achieve "just" conversion in a polyline. I'll keep that in mind if I run into such a problem as you mentioned, thanks. Thank you @marko_ribar, I learned something new. Best regards. Quote
pondpepo9 Posted September 18 Author Posted September 18 19 hours ago, Saxlle said: Hi @pondpepo9, Try with this modification. (defun c:spl2pl ( / ss i ent ss3 ss2 obj cpcount j ) (princ "\n Select spline to convert to pline : ") (setq ss (ssget '((0 . "SPLINE")))) (setq i 0) (setq ss3 (ssadd)) (repeat (sslength ss) (setq ent (ssname ss i)) (command "_explode" ent "") (setq ss2 (ssget "_P")) (setq j 0) (repeat (sslength ss2) (setq ent2 (ssname ss2 j)) ;;; (setq obj (vlax-ename->vla-object ent2)) -> Autocad 2024 LT doesn't support a "vla-, vlax-, and vlr- functions" (setq cpcount (cdr (assoc 73 (entget ent2)))) ;; this will replace code from above and bottom ;;; (setq cpcount (vlax-get-property obj 'Numberofcontrolpoints)) -> there is a "vlax-" function (command "_SPLINEDIT" ent2 "_P" cpcount "") (ssadd (entlast) ss3) (setq j (+ j 1)) ) (setq i (+ i 1)) ) (if (> (sslength ss3) 1) (progn (command "_pedit" "_M" ss3 "" "J" "0" "") ) (progn (command "_pedit" ss3 "") ) ) (princ) ) Best regards. Quote
Saxlle Posted September 18 Posted September 18 (edited) Hi @pondpepo9, The reason why you're getting "error: bad argument type: lselsetp nil" is because "(sslength ss)" is 0, which means that when you asked to "Select a spline to convert to pline:", there is no "SPLINE" entity in the drawing. Can you post a .dwg file? Best regards. Edited September 18 by Saxlle 1 Quote
SLW210 Posted September 18 Posted September 18 On 9/17/2024 at 5:29 AM, Saxlle said: Hi @pondpepo9, Try with this modification. -> Autocad 2024 LT doesn't support a "vla-, vlax-, and vlr- functions" Best regards. You might want to check...AutoCAD LT 2024 Help | What's New or Changed with AutoLISP (AutoLISP) | Autodesk. Quote Here are some of the known limitations or differences from AutoCAD: Most VL*, VLA*, VLAX*, and VLR* functions are supported, but the use of third-party automation libraries is not supported in to AutoCAD LT. Here is a high-level summary of the functions that are not supported: vlax-create-object vlax-get-object vlax-get-or-create-object vlax-import-type-library vla-GetInterfaceObject VLA* functions related to creating and modifying 3D solid and surface, helix, material, multiline objects among others that can only be created in AutoCAD Quote
SLW210 Posted September 19 Posted September 19 I have this, but the straighter parts also slightly arced. Works for my uses, if I have time, I'll look at something to make the straighter parts non-arcs. ;;; Convert 2D splines to polyline arcs. ;;; ;;; https://www.cadtutor.net/forum/topic/91181-convert-spline-to-polyline/?do=findComment&comment=651477 ;;; ;;; By SLW210 (Steve Wilson) ;;; ;;; (defun c:S2CP ( / ss i ent precision) (SETVAR "PLINECONVERTMODE" 1) (setq precision 5) ;; Set default precision (princ "\nSelect splines to convert to polylines: ") (setq ss (ssget '((0 . "SPLINE")))) ;; Ensure selection is valid (if (and ss (> (sslength ss) 0)) (progn (setq i 0) ;; Initialize counter ;; Loop through each selected spline (while (< i (sslength ss)) (setq ent (ssname ss i)) ;; Use the SPLINEDIT command with the correct options (command "_SPLINEDIT" ent "_P" precision) (setq i (1+ i)) ;; Increment counter ) (princ "\nSplines converted to polylines.") ) (princ "\nNo valid splines selected.") ) (princ) ) Quote
SLW210 Posted September 19 Posted September 19 On 9/18/2024 at 1:44 AM, Saxlle said: Hi @pondpepo9, The reason why you're getting "error: bad argument type: lselsetp nil" is because "(sslength ss)" is 0, which means that when you asked to "Select a spline to convert to pline:", there is no "SPLINE" entity in the drawing. Can you post a .dwg file? Best regards. I get the same error and I definitely have splines in the drawing. Both AutoCAD 2024 at work and AutoCAD 2000i at home. There is a .dwg in the linked thread in the first post. Quote
SLW210 Posted September 19 Posted September 19 I have somewhere (or had ?) an old dxfout-dxfin LISP, does AutoCAD 2024 LT have those commands? Quote
Saxlle Posted September 19 Posted September 19 According to this link (the first one I found, also there is a list of explodeable entities): https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-88A2E2A3-B8F3-45AE-A484-F366072ADDF6 "AcDbSpline" is not explodeable. But something else is weird, when you draw and combine two or more splines into one, it can be exploded, but when you draw a "single" spline, it doesn't (i supposed that is the main reason why "error: bad argument type: lselsetp nil", because after this line of code: (command "_explode" ent "") get: "Cannot explode SPLINE"). I don't know the main reason? From this original post: https://www.cadtutor.net/forum/topic/78667-convert-spline-to-polyline/ , in dwg is spline entity, which is combined with two and more splines, and it can be exploded, and rest original lisp from "exceed" works well, as well the modified lisp. Maybe someone can give an explanation about this. Best regards. Quote
SLW210 Posted September 19 Posted September 19 DXFout>DXFin to older version (R12) is all that works on my AutoCAD 2000i at home. WMFout and WMFin probably works, but usually a scaling problem IIRC. You could also do a Wblock to a R12 dxf and select objects. Even SAVE and SAVEAS can do R12 DXF IIRC. Maybe a Script would work better? Maybe incorrect information on the AcDbSpline, I have never been able to explode them. I'll have to look at that when I go back to work next week. I have posted a DWGtoDXF by folder conversion and a DXFtoDWG by folder on here somewhere, but not LT friendly. 1 Quote
Steven P Posted September 19 Posted September 19 I don't like splines if that is any help (electrically biased, so a lot of single lines and schematics, nice, net parallel lines, ahhhh...) There was a LISP - PLDiet which might help out a little - convert splines to polylines using a small enough segment length and then pldiet that to join polyline segments, not sure if that would be any good? 1 Quote
SLW210 Posted September 20 Posted September 20 https://cadtips.cadalyst.com/linear-objects/polyline-diet One by ribarm at https://www.theswamp.org/index.php?topic=58030.0 (marko_ribar on CADTutor) Also a LISP called Weed. https://cadtips.cadalyst.com/linear-objects/weed-r13-polylines 1 Quote
lrm Posted September 22 Posted September 22 I've been experimenting with a method to give greater user control in the conversion of a 2D spline to a polyline. The following program enables the user to specify the maximum number of vertices for the resulting polyline from a selected spline. The program calculates the instantaneous radius of curvature for points along the spline. If the magnitude of the radius is above a specified threshold then a vertex for the polyline is not created at that point. The image below shows the results of using the splinedit commad (left column) and the program (right column). The radius of curvature is output to aid the user in determining an appropriate threshold for successive runs of the program. Note that the program creates vertices closer together where the spline radius is small and further apart for flatter sections of the spline. The splines are red and polylines yellow in the image below. (defun C:SmartSPL2POLY (/ spl ptList i n maxCurva smax ds s pOld der1 der2 d p ) ; Creates a polyline from a 2D spline. The user can control the number of vertices in ; the resulting polyline and omit vertices that have a radius of curvature greater ; than a specifed threshold. ; Lee Minardi 9/22/2024 ; (setq spl (car (entsel "\nSelect Spline.")) ptList nil i 0 n (getint "\nEnter maximum number of vertices for polyline: ") maxCurva (getreal "\nEnter maximum curvature: ") smax (vlax-curve-getEndParam spl) ds (/ smax n) s ds ) (setq pOld (vlax-curve-getPointAtParam spl 0.0)) (setq ptlist (list pOld)) (repeat (+ n 1) (setq der1 (vlax-curve-getfirstDeriv spl s) der2 (vlax-curve-getSecondDeriv spl s) ) ; calculate curvature at point p (setq d (distance '(0 0 0) (cross der1 der2))) (setq curva (/ (expt (distance '(0 0 0) der1) 3) d)) (princ "\nVertex #") (princ i) (princ " curvature = ") (princ curva) (if (< curva maxcurva) (setq p (vlax-curve-getPointAtParam spl s) ptList (append ptList (list p)) pOld p ) ) ; end if (setq i (1+ i) s (+ s ds) ) ) ; end repeat (setq p (vlax-curve-getPointAtParam spl smax) ptList (append ptList (list p)) ) (lwpoly ptList 0) (princ) ) (defun LWPoly (lst cls) ; Lee Mac's entmake functions (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls) ) (mapcar (function (lambda (p) (cons 10 p))) lst) ) ) ) ;;; Compute the cross product of 2 vectors a and b (defun cross (a b / crs) (setq crs (list (- (* (nth 1 a) (nth 2 b)) (* (nth 1 b) (nth 2 a)) ) (- (* (nth 0 b) (nth 2 a)) (* (nth 0 a) (nth 2 b)) ) (- (* (nth 0 a) (nth 1 b)) (* (nth 0 b) (nth 1 a)) ) ) ) ) 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.