Author Topic: Need fresh eyes to check this lisp  (Read 1435 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Need fresh eyes to check this lisp
« on: April 15, 2014, 07:42:18 AM »
Could a fresh eyes check this subroutine why stop working in this part
Code: [Select]
  (command "MASSPROP" obj "" "Y" wPath)
Code: [Select]
(defun C:CEN ( / doc index obj objects objlay objlist objtype )
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (LM:startundo doc)

  ;(setq obj (getpoint "Pick inside closed area"))
 

  (setq objects (ssget '((-4 . "<OR")(0 . "LWPOLYLINE")(0 . "REGION")(-4 . "OR>")))
obj (ssname objects 0))
  (while obj
    (setq objlist (entget obj))
    (setq objtype (cdr (assoc 0 objlist)))
    (setq objlay  (cdr (assoc 8 objlist)))
    (cond
     ((and (= objtype "LWPOLYLINE") (= (cdr (assoc 70 objlist)) 1)) (command "REGION" obj "") (setq obj (entlast)) (get_centroid_point))
     ((= objtype "REGION") (get_centroid_point)))
    (setq index (+ index 1)
            obj (ssname objects index))
    )
    (LM:endundo doc)
  (princ)
    (princ "\n       q_|_|| _\\|| q_|| _\\|      ")
  (princ "\n  Type  CEN  to invoke the lisp")
  )

(defun get_centroid_point (/ wpath open-a data vlen X-value Y-value c-point objtype ss )
  (setq fd (getvar "filedia")) (setvar "FILEDIA" 0)
  (setq cd (getvar "CMDECHO")) (setvar "CMDECHO" 0)
   
  (command "LAYER" "set" objlay "")
  (setq wPath nil)

  (if (setq wPath (findfile "ACAD.PAT"))
      (progn
        (setq wPath (vl-filename-directory wPath))
(or (eq "\\" (substr wPath (strlen wPath)))
    (setq wPath (strcat wPath "\\data")))))
 
  (command "MASSPROP" obj "" "Y" wPath)
  (setq datafile (strcat wPath ".mpr"))
 
  (setq open-a (open datafile) "r")
  (setq data "" )
  (while (not (wcmatch data "Centroid:*"))
    (setq data (read-line open-a))
  )
  (setq    vlen (- (strlen data) 26)
        X-value (atof (substr data 26 vlen))
        Y-value (atof (substr (read-line open-a) 26 vlen))
        c-point (list X-value Y-value)
  )
  (close open-a)
  (if (= objtype "LWPOLYLINE")
    (progn
      (command "EXPLODE" obj)
      (setq  ss (ssget "p")
            obj (ssname ss 0))
      (command "PEDIT" obj "Y" "Join" ss "" "")
    )
  )
  (command "POINT" c-point)
  (setvar "FILEDIA" fd)
  (setvar "CMDECHO" cd)
  (princ)
)

;Error
  (defun *error* ( msg )
        (if val (mapcar 'setvar var val))
        (if doc (LM:endundo doc))
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))) (princ))

  (defun LM:startundo ( doc ) (LM:endundo doc) (vla-startundomark doc))

  (defun LM:endundo ( doc ) (while (= 8 (logand 8 (getvar 'undoctl))) (vla-endundomark doc)))

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Need fresh eyes to check this lisp
« Reply #1 on: April 15, 2014, 08:00:35 AM »
Why don't you use this method for obtaining Centroid data after you convert LWPOLYLINE to REGION...

Code: [Select]
(defun c:centroid ( / ss ent enta )
  (vl-load-com)
  (setq ss (ssget "_+.:E:S" '((0 . "3DSOLID,REGION"))))
  (setq ent (ssname ss 0))
  (setq enta (vlax-ename->vla-object ent))
  (setq cent (vlax-safearray->list (vlax-variant-value (vla-get-centroid enta))))
  (prompt "\nCentroid : ") (princ cent)
  (prompt "\nVariable is called \"cent\" - you call it with !cent")
  (princ)
)

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube