Author Topic: UCS Help  (Read 1860 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
UCS Help
« on: July 08, 2010, 11:25:56 AM »
This is really bugging me now, because I cannot seem to get it to work (just when I thought I'd mastered trans...)

A simple code just to draw an elevation marker, but I cannot get it to work in all views/ucs's

Any help is much appreciated:

Code: [Select]
(defun c:ellev ( / *error* Line Text OFFSET OLDDIM P1 P2 PT TSZE X Y Z )
  ;; Lee Mac 2010

  (setq offset 1.5) ;; Text Offset

  (defun *error* ( msg )
    (and oldDim (setvar 'DIMZIN oldDim))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun Line ( p1 p2 norm )
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 p1)
        (cons 11 p2)
        (cons 210 norm)
      )
    )
  )

  (defun Text ( pt hgt str norm )
    (entmakex
      (list
        (cons 0 "TEXT")
        (cons 10  pt)
        (cons 40 hgt)
        (cons 1  str)
        (cons 50 (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))
        (cons 7  (getvar 'TEXTSTYLE))
        (cons 72 1) ; Center
        (cons 73 2) ; Middle
        (cons 11 pt)
        (cons 210 norm)
      )
    )
  )

  (setq oldDim (getvar 'DIMZIN))
  (setvar 'DIMZIN 0)
 
  (or *scl (setq *scl 100))

  (initget 6)
  (setq *scl
    (cond
      ( (getint (strcat "\nEnter Drawing Scale <" (itoa *scl) "> : ")) )
      ( *scl )
    )
  )

  (setq tsze (* 0.002 *scl))

  (setq norm (trans '(0. 0. 1.) 1 0 t))

  (terpri)
  (while (setq pt (getpoint "\rPick Elevation Line Point: "))

    (setq pt (trans pt 1 norm)) ; UCS->WCS
   
    (setq x (car pt) y (cadr pt) z (caddr pt))

    (setq p1 (list (- x (/ tsze 2)) (+ y tsze) z)
          p2 (list (+ x (/ tsze 2)) (+ y tsze) z))

    (mapcar (function (lambda ( x ) (line pt x norm))) (list p1 p2))
    (line p1 p2 norm)

    (Text
      (list x (+ y (* offset tsze)) z)
      tsze
      (strcat (if (<= 0 y) "+" "") (rtos y 2 2) "m")
      norm
    )
  )

  (setvar 'DIMZIN oldDim)
  (princ)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UCS Help
« Reply #1 on: July 08, 2010, 12:10:20 PM »
When you use entmake, don't you want your points to be in WCS?  Then you apply the normal to the entity?  If so, then just trans your points like

(setq pt (trans pt 1 0))
Tim

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

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: UCS Help
« Reply #2 on: July 08, 2010, 12:46:28 PM »
Hi Lee,

I'm not sur to understan what the goal is but looking at your code, I can say:
(trans '(0. 0. 1.) 1 0 T) returns the normal vector of the current UCS defined in WCS coordinates. This is to be used with the 210 DXF code (or Normal COM property) to creates entities on the current UCS. It have to be used only with entities wich requires OCS coordinates (arc circle lwpolyline text ...)

You need to care of this normal for lines which are considered as 3d entities and have always their coordinates defines in WCS.
But you must use it for texts.

So here's a little corection of your code, but I don't know what you're expecting withe the triangle you draw

Code: [Select]
(defun c:ellev ( / *error* Line Text OFFSET OLDDIM P1 P2 PT TSZE X Y Z )
  ;; Lee Mac 2010

  (setq offset 1.5) ;; Text Offset

  (defun *error* ( msg )
    (and oldDim (setvar 'DIMZIN oldDim))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun Line ( p1 p2 )
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 p1)
        (cons 11 p2)
      )
    )
  )

  (defun Text ( pt hgt str norm )
    (entmakex
      (list
        (cons 0 "TEXT")
        (cons 10  pt)
        (cons 40 hgt)
        (cons 1  str)
        (cons 50 (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))
        (cons 7  (getvar 'TEXTSTYLE))
        (cons 72 1) ; Center
        (cons 73 2) ; Middle
        (cons 11 pt)
        (cons 210 norm)
      )
    )
  )

  (setq oldDim (getvar 'DIMZIN))
  (setvar 'DIMZIN 0)
 
  (or *scl (setq *scl 100))

  (initget 6)
  (setq *scl
    (cond
      ( (getint (strcat "\nEnter Drawing Scale <" (itoa *scl) "> : ")) )
      ( *scl )
    )
  )

  (setq tsze (* 0.002 *scl))

  (setq norm (trans '(0. 0. 1.) 1 0 t))

  (terpri)
  (while (setq pt (getpoint "\rPick Elevation Line Point: "))

    (setq pt (trans pt 1 0)) ; UCS->WCS
   
    (setq x (car pt) y (cadr pt) z (caddr pt))

    (setq p1 (list (- x (/ tsze 2)) (+ y tsze) z)
          p2 (list (+ x (/ tsze 2)) (+ y tsze) z))

    (mapcar (function (lambda ( x ) (line pt x))) (list p1 p2))
    (line p1 p2)

    (setq pt (trans pt 0 norm) x (car pt) y (cadr pt) z (caddr pt))

    (Text
      (list x (+ y (* offset tsze)) z)
      tsze
      (strcat (if (<= 0 y) "+" "") (rtos y 2 2) "m")
      norm
    )
  )

  (setvar 'DIMZIN oldDim)
  (princ)
)
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: UCS Help
« Reply #3 on: July 08, 2010, 12:54:46 PM »
Hi Gile,

Firstly, many thanks for your time.

I didn't realise that the normal property was not needed for lines - thanks for that.

The desired result is to have a downwards pointing triangle, but at this point I may rewrite the code to use an LWPolyline, instead of three lines.

I shall get back to you on this  :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: UCS Help
« Reply #4 on: July 08, 2010, 01:20:54 PM »
Ok, so I'm going to use an LWPolyline instead. :-)

But things are still not quite there with the UCS.

I first tried converting the Point from UCS -> WCS as per your post Gile, but this didn't work too well with a rotated UCS.

So then I tried calculating the triangle point position relative to each other in UCS, then converting to WCS - but, although this works in a rotated UCS, it fails in different views... I cannot seem to win :-(

Code: [Select]
(defun c:ellev ( / *error* LWPoly Text oldDim tsze norm pt str ref )
  ;; Lee Mac 2010

  (setq offset 1.6) ;; Text Offset

  (defun *error* ( msg )
    (and oldDim (setvar 'DIMZIN oldDim))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )
 
  (defun LWPoly ( lst cls norm )
    (entmakex
      (append
        (list
          (cons 0 "LWPOLYLINE")
          (cons 100 "AcDbEntity")
          (cons 100 "AcDbPolyline")
          (cons 90 (length lst))
          (cons 70 cls)
          (cons 210 norm)
        )
        (mapcar '(lambda ( p ) (cons 10 p)) lst)
      )
    )
  )

  (defun Text ( pt hgt str norm )
    (entmakex
      (list
        (cons 0 "TEXT")
        (cons 10  pt)
        (cons 40 hgt)
        (cons 1  str)
        (cons 50 (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))
        (cons 7  (getvar 'TEXTSTYLE))
        (cons 72 1) ; Center
        (cons 73 2) ; Middle
        (cons 11 pt)
        (cons 210 norm)
      )
    )
  )

  (setq oldDim (getvar 'DIMZIN))
  (setvar 'DIMZIN 0)
 
  (or *scl (setq *scl 100))

  (initget 6)
  (setq *scl
    (cond
      ( (getint (strcat "\nEnter Drawing Scale <" (itoa *scl) "> : ")) )
      ( *scl )
    )
  )

  (setq tsze (* 0.002 *scl))

  (setq norm (trans '(0. 0. 1.) 1 0 t))

  (terpri)
  (while (setq pt (getpoint "\rPick Elevation Line Point: "))

    (setq str (strcat (if (<= 0 (cadr pt)) "+" "") (rtos (cadr pt) 2 2))
      )
           ;pt (trans pt 1 0)) ; UCS->WCS

    (setq ref (polar pt (/ pi 2.) tsze))

    (LWPoly
      (mapcar '(lambda ( x ) (trans x 1 0))
        (list pt (polar ref 0 (/ tsze 2.)) (polar ref pi (/ tsze 2.)))
      )
      1 norm
    )

    (Text (trans (polar pt (/ pi 2.) (* offset tsze)) 1 0) tsze str norm)
  )

  (setvar 'DIMZIN oldDim)
  (princ)
)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: UCS Help
« Reply #5 on: July 08, 2010, 01:48:03 PM »
As for text, lwpolyline vertices have to be defined in OCS.

Is that you're looking for ?

Code: [Select]
(defun c:ellev ( / *error* Text OFFSET OLDDIM P1 P2 PT TSZE X Y Z )
  ;; Lee Mac 2010

  (setq offset 1.5) ;; Text Offset

  (defun *error* ( msg )
    (and oldDim (setvar 'DIMZIN oldDim))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun Text ( pt hgt str rot norm )
    (entmakex
      (list
        (cons 0 "TEXT")
        (cons 10  pt)
        (cons 40 hgt)
        (cons 1  str)
        (cons 50 rot)
        (cons 7  (getvar 'TEXTSTYLE))
        (cons 72 1) ; Center
        (cons 73 2) ; Middle
        (cons 11 pt)
        (cons 210 norm)
      )
    )
  )

  (setq oldDim (getvar 'DIMZIN))
  (setvar 'DIMZIN 0)
 
  (or *scl (setq *scl 100))

  (initget 6)
  (setq *scl
    (cond
      ( (getint (strcat "\nEnter Drawing Scale <" (itoa *scl) "> : ")) )
      ( *scl )
    )
  )

  (setq tsze (* 0.002 *scl))

  (setq norm (trans '(0. 0. 1.) 1 0 t))

  (setq rot (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))

  (terpri)
  (while (setq pt (getpoint "\rPick Elevation Line Point: "))

    (setq txt (strcat (if (<= 0 (cadr pt)) "+" "") (rtos (cadr pt) 2 2) "m"))

    (setq pt (trans pt 1 norm)) ; UCS->OCS
   
    (setq x (car pt) y (cadr pt) z (caddr pt))

    (setq p1 (polar pt (+ rot (/ pi 3)) tsze)
          p2 (polar pt (+ rot (/ (* 2 pi) 3)) tsze))
   
    (entmakex
      (list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 3)
'(70 . 1)
(cons 38 z)
(cons 10 pt)
(cons 10 p1)
(cons 10 p2)
(cons 210 norm)
)
      )

    (Text
      (list x (+ y (* offset tsze)) z)
      tsze
      txt
      rot
      norm
    )
  )

  (setvar 'DIMZIN oldDim)
  (princ)
)
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: UCS Help
« Reply #6 on: July 08, 2010, 01:51:25 PM »
Perfect Gile!

I can see where I was getting confused: am I correct in saying that lines are defined in WCS, but entities such as Text/LWpolylines etc are defined in OCS?

No wonder I was getting confused!

Many thanks mate for your patience.

LE3

  • Guest
Re: UCS Help
« Reply #7 on: July 08, 2010, 02:22:39 PM »
Told to my self don't get in lisp trouble again... but well

I tried and no workie here, i drew a box and then went into setting the ucs to each of the faces and it does the alignment but some times the pline is above of the text or does that effect.

Have done a lot of miserable transformations... but using the miserable arx matrix classes...nothing todo here I know