Transform points from lwpolyline with entmod

Transform points from lwpolyline with entmod

carlos_m_gil_p
Advocate Advocate
1,575 Views
15 Replies
Message 1 of 16

Transform points from lwpolyline with entmod

carlos_m_gil_p
Advocate
Advocate

Hello boys how are you.

 

I wanted to consult, how to transform points of lwpolyline with entmod.
I want to edit lwpolyline.
I want to project it in the view I am in, whether it is top, front, side, etc.
But I don't understand how to apply the entmod with lwpolyline.
I am attaching a dwg of what I want.
The red polyline is the original.
The white polyline as it should be if I am in a frontal view.
The green polyline as it should look if I am in a top view.
As far as you can help me, I thank you.
Sorry about my English, I only speak Spanish.
Greetings.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Accepted solutions (1)
1,576 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant

First question:  Do Polylines that you want to project in this way ever include arc segments?  Those would become elliptical in projection if the source Polyline is not parallel to the plane you want to project it onto, so a Polyline could not be an accurate projection.

Kent Cooper, AIA
0 Likes
Message 3 of 16

_gile
Consultant
Consultant
Accepted solution

If the polyline only have line segment (as noticed by @Kent1Cooper), this routine should do the trick:

(defun projectOnViewPlane (pline / elst el vd)
  (setq	elst (entget pline)
	el   (cdr (assoc 38 elst))
	vd   (trans '(0 0 1) 2 0 T)
  )
  (entmod
    (mapcar
      (function
	(lambda	(x)
	  (cond
	    ((= 10 (car x)) (cons 10 (trans (list (cadr x) (caddr x) el) pl vd)))
	    ((= (car x) 38) (cons 38 0.))
	    ((= (car x) 210) (cons 210 vd))
	    (T x)
	  )
	)
      )
      elst
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 16

carlos_m_gil_p
Advocate
Advocate

Hi @Kent1Cooper , how are you? Thanks for your help.
I hadn't really thought about the curves thing.
Currently I use it in straight sections.
I do not know if you can leave a function apart, in case you need it with curves.
But in the first stay, only straight sections.

 

Hi @_gile , how are you? Thanks for your help too.
Try applying it to the red polyline and it gives an error.

 

(setq lw (car (entsel)))
(projectOnViewPlane lw)

AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 5 of 16

_gile
Consultant
Consultant

@carlos_m_gil_p  a écrit :

Try applying it to the red polyline and it gives an error.

 

(setq lw (car (entsel)))
(projectOnViewPlane lw)

It works as expected for me. What's the error message ?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 16

_gile
Consultant
Consultant

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 16

carlos_m_gil_p
Advocate
Advocate

Hi, how are you.
This is what it shows me on screen.

 

Screenshot 2021-05-24 103131.jpg


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 8 of 16

_gile
Consultant
Consultant

Oops!...

My mistake (pline instead of pl).

(defun projectOnViewPlane (pl / elst el vd)
  (setq	elst (entget pline)
	el   (cdr (assoc 38 elst))
	vd   (trans '(0 0 1) 2 0 T)
  )
  (entmod
    (mapcar
      (function
	(lambda	(x)
	  (cond
	    ((= 10 (car x)) (cons 10 (trans (list (cadr x) (caddr x) el) pl vd)))
	    ((= (car x) 38) (cons 38 0.))
	    ((= (car x) 210) (cons 210 vd))
	    (T x)
	  )
	)
      )
      elst
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 16

carlos_m_gil_p
Advocate
Advocate

Hi @_gile 

Now it does nothing.

Fixed the setq (setq elst (entget pl).....
I don't know how to use the lambda function, but in the result I see that the codes 10 have 3 values (x y z) and I think they should be 2 (x y)

((-1 . <Entity name: 1987bbe3d60>) (0 . "LWPOLYLINE") (330 . <Entity name: 1987bbe19f0>) (5 . "8E6") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (62 . 1) (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 2.16924 2.93981 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 2.66802 3.44022 -2.22045e-16) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 2.48333 4.29932 4.44089e-16) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 1.98456 3.79892 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 -0.57735 -0.57735 0.57735))

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 10 of 16

_gile
Consultant
Consultant


@carlos_m_gil_p  a écrit :

I don't know how to use the lambda function, but in the result I see that the codes 10 have 3 values (x y z) and I think they should be 2 (x y)


It does work (as shown in the screencast)
It does not matter if there's the Z coordinate or not in the 10 group and as you can see it's equal to 0 or (very closed to).
If you enter: (projectOnViewPlane (car (entsel))) at the command line and the command line shows the new DXF list, that means it worked.
You can replace entmod with entmake so that you'll see the source polyline and the newly created one.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 16

carlos_m_gil_p
Advocate
Advocate

Hello Brother how are you.
If it works, it was my mistake, it was not fully located in an orthogonal view.
If at some point you get a function, where the polyline has curves, that would be very good.
Thank you very much for your help and everyone's.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 12 of 16

carlos_m_gil_p
Advocate
Advocate

Hello @_gile @Kent1Cooper how are you.

Sorry to bother you again.

But I was doing some tests with the function and it is not working well.

But I don't know what it could be.

Could you do me a favor and check it out.

I am attaching the dwg that I am using.

With red polyline it works fine, but with white polyline, it is not the expected result.

Thanks again.
Greetings.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 13 of 16

_gile
Consultant
Consultant

Hi,

The white polyline have only 2 vertices and a thickness of 0.15 (DXF code group 39). So the projected polylines have also 2 vertices and a thickness of 0.15.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 14 of 16

carlos_m_gil_p
Advocate
Advocate

Hello @_gile how are you.
I've been checking, but I can't get it to work.
Could you help me modify it.
I thank you with all my heart.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 15 of 16

_gile
Consultant
Consultant

The white polyline is not a rectangle (i.e. a 4 vertices closed polyline). It is a 2 vertices polyine vertices with a thickness (it could be a line a thickness), an projecting such entity will always generate a 2 vertices polyine vertices with a thickness.
This is not the routine which need to be modified, this is the input entity.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 16 of 16

carlos_m_gil_p
Advocate
Advocate

Hi @_gile .
Sorry Sorry sorry.
I did not understand what you were explaining to me.
Everything was clarified.
Thank you.

 

Brother, I wanted to ask you another favor.
I am trying to modify the function to be more general.

And so it works with more entities.

But I haven't gotten it to work, I don't understand lambda much.
You could check it out, if it's not too much of a hassle.

Sorry my English, I only speak Spanish.

 

In this case, what I want is to add a list of codes that I want to modify and the value of z.
For now remove the value of code 10 from the polyline, to test with a point.
But as I mentioned, I have not been able to make it work.
But already working, I would only have to change the list of codes to be modified and add the comparisons of those codes.
Also note that sometimes code 39 is not in the list, if its value is 0.0 I don't know if that generates an error.

As always, thank you for your time and dedication to help me and teach me.
Thank you.

 

(setq lw (car (entsel))) ;Entity
(setq lc '(10 39)) ;codes to modify
(setq cz 0.0) ;Value in z

(projectOnViewPlane lw lc cz)

(defun projectOnViewPlane (pl lc cz / elst el vd) 
  (setq elst (entget pl)
        vd   (trans '(0 0 1) 2 0 T))
  (entmod 
    (mapcar 
      '(lambda (c) 
         (mapcar 
           '(lambda (x) 
              (cond 
                ((= (car c) 10) (cons 10 (trans (list (cadr x) (caddr x) cz) 1 0)))
                ((= (car c) 38) (cons 38 0.0))
                ((= (car c) 39) (cons 39 0.0))
                ((= (car c) 210) (cons 210 vd))
                (T x)))
           elst
           lc)))))

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes