;::: Boltholes ;;;; Copyright 2005 by Daniel Abbott ;;;; Southern Maine Community College ;;;; ;;;; Permission to use, copy, modify, and distribute this software ;;;; for any purpose and without fee is hereby granted, provided ;;;; that the above copyright notice appears in all copies and ;;;; that both that copyright notice and the limited warranty and ;;;; restricted rights notice below appear in all supporting ;;;; documentation. ;;;; ;;;; I PROVIDE THIS PROGRAM "AS IS" AND WITH ALL FAULTS. ;;;; I SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTY OF ;;;; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. I DO ;;;; DO NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE ;;;; UNINTERRUPTED OR ERROR FREE. ;;; "Bolt" command will place boltholes based on user input. ;;; "CC" command will place circular centerlines that are scaled to current viewport ;;; based on the setting for "dimcen." If in model space, or in a layout but not in ;;; a viewport, setting for "dimcen" will be used to determine size of centermark. ;;; Crosshair consists of two arcs. ;;error trap (defun daet (message) ;names error trapping function (command "undo" "end") (command "undo" "b") ;restores drawing to mark set at beginning of program ;in some cases, this will not work, so following lines ;will restore specific variables to original (setvar "osmode" os) ;restores variables that are changed in program (setvar "clayer" cl) (setq *error* temperr) ;restore *error* (prompt "\nResetting System Variables ") ;inform user (princ) ) (defun c:bolt (/ cl os p1 p2 nu o1) (setq temperr *error*) ;store *error* (setq *error* daet) ;re-assign *error* (command "undo" "m") (command "undo" "be") (command "layer" "n" "obj" "c" "white" "obj" "lw" ".4" "obj" "") (setq cl (getvar "clayer") os (getvar "osmode") p1 (getpoint "\nCenterpoint of circular pattern:") p2 (getpoint "\nCenterpoint of any bolt hole: " p1) d1 (getdist "\nDiameter of bolthole: ") nu (getint "\Number of bolt holes in pattern: ") ) (setvar "osmode" 0) (setvar "clayer" "obj") (command "circle" p2 "d" d1) (setq o1 (entlast)) (command "array" o1 "" "p" p1 nu "" "") (setvar "osmode" os) (setvar "clayer" cl) (command "undo" "end") (princ) ) ; Centerlines (defun c:cc (/ tm size cvp vhms ss1 entlist vhps ps cl os p1 p2 d1 r1 a1 a2 nu start1 end1 start2 end2 start3 end3 o2 o3 o4 o5 o6 o7 o8 o9 end4 end5 ) (setq temperr *error*) ;store *error* (setq *error* daet) ;re-assign *error* (command "undo" "m") (command "undo" "be") (command "layer" "n" "obj,cen" "c" "white" "obj" "c" "red" "cen" "l" "center2" "cen" "" ) (setq tm (getvar "tilemode")) (if (= tm 1) (setq size (abs (getvar "dimcen"))) (setq size (abs (getvar "dimcen")) ;gets absolute value of dimcen cvp (getvar "cvport") ;gets the number of the current viewport vhms (getvar "viewsize") ;gets the model space height of cvport ss1 (ssget "X" (list '(0 . "viewport") (cons 69 cvp))) ;creates a selection set of cvport entlist (entget (ssname ss1 0)) ;creates a list of properties for the cvport vhps (cdr (assoc 41 entlist)) ;gets the paper space height of cvport ps (/ vhms vhps) ;sets ps to the ratio between the ms size and ps size size (* ps size) ;multiplies ps {reciprocal of scale factor} times dimcen ) ) (prompt "Select a bolt hole: ") (if (/= d1 nil) (setq d1 d1) (setq d1 (* 2 (cdr (assoc 40 (entget (car (entsel))))))) ) (abs (getvar "dimcen")) (setq cl (getvar "clayer") os (getvar "osmode") p1 (getpoint "\nCenterpoint of circular pattern:") p2 (getpoint "\nCenterpoint of first bolt hole: " p1) ;d1 (getdist "\nDiameter of bolthole: ") r1 (distance p1 p2) a1 (angle p1 p2) a2 (angle p2 p1) nu (getint "\nNumber of bolt holes in pattern: ") start1 (polar p1 a1 (* size 2)) end1 (polar p2 a2 (* size 2)) start2 (polar end1 a1 size) end2 (polar start2 a1 (* size 2)) start3 (polar end2 a1 size) end3 (polar start3 a1 (- (/ d1 2) size)) ) (setvar "osmode" 0) ;(setvar "clayer" "obj") ;(command "circle" p2 "d" d1) ;(setq o1 (entlast)) (setvar "clayer" "cen") (command "line" start1 end1 "") (setq o2 (entlast)) (command "line" start2 end2 "") (setq o3 (entlast)) (command "line" start3 end3 "") (setq o4 (entlast)) (setq end4 (polar p2 (+ (angle p1 p2) (/ pi 2)) size)) (command "arc" "c" p1 p2 end4) (setq o5 (entlast)) (command "mirror" o5 "" p1 p2 "n") (setq o6 (entlast)) (command "circle" p2 (* size 2)) (setq o7 (entlast)) (command "array" o7 "" "p" p1 2 (/ 360 nu) "") (setq o8 (entlast)) (setq end5 (polar p1 (+ (angle p1 p2) (/ (* 2 pi) nu)) r1)) (command "arc" "c" p1 "end" end4 end5 "trim" o7 o8 "" end4 end5 "") (setq o9 (entlast)) (command "erase" o7 o8 "") (command "array" o2 o3 o4 o5 o6 o9 "" "p" p1 nu "" "") (command "undo" "end") (setvar "osmode" os) (setvar "clayer" cl) (princ) )