Michaels Posted August 7, 2010 Posted August 7, 2010 Hello, Suppose that I have specified four points, and I want to connect them with a Polyline entmake. How to build the start point and the rest of points in Polyline entmake ? A method to complete ..... (defun c:try (/ p1 p2 p3 p4 ) (if (setq p1 (getpoint "\nSpecify first Point :") p2 (getpoint "\nSpecify second Point : ") p3 (getpoint "\nSpecify third Point : ") p4 (getpoint "\nSpecify forth Point : ") ) (entmake (list (cons 0 "POLYLINE") [color="red"](cons 10 ..) (.................[/color] )) (princ) ) (princ) ) Thanks. Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 Before I show you how, a few other things first: The way that your IF statement is constructed will mean that only the last point selected will be tested for validity, you need to use an AND expression to check all the points are valid. Are you looking to create an LWPolyline, or a Polyline? Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 Also, here is an old thread of mine, which may help you: http://www.cadtutor.net/forum/showthread.php?44768-Entmake-Functions&p=302880&viewfull=1#post302880 Quote
Michaels Posted August 7, 2010 Author Posted August 7, 2010 This one sent by mistake, So please check the second one. Quote
Michaels Posted August 7, 2010 Author Posted August 7, 2010 Thanks, Yes. I should have added AND after the if to contain all points . Great notice. So I would like to know both of entmake(s) POLYLINE and LWPOLYLINE . The way in dealing with mapcar , function , lambda. are completely not clear to me, I mean , I have been trying to understand them for a long time now but with out that good knowledge at it... Here is Lwpolyline from your given link . (defun LWPoly (lst cls) (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)))) here is the second one with Polyline ... (defun Polyline (lst) (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)))) (mapcar (function (lambda (p) (entmake (list (cons 0 "VERTEX") (cons 10 p))))) lst) (entmakex (list (cons 0 "SEQEND")))) Thanks Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 Dealing with the LWPolyline first, all the vertices are stored as DXF Group 10 codes in the primary DXF Data list. Hence to create the LWPolyline, all we need to do is present a single list containing all the necessary data to the entmake(x) function and the LWPolyline will be created if possible. In my code: (defun LWPoly ( lst cls ) (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) ) ) ) The first list contains such data as the subclass markers, the number of vertices and whether the lwpolyline is open or closed. I then append this to the list that is returned by the mapcar function, which, in this case, contains all the vertex data. Each coordinate (vertex) in the list (lst) supplied to the mapcar function is passed to the lambda function, and this function is then evaluated, the result of each evaluation of the lambda function is subsequently returned in the resultant list. Hence, say we have a list: '((1 2) (3 4) (4 5)) After passing the list through our mapcar statement: (mapcar (function (lambda ( p ) (cons 10 p))) '((1 2) (3 4) (4 5))) We have: ((10 1 2) (10 3 4) (10 4 5)) For information about which DXF codes mean what, see here: http://images.autodesk.com/adsk/files/acad_dxf1.pdf Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 In your first example, we could approach it in this way: (defun c:try (/ p1 p2 p3 p4) (if (and (setq p1 (getpoint "\nSpecify First Point : " )) (setq p2 (getpoint "\nSpecify Second Point : ")) (setq p3 (getpoint "\nSpecify Third Point : " )) (setq p4 (getpoint "\nSpecify Fourth Point : ")) ) (entmakex (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 4) (cons 70 1) (cons 10 p1) (cons 10 p2) (cons 10 p3) (cons 10 p4) ) ) ) (princ) ) Quote
Michaels Posted August 7, 2010 Author Posted August 7, 2010 In your first example, we could approach it in this way: That's nice. And how about Polyline. I replaced the above ... (cons 0 "LWPOLYLINE") with (cons 0 "POLYLINE") and gave me an error with 90 in entmake. Thanks Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 Did you look at the document regarding DXF codes? Its not as easy as just changing the first entry, the DXF codes, and the way that the vertices are constructed is a completely different procedure for a Polyline. I shall post an example in a bit. Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 As you can see from my earlier link, the method of creating a Polyline is completely different to that of an LWPolyline: (defun Polyline ( lst ) (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)) ) ) (mapcar (function (lambda ( p ) (entmake (list (cons 0 "VERTEX") (cons 10 p))) ) ) lst ) (entmakex (list (cons 0 "SEQEND"))) ) For a Polyline, we must entmake(x) each separate VERTEX entity in succession and then entmake a terminating SEQEND entity to declare that we have finished constructing the Polyline. The logic of mapcar follows from above, and you can again look up the DXF codes in the document I linked you to. Quote
Michaels Posted August 7, 2010 Author Posted August 7, 2010 In my code: (defun LWPoly ( lst cls ) (entmakex [color="red"](append[/color] (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls) ) [color="red"](mapcar (function (lambda ( p ) (cons 10 p))) lst)[/color] ) ) ) What's the purpose of append in the code above plus (mapcar (func..... ? Thanks Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 As an example similar to your first post - but I would be inclined to use mapcar in this instance: (defun c:try ( / p1 p2 p3 p4 ) (if (and (setq p1 (getpoint "\nSpecify First Point : ")) (setq p2 (getpoint "\nSpecify Second Point : ")) (setq p3 (getpoint "\nSpecify Third Point : ")) (setq p4 (getpoint "\nSpecify Fourth Point : ")) ) (progn (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)) ) ) (entmakex (list (cons 0 "VERTEX") (cons 10 p1))) (entmakex (list (cons 0 "VERTEX") (cons 10 p2))) (entmakex (list (cons 0 "VERTEX") (cons 10 p3))) (entmakex (list (cons 0 "VERTEX") (cons 10 p4))) (entmakex (list (cons 0 "SEQEND"))) ) ) (princ) ) Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 What's the purpose of append in the code above plus (mapcar (func..... ? The first list contains such data as the subclass markers, the number of vertices and whether the lwpolyline is open or closed. I then append this to the list that is returned by the mapcar function, which, in this case, contains all the vertex data. ^^ As previously explained. Quote
Michaels Posted August 7, 2010 Author Posted August 7, 2010 As an example similar to your first post - but I would be inclined to use mapcar in this instance: (defun c:try ( / p1 p2 p3 p4 ) (if (and (setq p1 (getpoint "\nSpecify First Point : ")) (setq p2 (getpoint "\nSpecify Second Point : ")) (setq p3 (getpoint "\nSpecify Third Point : ")) (setq p4 (getpoint "\nSpecify Fourth Point : ")) )(progn (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)) ) ) (entmakex (list (cons 0 "VERTEX") (cons 10 p1))) (entmakex (list (cons 0 "VERTEX") (cons 10 p2))) (entmakex (list (cons 0 "VERTEX") (cons 10 p3))) (entmakex (list (cons 0 "VERTEX") (cons 10 p4))) [color="red"](entmakex (list (cons 0 "VERTEX") (cons 10 p1)))[/color]<-- i added this to close the pose. (entmakex (list (cons 0 "SEQEND"))) ) ) (princ) ) It's perfect. but what do you mean by "SEQEND" ? Thanks Quote
stevesfr Posted August 7, 2010 Posted August 7, 2010 Wow, was this a great teaching excerise or what !!! thanks Lee S Quote
Lee Mac Posted August 7, 2010 Posted August 7, 2010 It's perfect. but what do you mean by "SEQEND" ? For a Polyline, we must entmake(x) each separate VERTEX entity in succession and then entmake a terminating SEQEND entity to declare that we have finished constructing the Polyline. Once again, as previously explained ^^ Seriously man, do you not read my posts? Quote
Michaels Posted August 8, 2010 Author Posted August 8, 2010 I am facing difficulties with the Polyline , I can't understand most of them . :( (defun Polyline ( lst ) (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)) ) ) (mapcar (function (lambda ( p ) (entmake (list (cons 0 "VERTEX") (cons 10 p))) ) ) lst ) (entmakex (list (cons 0 "SEQEND"))) ) Please forgive my hard understanding with that . :oops: Sorry.... Quote
The Buzzard Posted August 8, 2010 Posted August 8, 2010 Michaels, Give this a try and read each comment to see what going on. I mixed it with your code. (defun c:try (/ p1 p2 p3 p4 plst) ;Define function, Declare local variables (setq p1 (getpoint "\nSpecify First Point : ") ;Get point 1 p2 (getpoint "\nSpecify Second Point : ") ;Get point 2 p3 (getpoint "\nSpecify Third Point : ") ;Get point 3 p4 (getpoint "\nSpecify Fourth Point : ")) ;Get point 4 (setq plst (list p1 p2 p3 p4)) ;Place all the points in a list call plst (Polyline plst) ;Go to the Polyline function using the supplied list plst (princ) ;Exit quietly ) ;End defun (defun Polyline ( lst ) ;Polyline function, lst is the argument you are feeding plst to (entmakex ;Entity Make (list ;List (cons 0 "POLYLINE") ;Entity type 3D polyline (cons 10 '(0 0 0)) ;Dummy point XYZ ) ;End list ) ;End entmakex (mapcar ;Returns a list that is the result of executing a function with a list (or lists) ;supplied as arguments to the function (function ;Tells the Visual LISP™ compiler to link and optimize an argument as ;if it were a built-in function (lambda ( p ) ;Defines an anonymous function (entmake ;Entmake (list ;List (cons 0 "VERTEX") ;Polyline vertex (cons 10 p) ;Polyline points ) ;End list ) ;End entmake ) ;End lambda ) ;End function lst ;lst ) ;End mapcar (entmakex ;Entmake (list ;List (cons 0 "SEQEND") ;Sequence End ) ;End list ) ;End make ) ;End defun Quote
Michaels Posted August 8, 2010 Author Posted August 8, 2010 Michaels, Give this a try and read each comment to see what going on. I mixed it with your code. (defun c:try (/ p1 p2 p3 p4 plst) ;Define function, Declare local variables (setq p1 (getpoint "\nSpecify First Point : ") ;Get point 1 p2 (getpoint "\nSpecify Second Point : ") ;Get point 2 p3 (getpoint "\nSpecify Third Point : ") ;Get point 3 p4 (getpoint "\nSpecify Fourth Point : ")) ;Get point 4 (setq plst (list p1 p2 p3 p4)) ;Place all the points in a list call plst (Polyline plst) ;Go to the Polyline function using the supplied list plst (princ) ;Exit quietly ) ;End defun (defun Polyline ( lst ) ;Polyline function, lst is the argument you are feeding plst to (entmakex ;Entity Make (list ;List (cons 0 "POLYLINE") ;Entity type 3D polyline (cons 10 '(0 0 0)) ;Dummy point XYZ ) ;End list ) ;End entmakex (mapcar ;Returns a list that is the result of executing a function with a list (or lists) ;supplied as arguments to the function (function ;Tells the Visual LISP™ compiler to link and optimize an argument as ;if it were a built-in function (lambda ( p ) ;Defines an anonymous function (entmake ;Entmake (list ;List (cons 0 "VERTEX") ;Polyline vertex (cons 10 p) ;Polyline points ) ;End list ) ;End entmake ) ;End lambda ) ;End function lst ;lst ) ;End mapcar (entmakex ;Entmake (list ;List (cons 0 "SEQEND") ;Sequence End ) ;End list ) ;End make ) ;End defun Waw Waw ..... That's so great Buzzard. Thank you so much for your precious help. :) Regards, Quote
The Buzzard Posted August 8, 2010 Posted August 8, 2010 Waw Waw ..... That's so great Buzzard. Thank you so much for your precious help. :) Regards, Do you understand now what is going on? 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.