Jump to content

Recommended Posts

Posted

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.

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • Michaels

    12

  • Lee Mac

    10

  • The Buzzard

    6

  • stevesfr

    1

Top Posters In This Topic

Posted

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?

Posted

This one sent by mistake, So please check the second one.

Posted

Thanks,

 

Yes. I should have added AND after the if to contain all points . Great notice.:D

 

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

Posted

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

Posted

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)
)

Posted
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

Posted

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.

Posted

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.

Posted

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

Posted

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)
)

Posted
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.

Posted
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

Posted

Wow, was this a great teaching excerise or what !!!

thanks Lee

S

Posted
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?

Posted

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: :oops:

 

Sorry....

Posted

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

Posted
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,

Posted
Waw Waw ..... That's so great Buzzard.

 

Thank you so much for your precious help. :) :)

 

Regards,

 

 

Do you understand now what is going on?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...