Jump to content

Recommended Posts

Posted

Can anybody provides me with an Autolisp program that can extract heights from a 3D polyline at specified distances and the result (elevations) to be displayed in a txt file (text editor)? (in any version of AutoCAD)

Posted

height is coordinate Z?

;------------ RUS ------------------------------------------------
; Точка лежащая от точки P1 на расстоянии L в направлении точки P2
;-----------------------------------------------------------------
;Параметры:
;p1 - первая точка
;p2 - точка в направлении которой откладывается расстояние
;L  - расстояние

;------------ EN --------------------------------------------
;Point laying from point P1 on distance L in a direction of point P2
;
; Parameters:
; p1 - the first point
; p2 - the point in which direction is postponed distance
; L - distance
(defun 3d_polarp (P1 P2 L)
(setq L (/ L (distance P1 P2)))
(mapcar '+ P1 (mapcar '(lambda (V) (* V L)) (mapcar '- P2 P1)))
)
;;Get coors from 3d polyline
;; pline - ename 3d polyline
(defun _get_coors_3dpoly ( pline / tmp_ent coors ent_data)
 (setq tmp_ent pline)
 (while (/= "SEQEND" (cdr(assoc 0 (setq ent_data (entget(setq tmp_ent (entnext tmp_ent)))))))
   (setq coors (cons (cdr (assoc 10 ent_data))  coors))
  );_while
 (reverse coors)
 )
;;;Test command
;;Get Coordinates of a point on the specified distance from each vertex 3d polylines
(defun C:TEST (/ dst pl coors point_list filPath cFile oFlag)
 (initget 1)
 (if
   (and
     (setq dst (getdist "\nSpecify distance: "))
     (setq pl (car (entsel "\nPick a 3d polyline: ")))
     (member '(100 . "AcDb3dPolyline") (entget pl))
   ) ;_ end of and
    (progn
      (setq coors (_get_coors_3dpoly pl))
      (setq point_list
             (mapcar '(lambda (P1 P2)
                        (3d_polarp P1 P2 dst)
                      ) ;_ end of lambda
                     coors
                     (cdr coors)
             ) ;_ end of mapcar
      ) ;_ end of setq
;;;Export Data to Text File
      (setq filPath
             (getfiled "Save Coordinates to Text File"
                       "Coordinates.txt"
                       "txt;csv"
                       33
             ) ;_ end of getfiled
      ) ;_ end of setq
      (setq cFile (open filPath "w"))
      (foreach ln point_list
        (write-line
          (strcat (rtos (car ln))
                  ","
                  (rtos (cadr ln))
                  (if (= 3 (length ln))
                    (strcat "," (rtos (nth 2 ln)))
                  ) ;_ end of if
          ) ;_ end of strcat
          cFile
        ) ;_ end of write-line
      ) ;_ end of foreach
      (close cFile)
      (initget "Yes No")
      (setq oFlag (getkword "\nOpen text file? [Yes/No] <No> : "))
      (if (= oFlag "Yes")
        (startapp "notepad.exe" filPath)
      ) ;_ end of if
    ) ;_ end of progn
    (alert "Not a 3d polyline")
 ) ;_ end of if
 (princ)
) ;_ end of defun

Type TEST in command line to execute

Posted

Thanks so much VVA, I appreciate ur response. But, the code is giving only cordinates of two points, not cordinates of all the specified points (at given distances).

Please adjust the code to output the cordinates of all the specified points.

Thank you for coperation

Posted

The command exports all coordinates of points on the specified distance from each vertex of polyline.

Give an example polyline and points which coordinates are necessary for exporting that it is better to understand a problem

Posted

Thanks, VVA, I'll test the codes now and feed you back soonest

  • 7 years later...
Posted

My question would be : how to get this code to work ?! :D (I've heard of it, but never used LISP before...)

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