AutoLisp

[AutoCAD] 오토캐드 에서 AutoLisp 강좌 예제 - 오토리습으로 길이를 구하기

데브프로그라 2024. 2. 21. 22:08
반응형

AutoCAD를 사용하다 보면, 객체의 길이를 알아야 할 때가 있는데, 필요할 때 마다 객체를 선택하고 속성의 정보를 보거나, 하나하나씩 길이를 측정해야 할 때가 있습니다.

명령을 실행하고, 원하는 객체를 선택하면 길이를 출력하는  Lisp입니다.

Pline, Line, arc, circle 모두 가능합니다.

getlength.lsp
0.00MB

(defun c:getlength()
 (vl-load-com)
 (setq x_object (entsel))
 (setq x_object (vlax-Ename->Vla-Object (car x_object)))  (setq x_length (vlax-curve-getdistatparam x_object (vlax-curve-getendparam x_object )))
 (princ (rtos x_length))(alert (strcat "길이 = " (rtos x_length)))(princ) 
)

getlength.lsp
0.00MB


결과:

명령:  GETLENGTH
객체 선택: 1695.5227


사용 방법1:
1. getlength.lsp 파일을 다운받아 원하는 위치에 복사합니다.
2. 명령창에 GETLENGTH 를 입력하면, 객체를 선택하라는 메시지가 나타납니다.
3. 객체를 선택하면, 선택한 객체의 레이어로 현재 레이어가 변경됩니다.

반응형

/* 코드복사 버튼 */ pre { position: relative; overflow: visible; } pre .copy-button { opacity: 0; position: absolute; right: 8px; top: 4px; padding: 6px 18px; color: rgb(255, 255, 255); background: rgba(255, 223, 0, 0.6); border-radius: 5px; transition: opacity .3s ease-in-out; } pre:hover .copy-button { opacity: 1; } pre .copy-button:hover { color: #eee; transition: all ease-in-out 0.3s; } pre .copy-button:active { color: #33f; transition: all ease-in-out 0.1s; } .copy-message:before { content: attr(copy-message); position: absolute; left: -95px; top: 0px; padding: 6px 18px; color: #fff; background: rgba(255, 223, 0, 0.6); border-radius: 5px; } /* 코드복사 버튼 END */