107
615
575
中流砥柱
Drawing scale factor 1= 1:100, 2 = 1:200, 3 = 1:500
;------------------------------------------------------------------------------; CAD Concepts Limited; ; BEARING DISTANCE TEXT; ; Copyright (C) 2011 CAD Concepts Limited.; BEARING DISTANCE TEXT by CAD Concepts Ltd is licensed under; a Creative Commons Attribution-ShareAlike 3.0 Unported License.; http://creativecommons.org/licenses/by-sa/3.0/nz/deed.en; For options available to you under this license.; This software is provided "as is". No liability is taken of; FITNESS FOR ANY PARTICULAR PURPOSE.;------------------------------------------------------------------------------; File : BD.lsp; Author : Jason Bourhill; Email : jason@cadconcepts.co.nz; Web : http://www.cadconcepts.co.nz; Date : 20/Mar/2011; CAD Ver(s) : Tested on AutoCAD 2010 & Bricscad V11; Purpose : Places Bearing & Distance text above and below selected lines;; Usage : To load type (load "BD.LSP") from the command line or drag; and drop the file onto your drawing using explorer. Will; automatically run on loading.;; Select a LINES or LIGHT WEIGHT POLYLINES on your drawing. Text; placed above the line will give the Bearing. Text placed; below the line gives the distance.; ; If you use inside a viewport from paperspace the routine will; automatically work out the scale factor. If you use in model; space you will be prompted for a scale factor.;; Bearing given is always between 0 - 180 deg irrespective of; the direction the line has been drawn in.;; Text is placed on the current layer using the default text; style. Text height is based on the text height for the; current dimension style.; ; To run the routine again type BD at the command line.;; NOTE in AutoCAD bearing gives a D instead of the degree symbol; in Bricscad you get the degree symbol.;; Requires : Nothing else;------------------------------------------------------------------------------; Rev no : A; Reason : First release; Rev Date : 20/Mar/2011; Rev by : Jason Bourhill; Email : jason@cadconcepts.co.nz;; Description:; First release.;------------------------------------------------------------------------------(defun C:BD ( / ASK GETDWGSCALE TEXTPOSITION LISTPLINEVER PLACETEXT sset num scalefac ent startpt endpt VerLst Ctr lstlen);ASK;This routine allows default prompt issuing(defun ASK (typ prmpt def / val vt) (setq vt (type def)) (cond ((null vt) (princ (strcat prmpt ": "))) ((= vt 'STR) (princ (strcat prmpt " <" def ">: "))) ((= typ 'ANG) (princ (strcat prmpt " <" (rtd def) ">: "))) ((= vt 'REAL) (princ (strcat prmpt " <" (rtos def 2 2) ">: "))) ((= vt 'INT) (princ (strcat prmpt " <" (itoa def) ">: "))) ) (cond ((= typ 'R) (setq val (getreal))) ((= typ 'S) (setq val (getkword))) ((= typ 'ANG) (setq val (getangle))) ((= typ 'DIST) (setq val (getdist))) ((= typ 'INT) (setq val (getint))) ((= typ 'STR) (setq val (getstring))) ((= typ 'STRT)(setq val (getstring T))) ) (if (or (= val "")(= val ())) def val)); find Drawing scale; if user is inside a paperspace vport will work out dwgscale automatically; if in paperspace set dwgscale = 1; if in modelspace as user for dwgscale value; Required as Bricscad doesn't support annotative text scaling(defun getdwgscale ( )(cond((and (= 0 (getvar "TILEMODE")) (= 1 (getvar "CVPORT"))) ; in paperspace not inside a vport (setq dwgscale 1))((and (= 0 (getvar "TILEMODE")) (> (getvar "CVPORT") 1)) ; in paperspace and inside a vport (setq dwgscale (/ 1.0 (caddr (trans '(0 0 1) 2 3)))))((= 1 (getvar "TILEMODE")) ; in modelspace, ask user for dwgscale (if (not dwgscale) (setq dwgscale 0.5)) ; if not set, set dwgscale to 1:2000 assumes modelspace is in metres, and paperspace is mm (setq dwgscale (ask 'R "Drawing scale factor 1= 1:100, 2 = 1:200, 3 = 1:500" dwgscale))) ) dwgscale ; return dwgscale value) ; end getdwgscale; Find and return the Text postion and angle value; adjusts position and angle based on which quadrant the angle falls in; Note internally Lisp uses radians, with 0 at East position and measures anticlockwise.(defun textposition (LineMpt Langle TextOff / TestPos Langle)(cond ((and (>= Langle 0 )(<= Langle (/ pi 2.0))) ; Langle between 0 - 90 degrees (setq TextPos (polar LineMpt (+ Langle (/ pi 2.0)) TextOff)) (setq Langle Langle) ) ((and (> Langle (/ pi 2.0))(<= Langle pi)) ; Langle between 90 - 180 degrees (setq TextPos (polar LineMpt (- Langle (/ pi 2.0)) TextOff)) (setq Langle (- Langle pi)) ) ((and (> Langle pi)(<= Langle (* pi 1.5))) ; Langle between 180 - 270 degrees