Skip to content
The Chat Archive
claude-2.0· Anthropic Arena Human Preference 55K

can you write lisp code for change polyline elevation? Comment line code.

  1. User

    can you write lisp code for change polyline elevation? Comment line code.

  2. 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:

    1. Get the polyline entity using entget
    2. Loop through all vertices using entget on the polyline's first entity (the vertex list)
    3. Extract the vertex position (on the 10th entity data)
    4. Construct a new position list with the new elevation
    5. Use entmod and subst to replace the old position with the new one
    6. Call entupd to update the polyline

    This will iterate through each vertex and change its Z elevation value to the new value specified.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.