point position

Discussion in 'AutoCAD' started by felixlee, Nov 21, 2004.

  1. felixlee

    felixlee Guest

    I have written an autolisp scrip to do some slope analysis work. I have to determine the intersection of certain line and contours. I have already done the calculation. However, when I want to write the data to AUTOCAD, the position of my text was incorrect.
    Here is my code. Please help me to identify where the problem is.

    ps. My output data will be written on pt3, pt5 pt7 and pt8.
    Everytime I rotate the base line, the location of pt3, pt5 pt7 and pt8 will be different.

    (setq spacing (getint "\n Input distance of grid:"))
    (setq layer5m (getstring "\n Input the layer name of contour-5m:"))
    (setq layer1m (getstring "\n Input the layer name of contour-1m:"))
    (setq pt0 (getpoint "\n Input the left-bottom point"))
    (setq ptend (getpoint "\n Input the upper-right point"))
    (setq totallength (distance pt0 ptend))
    (setq tempangle (angle pt0 ptend))
    (setq oriangle (getangle "\n Input angle between base line:"))
    (command "layer" "n" "å¡åº¦åˆ†æž" "S" "å¡åº¦åˆ†æž" "")
    (setq tempangle1 (- tempangle oriangle))
    (setq mmmm (/ (* totallength (cos tempangle1)) spacing))
    (setq mm (fix mmmm))
    (setq nnnn (/ (* totallength (sin tempangle1)) spacing))
    (setq nn (fix nnnn))
    (if (= spacing 10) (setq fontheight 1.5))
    (if (= spacing 25) (setq fontheight 3.75))
    (setq n 0)
    (setq m 0)
    (setq radian (atan n m))
    (setq length1 (* (sqrt (+ (* n n) (* m m))) spacing))
    (setq INTH1 0)
    (setq VALUEINTH1 0)
    (setq INTV1 0)
    (setq VALUEINTV1 0)
    (setq INTH2 0)
    (setq VALUEINTH2 0)
    (setq INTV2 0)
    (setq VALUEINTV2 0)
    (setq VALUEINT 0)
    (setq pt1 (polar pt0 (+ radian oriangle) length1))
    (setq pt2 (polar pt1 oriangle spacing))
    (setq pt3 (polar pt1 oriangle (/ spacing 2)))
    (setq pt4 (polar pt1 (+ (/ pi 2) oriangle) spacing))
    (setq pt5 (polar pt1 (+ (/ pi 2) oriangle) (/ spacing 2)))
    (setq pt6 (polar pt4 oriangle spacing))
    (setq pt7 (polar pt4 oriangle (/ spacing 2)))
    (setq pt8 (polar pt2 (+ (/ pi 2) oriangle) (/ spacing 2)))
    (setq pt9 (polar pt3 (+ (/ pi 2) oriangle) (/ spacing 5)))
    (setq pt10 (polar pt3 (+ (/ pi 2) oriangle) (/ spacing 2.5)))
    (setq pt11 (polar pt3 (+ (/ pi 2) oriangle) (/ spacing 1.67)))
    (setq pt12 (polar pt3 (+ (/ pi 2) oriangle) (/ spacing 1.25)))
    (setq pt13 (polar pt1 (+ (atan 1) oriangle) 0.01))
    (setq pt14 (polar pt13 (+ (/ pi 2) oriangle) (- spacing 0.02)))
    (setq pt15 (polar pt14 oriangle (- spacing 0.02)))
    (setq pt16 (polar pt13 oriangle (- spacing 0.02)))
    (setq pt21 (polar pt1 oriangle (* spacing 0.25)))
    (setq pt22 (polar pt1 oriangle (* spacing 0.75)))
    (setq pt23 (polar pt1 (+ (/ pi 2) oriangle) (* spacing 0.25)))
    (setq pt24 (polar pt1 (+ (/ pi 2) oriangle) (* spacing 0.75)))
    (setq pt25 (polar pt4 oriangle (* spacing 0.25)))
    (setq pt26 (polar pt4 oriangle (* spacing 0.75)))
    (setq pt27 (polar pt2 (+ (/ pi 2) oriangle) (* spacing 0.25)))
    (setq pt28 (polar pt2 (+ (/ pi 2) oriangle) (* spacing 0.75)))
    (setq myfilter (list '(-4 . "<or") (cons 8 layer5m) (cons 8 layer1m) '(-4 . "or>") ))
    (setq INTH11 (ssget "F" (list pt1 pt21) myfilter ))
    (if (= INTH11 nil) (setq VALUEINTH11 0) (setq VALUEINTH11 (sslength INTH11)))
    (setq INTH12 (ssget "F" (list pt21 pt3) myfilter ))
    (if (= INTH12 nil) (setq VALUEINTH12 0) (setq VALUEINTH12 (sslength INTH12)))
    (setq INTH13 (ssget "F" (list pt3 pt22) myfilter ))
    (if (= INTH13 nil) (setq VALUEINTH13 0) (setq VALUEINTH13 (sslength INTH13)))
    (setq INTH14 (ssget "F" (list pt22 pt2) myfilter ))
    (if (= INTH14 nil) (setq VALUEINTH14 0) (setq VALUEINTH14 (sslength INTH14)))
    (setq VALUEINTH1 (+ VALUEINTH11 VALUEINTH12 VALUEINTH13 VALUEINTH14))
    (setq INTH21 (ssget "F" (list pt4 pt25) myfilter ))
    (if (= INTH21 nil) (setq VALUEINTH21 0) (setq VALUEINTH21 (sslength INTH21)))
    (setq INTH22 (ssget "F" (list pt25 pt7) myfilter ))
    (if (= INTH22 nil) (setq VALUEINTH22 0) (setq VALUEINTH22 (sslength INTH22)))
    (setq INTH23 (ssget "F" (list pt7 pt26) myfilter ))
    (if (= INTH23 nil) (setq VALUEINTH23 0) (setq VALUEINTH23 (sslength INTH23)))
    (setq INTH24 (ssget "F" (list pt26 pt6) myfilter ))
    (if (= INTH24 nil) (setq VALUEINTH24 0) (setq VALUEINTH24 (sslength INTH24)))
    (setq VALUEINTH2 (+ VALUEINTH21 VALUEINTH22 VALUEINTH23 VALUEINTH24))
    (setq INTV11 (ssget "F" (list pt1 pt23) myfilter ))
    (if (= INTV11 nil) (setq VALUEINTV11 0) (setq VALUEINTV11 (sslength INTV11)))
    (setq INTV12 (ssget "F" (list pt23 pt5) myfilter ))
    (if (= INTV12 nil) (setq VALUEINTV12 0) (setq VALUEINTV12 (sslength INTV12)))
    (setq INTV13 (ssget "F" (list pt5 pt24) myfilter ))
    (if (= INTV13 nil) (setq VALUEINTV13 0) (setq VALUEINTV13 (sslength INTV13)))
    (setq INTV14 (ssget "F" (list pt24 pt4) myfilter ))
    (if (= INTV14 nil) (setq VALUEINTV14 0) (setq VALUEINTV14 (sslength INTV14)))
    (setq VALUEINTV1 (+ VALUEINTV11 VALUEINTV12 VALUEINTV13 VALUEINTV14))
    (setq INTV21 (ssget "F" (list pt2 pt27) myfilter ))
    (if (= INTV21 nil) (setq VALUEINTV21 0) (setq VALUEINTV21 (sslength INTV21)))
    (setq INTV22 (ssget "F" (list pt27 pt8) myfilter ))
    (if (= INTV22 nil) (setq VALUEINTV22 0) (setq VALUEINTV22 (sslength INTV22)))
    (setq INTV23 (ssget "F" (list pt8 pt28) myfilter ))
    (if (= INTV23 nil) (setq VALUEINTV23 0) (setq VALUEINTV23 (sslength INTV23)))
    (setq INTV24 (ssget "F" (list pt28 pt6) myfilter ))
    (if (= INTV24 nil) (setq VALUEINTV24 0) (setq VALUEINTV24 (sslength INTV24)))
    (setq VALUEINTV2 (+ VALUEINTV21 VALUEINTV22 VALUEINTV23 VALUEINTV24))
    (setq VALUEINT (+ VALUEINTH1 VALUEINTH2 VALUEINTV1 VALUEINTV2))
    (setq oriangledegree (* (/ oriangle pi) 180))
    (command "text" "j" "mc" pt3 fontheight oriangledegree VALUEINTH1)
    (command "text" "j" "mc" pt5 fontheight oriangledegree VALUEINTV1)
    (command "text" "j" "mc" pt7 fontheight oriangledegree VALUEINTH2)
    (command "text" "j" "mc" pt8 fontheight oriangledegree VALUEINTV2)
    (setq INTOFBOUND (ssget "F" (list pt13 pt14 pt15 pt16 pt13) '((8 . "邊界"))))
    (if (= INTOFBOUND nil) ()
    (progn (command "layer" "off" "*" "y" "")
    ;(if (= T (<= m (/ mm 2)) (<= n (/ nn 2))) (setq pt17 pt15))
    ;(if (= T (<= m (/ mm 2)) (>= n (/ nn 2))) (setq pt17 pt16))
    ;(if (= T (>= m (/ mm 2)) (>= n (/ nn 2))) (setq pt17 pt13))
    ;(if (= T (>= m (/ mm 2)) (<= n (/ nn 2))) (setq pt17 pt14))
    (setq pt17 pt10)
    (command "layer" "S" "å¡åº¦åˆ†æž" "on" "å¡åº¦åˆ†æž" "")
    (command "layer" "on" "邊界" "on" "方格" "")
    (command "boundary" pt17 "")
    (command "area" "o" "l")
    (setq ans_area (getvar "area"))
    (setq areaamount (strcat (rtos ans_area 2 2) "㎡"))
    (command "text" "j" "mc" pt9 (* fontheight 0.8) oriangledegree areaamount)
    ;(command "text" "j" "mc" pt10 fontheight oriangledegree slopegrade)

    ;(command "text" "j" "c" pt11 fontheight oriangledegree slopeaverage)
    (setq char (+ m 65))
    (if (> char 91) (setq char2 (- char 26)) (setq char2 0))
    (if (< char2 91) (setq row (strcat "A" (chr char2) (itoa n) "(" (itoa VALUEINT) ")")))
    (if (< char 91) (setq row (strcat (chr char) (itoa n) "(" (itoa VALUEINT) ")")))
    (command "text" "j" "mc" pt12 (* fontheight 1.2) oriangledegree row)
    (command "layer" "on" "*" "")
    ) ;progn之下括號
    ) ;(if (= INTOFBOUND nil) ()之下括號
    ;)
    ;)
     
    felixlee, Nov 21, 2004
    #1
  2. felixlee

    John Uhden Guest

    Perhaps your OSMODE is set to some snap.
    Try changing your text commands to add the _non override...
    (command "text" "j" "mc" "_non" pt3 fontheight oriangledegree VALUEINTH1)





    determine the intersection of certain line and contours. I have already done the
    calculation. However, when I want to write the data to AUTOCAD, the position of
    my text was incorrect.
     
    John Uhden, Nov 21, 2004
    #2
  3. felixlee

    felixlee Guest

    Thanks, John.
    You are absolutely right. This is what I want.
     
    felixlee, Nov 21, 2004
    #3
  4. felixlee

    John Uhden Guest

    You're very welcomed.
     
    John Uhden, Nov 21, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.