claude-2.0· Anthropic Arena Human Preference 55K
can you write lisp code for change polyline elevation? Comment line code.
- User
can you write lisp code for change polyline elevation? Comment line code.
- Assistant
Here is some Lisp code to change the elevation of a polyline in AutoCAD:
; Function to change polyline elevation ; polyline - the polyline entity name ; newElev - the new elevation value (defun c:ChangePolylineElevation (polyline newElev) (setq poly EntGet (car (entsel polyline))) ; Get the polyline entity ; Loop through all vertices (setq vertexList (entget (entget poly 1))) (foreach x vertexList (setq vertexPos (assoc 10 (cdr x))) ; Get vertex position (setq newPos (list (car vertexPos) (cadr vertexPos) newElev)) ; Replace Z value (entmod (subst (cons 10 newPos) (assoc 10 (cdr x)) x)) ; Modify vertex ) (entupd poly) ; Update polyline (princ "\nPolyline elevation changed") ) ; Example usage: ; Command: (ChangePolylineElevation "MyPoly" 100)The key steps are:
- Get the polyline entity using
entget - Loop through all vertices using
entgeton the polyline's first entity (the vertex list) - Extract the vertex position (on the 10th entity data)
- Construct a new position list with the new elevation
- Use
entmodandsubstto replace the old position with the new one - Call
entupdto update the polyline
This will iterate through each vertex and change its Z elevation value to the new value specified.
- Get the polyline entity using
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.