Author Topic: Question regarding this LISP routine  (Read 1986 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Question regarding this LISP routine
« on: December 12, 2006, 10:44:05 AM »
Using ACAD2002 (for now)

This routine works in modelspace when we create our typical 2D drawings. This creates a detail bubble using a section linetype with arrowheads and text.

Quote
(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)
  (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)
             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 hight &
  ;; 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 ""
                   "._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)
)

Now we've come out of the dark ages. We are beginning to use paperspace, layout tabs, viewports, etc.

Problem were having now is that this routine bombs out in paperspace and leaves the following message:

Quote
Command: (if (not DETL.LSP) (load "DETL.lsp"))
C:DETL

Command: DETL

Layer "SECTION" already exists.

Pick center of View Circle:
Pick location of View Name:
Detail Name? A
; error: bad argument type: 2D/3D point: nil


Any ideas how to correct this?

Thanks

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Question regarding this LISP routine
« Reply #1 on: December 12, 2006, 11:04:37 AM »
It works in both model space, and paper space on my computer.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Question regarding this LISP routine
« Reply #2 on: December 12, 2006, 11:47:24 AM »
Well this is close but I don't have time to complete it.
Code: [Select]
(defun C:DETL
              (/       ANG02   ANG021  ANG022  CLAY    CORM    COSM    DETN
               DSCL    PNT01   PNT02   PNT021  PNT022  PNT023  PNT024  RAD01
               RAD02   RAD03   LTSC  arw r2 r3
              )
     ; 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")
  )

  ;;  CAB added vara
(setq arw 0.38196601
      r2  0.140625
      r3  0.09375
)
(if (and (/= (getvar "TileMode") 1)
        (= (getvar "cvport") 1) ; in an active viewport
        (/= ltsc 1.0)
    )
    (setq ltsc (/ ltsc 10)
      arw (/ arw ltsc)
      r2  (/ r2 ltsc)
      r3  (/ r3 ltsc)
      DSCL (/ DSCL ltsc)
    )
)



 
  (setvar "CMDECHO" 0)
  (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 r2)
        RAD03 (* DSCL r3)

  )
  (command "._LAYER" "_SET" "0" ""
           "._CIRCLE" PNT01 PNT02)
  (command
           "._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 hight &
  ;; 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 arw) 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 "")
 
  (setvar "OSMODE" COSM)
  (setvar "CLAYER" CLAY)
  (setvar "ORTHOMODE" CORM)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Question regarding this LISP routine
« Reply #3 on: December 13, 2006, 01:19:41 PM »
Thanks CAB.

Some minor tweaking and got it to work great.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Question regarding this LISP routine
« Reply #4 on: December 13, 2006, 02:08:36 PM »
That's good the hear. Just wish I had more time. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.