Author Topic: Where is error ?  (Read 1497 times)

0 Members and 1 Guest are viewing this topic.

new_mem

  • Newt
  • Posts: 67
Where is error ?
« on: March 04, 2017, 08:19:35 PM »
Hello all,

i had modify search code of Gile coordinates of subentities this forum for LWPolyline. In my case block error. Pls tell me where ? Thanks.

Code: [Select]
;; Entmatrix
; Returns a list which first item is the 3X3 tranformation matrix and second item
; the insertion point of a block refernce in its owner (space or block definition)
(defun entmatrix (ename / elst ang norm)
  (setq elst (entget ename)
ang  (cdr (assoc 50 elst))
norm (cdr (assoc 210 elst))
  )
  (list
    (mxm
      (mapcar (function (lambda (v) (trans v 0 norm t)))
      '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
      )
      (mxm
(list (list (cos ang) (- (sin ang)) 0.0)
      (list (sin ang) (cos ang) 0.0)
      '(0.0 0.0 1.0)
)
(list (list (cdr (assoc 41 elst)) 0.0 0.0)
      (list 0.0 (cdr (assoc 42 elst)) 0.0)
      (list 0.0 0.0 (cdr (assoc 43 elst)))
)
      )
    )
    (trans (cdr (assoc 10 elst)) norm 0)
  )
)

;; Blk2Coord
; Returns a list of a block reference entities coordinates
(defun blk2coord (ref mat ins / blk ent lst)
  (setq blk (tblsearch "BLOCK" (cdr (assoc 2 (entget ref)))))
  (setq ent (cdr (assoc -2 blk)))
  (while ent
    (setq elst (entget ent)
  typ  (cdr (assoc 0 elst))
    )
    (cond
      ((= "LINE" typ)
       (setq lst
      (cons (list typ
  (mapcar '+ ins (mxv mat (cdr (assoc 10 elst))))
  (mapcar '+ ins (mxv mat (cdr (assoc 11 elst))))
    )
    lst
      )
       )
      )
      ((= "LWPOLYLINE" typ)
       (setq lst
      (cons
(list
  typ
  (mapcar
    '(lambda (p) (mapcar '+ ins (mxv mat p)))
    (mapcar '(lambda (aa) (append aa (list 0.)))
    (mapcar 'cdr (vl-remove-if-not '(lambda (x) (eq (car x) 10)) elst)
    )
    )
    )
)
lst
      )
       )
      )
      ((member typ '("POINT" "TEXT"))
       (setq lst
      (cons (list typ
  (mapcar '+ ins (mxv mat (cdr (assoc 10 elst))))
    )
    lst
      )
       )
      )
      ((= "INSERT" typ)
       (setq nent (entmatrix ent))
       (setq lst
      (append
lst
(blk2coord ent
   (mxm mat (car nent))
   (mapcar '+ ins (mxv mat (cadr nent)))
)
      )
       )
      )
      (t nil)
    )
    (setq ent (entnext ent))
  )
  (cons (list (cdr (assoc 2 blk)) ins) lst)
)

;; Transpose a matrix Doug Wilson
(defun trp (m)
  (apply 'mapcar (cons 'list m))
)

;; Apply a transformation matrix to a vector by Vladimir Nesterovsky
(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v))))
  m
  )
)

;; Multiply two matrices by Vladimir Nesterovsky
(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

;; Main function

(defun c:test (/ ss n ent mtx lst)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (repeat (setq n (sslength ss))
      (setq ent (ssname ss (setq n (1- n)))
    mtx (entmatrix ent)
    lst (append (blk2coord ent (car mtx) (cadr mtx)) lst)
      )
    )
  )
  (mapcar 'print lst)
  (textscr)
  (princ)
)

Chris

  • Swamp Rat
  • Posts: 548
Re: Where is error ?
« Reply #1 on: March 04, 2017, 10:27:49 PM »
You can use VLIDE to find out where errors are in the programming.  Using break on error will allow the program to stop and if you hit control f9 it will highlight the error section.   You can also use VLIDE to verify there are no errors in your syntax, such as missing ().
There is a list of error messages and what they mean floating around somewhere.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

new_mem

  • Newt
  • Posts: 67
Re: Where is error ?
« Reply #2 on: March 04, 2017, 10:33:59 PM »
Thanks for repply.

I used VLIDE check and no error code.

Problem is lisp not return true coordinates LW WCS in dwg attached. If i creat new block then lisp return true.

Why ????
« Last Edit: March 04, 2017, 10:45:29 PM by new_mem »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Where is error ?
« Reply #3 on: March 05, 2017, 03:12:46 AM »
Why ????
The "GE_Nha_cua3" block definition has an origin property that is not '(0.0 0.0 0.0).

new_mem

  • Newt
  • Posts: 67
Re: Where is error ?
« Reply #4 on: March 05, 2017, 06:04:03 AM »
Ahhhhh,

Ok thank you so much.