PDA

View Full Version : LISP Routine: Moving selected polyline to Z value of selected point (and changing layer of polyline)



jcml
2016-04-13, 05:29 PM
Hi all,

I learned AutoLISP back in the end of 2005 (it's been ten years... how time flies) for a school project.
I was pretty happy with the results and that I could say that we made a script that does sort of the same as a LOFT - some months before Autodesk released it in AutoCAD 2007.

Now in a different project I need something to help me not losing a massive amount of time doing a repetitive process but I don't remember a thing about AutoLISP. I used to use it for everything for a couple of years but I rarely use AutoCAD these days.

I want to ask if you know if it's available a script/command that does this:

- After calling the command moves a selected polyline's Z value to the Z value of a selected point (either both selected together and the command knows the difference or the point is selected after)
- Moves the changed polyline to a different layer

And not being available, do you thing it's easy to learn how to do it? (all over again)

Cheers

marko_ribar
2016-04-13, 05:43 PM
Is polyline LWPOLYLINE, placed in WCS or plane parallel to WCS?

jcml
2016-04-13, 06:00 PM
If I saw it correctly they are placed in the WCS.

How can I identify if the Polylines are lightweight?

marko_ribar
2016-04-13, 06:05 PM
If I saw it correctly they are placed in the WCS.

How can I identify if the Polylines are lightweight?

Use this syntax :
(entget (car (entsel)))

Then pick polyline...
Check for (0 . "LWPOLYLINE") or (0 . "POLYLINE")...
Also check end of list and confirm if it prompts (210 0.0 0.0 1.0) - this means that it lies in plane parallel to WCS and that info is important to me...

jcml
2016-04-13, 06:31 PM
Thanks for the instructions.

Select object: ((-1 . <Entity name: 7ff7af649d70>) (0 . "LWPOLYLINE") (330 . <Entity name: 7ff7af6271c0>) (5 . "58CA7") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "101") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 -87639.1 -104113.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -87631.6 -104113.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -87631.6 -104110.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -87639.1 -104110.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0))

marko_ribar
2016-04-13, 06:39 PM
Ok, try this...



(defun c:matchelev ( / lw ptss pt p )
(setq lw (car (entsel "\nPick LWPOLYLINE that lies in plane parallel to WCS to match its elevation to elevation of reference point...")))
(prompt "\nSelect reference point to match elevations... Just one point...")
(setq ptss (ssget '((0 . "POINT"))))
(setq pt (ssname ptss 0))
(setq p (cdr (assoc 10 (entget pt))))
(entupd (cdr (assoc -1 (entmod (subst (cons 38 (caddr p)) (assoc 38 (entget lw)) (entget lw))))))
(princ)
)


Regards...

jcml
2016-04-13, 08:53 PM
Many thanks! It worked perfectly. Sorry for the delay in the reply.

To make the polyline change layers after "moving" the Z value would this work?
(I don't have AutoCAD available at this moment)


(defun c:matchelev ( / lw ptss pt p )
(setq lw (car (entsel "\nPick LWPOLYLINE that lies in plane parallel to WCS to match its elevation to elevation of reference point...")))
(prompt "\nSelect reference point to match elevations... Just one point...")
(setq ptss (ssget '((0 . "POINT"))))
(setq pt (ssname ptss 0))
(setq p (cdr (assoc 10 (entget pt))))
(entupd (cdr (assoc -1 (entmod (subst (cons 38 (caddr p)) (assoc 38 (entget lw)) (entget lw))))))
(setq lw "" "LA" "[layername]" "")
(princ)
)

marko_ribar
2016-04-14, 06:47 AM
No this will do it...



(defun c:matchelev ( / lw ptss pt p )
(setq lw (car (entsel "\nPick LWPOLYLINE that lies in plane parallel to WCS to match its elevation to elevation of reference point...")))
(prompt "\nSelect reference point to match elevations... Just one point...")
(setq ptss (ssget '((0 . "POINT"))))
(setq pt (ssname ptss 0))
(setq p (cdr (assoc 10 (entget pt))))
(entupd (cdr (assoc -1 (entmod (subst (cons 38 (caddr p)) (assoc 38 (entget lw)) (entget lw))))))
(entupd (cdr (assoc -1 (entmod (subst (cons 8 "[layername]") (assoc 8 (entget lw)) (entget lw))))))
(princ)
)

jcml
2016-04-14, 11:18 AM
Thanks again.

Cheers