mhy3sx Posted 20 hours ago Posted 20 hours ago I am searching for a lisp code to draw a section line like the test.dwg. 1) Select 2 points for the length of the section 2) Pick a point for the direction of the section 3) Draw section line with the arrows and ask for the section letter for exampl A,B Thanks TEST.dwg Quote
mhy3sx Posted 17 hours ago Author Posted 17 hours ago (defun C:SECTIONLINE ( / pt1 pt2 dirpt baseAngle dirAngle angle arrowLen arrowAng secLetter txtpt angleDeg p1 p2 ) (setq arrowLen 10.0) (setq arrowAng (/ pi 6.0)) (setq pt1 (getpoint "\nSelect first point of section line: ")) (if (not (and pt1 (listp pt1))) (progn (princ "\nCanceled or invalid first point.") (quit)) ) (setq pt2 (getpoint pt1 "\nSelect second point of section line: ")) (if (not (and pt2 (listp pt2))) (progn (princ "\nCanceled or invalid second point.") (quit)) ) (setq dirpt (getpoint "\nPick a point to define section direction: ")) (if (not (and dirpt (listp dirpt))) (progn (princ "\nCanceled or invalid direction point.") (quit)) ) (setq baseAngle (angle pt1 pt2)) (setq dirAngle (angle pt1 dirpt)) (setq angle (if (< (abs (- baseAngle dirAngle)) (/ pi 2.0)) baseAngle (+ baseAngle pi))) (command "._LINE" "_non" pt1 "_non" pt2 "") (setq p1 (polar pt1 (+ angle arrowAng) arrowLen)) (setq p2 (polar pt1 (- angle arrowAng) arrowLen)) (command "._LINE" "_non" pt1 "_non" p1 "") (command "._LINE" "_non" pt1 "_non" p2 "") (setq p1 (polar pt2 (+ angle arrowAng) arrowLen)) (setq p2 (polar pt2 (- angle arrowAng) arrowLen)) (command "._LINE" "_non" pt2 "_non" p1 "") (command "._LINE" "_non" pt2 "_non" p2 "") (setq secLetter (getstring T "\nEnter section letter (e.g., A, B): ")) (if (= secLetter "") (setq secLetter "A")) (if (and (listp pt1) (listp pt2)) (progn (setq txtpt (mapcar '(lambda (a b) (/ (+ a b) 2.0)) pt1 pt2)) (setq angleDeg (* 180.0 (/ angle pi))) (command "._TEXT" "_non" txtpt 2.5 angleDeg (strcat secLetter "-" secLetter)) ) (princ "\nText not placed due to invalid points.") ) (princ "\nSection line created successfully.") (princ) ) I have this error (I use ZWCAD) Command: SECTIONLINE Select first point of section line: Select second point of section line: Pick a point to define section direction: Error: undefined function - nil Thanks Quote
marko_ribar Posted 16 hours ago Posted 16 hours ago (edited) You haven't defined "arrowAng" variable and you are using it in (polar) function... Sorry, my mistake - you defined it firstly... [EDIT : You should changle variable "angle" to something different like "ang" as (angle) is AutoLISP function and then you should localize "ang" in main (defun) instead of "angle"...] Edited 15 hours ago by marko_ribar 1 1 Quote
mhy3sx Posted 2 hours ago Author Posted 2 hours ago Hi Bigal I try but I have problem with the angles. In my template the units set (mapcar 'setvar (list 'aunits 'auprec 'angdir 'angbase 'lunits 'luprec 'insunits ) (list 2 4 1 (/ pi 2) 2 3 6)) ; for ZWCAD (defun C:SECTIONLINE ( / pt1 pt2 dirpt baseAngle dirAngle ang arrowBase arrowHeight secLetter txtpt1 txtpt2 angleDeg p1 p2 p3 offset letterOffset) (command "._STYLE" "Section" "Arial" 0.0 1.4 0 "N" "N" "N") (if (= (tblsearch "layer" "Section") nil) (vl-cmdf "_layer" "_m" "Section" "_c" "10" "" "_lw" "0.05" "" "") ) (setvar "clayer" "Section") (setq arrowBase 0.69) (setq arrowHeight 0.27) (setq offset 0.11) (setq letterOffset 0.31) (setq pt1 (getpoint "\nSelect first point of section line: ")) (if (not (and pt1 (listp pt1))) (progn (princ "\nCanceled or invalid first point.") (quit)) ) (setq pt2 (getpoint pt1 "\nSelect second point of section line: ")) (if (not (and pt2 (listp pt2))) (progn (princ "\nCanceled or invalid second point.") (quit)) ) (setq dirpt (getpoint "\nPick a point to define section direction: ")) (if (not (and dirpt (listp dirpt))) (progn (princ "\nCanceled or invalid direction point.") (quit)) ) (setq secLetter (getstring T "\nEnter section letter (e.g., A, B): ")) (if (= secLetter "") (setq secLetter "A")) (setq baseAngle (angle pt1 pt2)) (setq dirAngle (angle pt1 dirpt)) (setq ang (if (< (abs (- baseAngle dirAngle)) (/ pi 2.0)) dirAngle (+ dirAngle pi))) (command "._LINE" "_non" pt1 "_non" pt2 "") (setq p1 (polar pt1 baseAngle offset) (setq p2 (polar p1 (+ baseAngle (/ pi 2.0)) (/ arrowBase 2.0))) (setq p3 (polar p1 (- baseAngle (/ pi 2.0)) (/ arrowBase 2.0))) (command "._PLINE" "_non" p2 "_non" (polar p1 ang arrowHeight) "_non" p3 "_non" p2 "") (command "._HATCH" "SOLID" "_L" "" "") (setq txtpt1 (polar pt1 ang letterOffset)) (setq angleDeg (* 400.0 (/ baseAngle pi))) (command "._TEXT" "J" "MC" "_non" txtpt1 0.27 angleDeg secLetter) (setq p1 (polar pt2 (- baseAngle pi) offset)) (setq p2 (polar p1 (+ baseAngle (/ pi 2.0)) (/ arrowBase 2.0))) (setq p3 (polar p1 (- baseAngle (/ pi 2.0)) (/ arrowBase 2.0))) (command "._PLINE" "_non" p2 "_non" (polar p1 ang arrowHeight) "_non" p3 "_non" p2 "") (command "._HATCH" "SOLID" "_L" "" "") (setq txtpt2 (polar pt2 ang letterOffset)) (command "._TEXT" "J" "MC" "_non" txtpt2 0.27 angleDeg secLetter) (princ "\nSection line created successfully.") (princ) ) Thanks Quote
Recommended Posts
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.