Author Topic: Trying to improve this code  (Read 1725 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Trying to improve this code
« on: August 15, 2014, 08:30:57 AM »
The following code was created by a fellow employee a few years back and works fine.
The routine creates an arc with arrowheads on each end of the arc, using dimscale (and other settings) of a selected dimension. It then, allows the user to select the center point of the arc, location of view name, then type in the view name. All this is placed on a layer called "section" and uses  section linetype.
However there are times when the diameter of the arc is too small, causing the routine to bomb out and leaves the drawing with two circles on layer "0".
I have tried several times over the last year or two (when time allows) to modify the routine to allow for smaller circles and all I do is get lost in this busy code. We really like how "amdetail" works in mechanical but we just use the vanilla profile (a desicision from the higher ups).  So bottom line.........I've searched the internet for a better method and have found nothing. Anyone out there have any ideas. Would appreciate the help.
Thank you.

Code: [Select]
(defun C:DETL
         (/ ANG02    ANG021   ANG022    CLAY    CORM    COSM
            DETN      DSCL      PNT01       PNT02  PNT021  PNT022
           PNT023    PNT024  RAD01       RAD02  RAD03    LTSC
         )
                 ; DEFINE VARIABLES
                 ; ANG02 = ANGLE, PNT01 TO PNT02
                 ; CLAY = CURRENT LAYER
                 ; CORM = CURRENT ORTHO MODE
                 ; COSM = CURRENT OSNAP MODE
                 ; DETN = DETAIL NAME
                 ; DSCL = DIMSCALE
                 ; PNT01 = CENTER OF VIEW CIRCLE
                 ; PNT02 = LOCATION OF VIEW NAME
                 ; RAD01 = DISTANCE, PNT01 TO PNT02
                 ; RAD02 = DIMSCALE TIMES DETAIL ARROWHEAD SIZE
                 ; RAD03 = DIMSCALE TIMES TEXT HIGHT
                 ; LTSC = LTSCALE

  (setq   CLAY (getvar "CLAYER")
            CORM (getvar "ORTHOMODE")
            COSM (getvar "OSMODE")
            DSCL (getvar "DIMSCALE")
            LTSC (getvar "LTSCALE")
  )
  (setvar "CMDECHO" 0)

(setq BOB (entsel "Select Desired Dimstyle..." ))
   (command "-DIMSTYLE" "R" BOB "")

  (command "._-LAYER" "_NEW" "SECTION" "_COLOR" 230 "SECTION" "_LTYPE" "PHANTOM" "SECTION" "")
  (setvar "ORTHOMODE" 0)
  (setvar "OSMODE" 0)

  (setq    PNT01 (getpoint "\nPick center of View Circle: ")
             PNT02 (getpoint PNT01 "\nPick location of View Name: ")
             DETN  (getstring 2 "\nDetail Name? ")
             ANG02 (angle PNT01 PNT02)
             RAD01 (distance PNT01 PNT02)
         ;;;    RAD02 (* DSCL 0.140625)
             RAD02 (* DSCL 0.08)
             RAD03 (* DSCL 0.09375)

  )
  (command "._LAYER" "_SET" "0" "" "._CIRCLE" PNT01 PNT02 "._CIRCLE" PNT02 RAD02)

       ;;   Set layer to 0 and draw the detail circle and a circle on the
       ;; circumference of the detail circle having a radius equal to 1.5
       ;; times the standard character hite (i.e., 9/64").  Record points,
       ;; angles, & distances involved.

  (setq    PNT021 (polar PNT02 (+ ANG02 (* pi 0.5)) RAD02)
             PNT021 (osnap PNT021 "APP")
             ANG021 (angle PNT01 PNT021)
             PNT022 (polar PNT02 (+ ANG02 (* pi 1.5)) RAD02)
             PNT022 (osnap PNT022 "APP")
             ANG022 (angle PNT01 PNT022)
  )
  ;; Get both points where the two circles intersect, & record the points
  ;; and the angles relative to the center of the large circle.
 
(command "._MOVE" "_LAST" "" PNT02 PNT021)

  (setq    PNT023 (polar PNT021 (+ ANG021 (* pi 0.5)) RAD02)
              PNT023 (osnap PNT023 "APP")
  )
  ;;   Shift the small circle counterclockwise one character height &
  ;; determine where one of the arrowheads will end

  (command "._MOVE" "_LAST" "" PNT021 PNT022)

  (setq    PNT024 (polar PNT022 (+ ANG022 (* pi 1.5)) RAD02)
             PNT024 (osnap PNT024 "APP")
  )

  ;; then shift it two character hights clockwise & get the endpoint
  ;; of the other arrowhead.

 (command "._ERASE" "_LAST" ""
                   "._CIRCLE" PNT02 PNT023
                   "._TRIM" "_LAST" "" PNT02 ""
                   "._ERASE" "_PREVIOUS" ""
;;;;   "._PEDIT" "LAST" "YES" ""
                   "._CHANGE" "_LAST" "" "_PROPERTIES" "_LAYER" "SECTION" ""
                   "._LAYER" "SET" "SECTION" ""
;                "._PLINE" PNT021 "_WIDTH" 0.0 (* RAD02 0.38196601) PNT023 ""
                   "._PLINE" PNT021 "_WIDTH" 0.0 (* RAD02 0.333511111) PNT023 ""
                   "._MIRROR" "_LAST" "" PNT01 PNT02 "_NO"
                   ".-STYLE" "STANDARD" "ROMANS" "0" "1" "0" "N" "N" "N"
                   "._TEXT" "MC" PNT02 RAD03 0.0 (strcase DETN)
                   "._LAYER" "_SET" CLAY "")                  ;
  (princ)
)

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Trying to improve this code
« Reply #1 on: August 15, 2014, 09:01:42 AM »
I know it's not what you are after, but first thing that comes to my mind is this lisp :

http://www.lee-mac.com/arrowarc.html

Very neat, Lee...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Trying to improve this code
« Reply #2 on: August 15, 2014, 09:27:10 AM »
Kool routine. Just not close enough. Thanks for the reply.

hanhphuc

  • Newt
  • Posts: 64
Re: Trying to improve this code
« Reply #3 on: August 15, 2014, 08:43:35 PM »
hi can you attach an example image just i'm not mechanical, i think i got almost similar dov.lsp &dcl but i'm not sure is it same?
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Trying to improve this code
« Reply #4 on: August 18, 2014, 12:06:28 PM »
Here's an image. May have fixed it, but needs more testing.