Author Topic: Direct Autocad/Intellicad to Blender exporter. LISP to Download  (Read 6411 times)

0 Members and 1 Guest are viewing this topic.

Inciner

  • Guest
Direct Autocad/Intellicad to Blender exporter. LISP to Download
« on: October 12, 2012, 12:36:44 PM »
Hello everyone, my name is Paul Kotelevets aka 1D_Inciner, Im from Usinsk (Russia).
I use a lot of software such as AutoCAD+LISP+PGP+DCL, 3dsmax, Blender+Cycles+Octane, Zbrush, Sculptris, Mypaint, SAI, Photoshop, GIMP, Inkscape and others.

A week ago I start writing direct LISP exporter from AutoCAD/Bricscad/ZWCAD to Blender 2.64 via OBJ file (under GPL).
My original tread is on BlenderArtist
http://blenderartists.org/forum/showthread.php?267990-Direct-Autocad-Intellicad-to-Blender-exporter-LISP-to-Download
Currently it supports for LWPOLYLINE, POLYLINE, LINE, SPLINE, ARC, CIRCLE, ELLIPSE, 3DFACE, SOLID and POINT entities with ability to write every nth point to reduce pointcloud density.

Get Blender 2.64a (current version, GPL) http://www.blender.org/download/get-blender/
If someone is interested in it,  it's structure, or can to give data conversion/perfomance advice - here it is, attached below.
Thanks for your attention
updated to v 2.01 (2:58 12.10.2012)


« Last Edit: October 13, 2012, 03:48:34 PM by Inciner »

Inciner

  • Guest
Re: Direct Autocad/Intellicad to Blender exporter. LISP to Download
« Reply #1 on: October 26, 2012, 02:57:14 PM »
By the way, does anybody have good LWPOLYLINE parser?
That will allow rebuild them with bulges, normals and 'Close detecting?

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Direct Autocad/Intellicad to Blender exporter. LISP to Download
« Reply #2 on: October 26, 2012, 04:13:04 PM »
By the way, does anybody have good LWPOLYLINE parser?
That will allow rebuild them with bulges, normals and 'Close detecting?

entget?

Inciner

  • Guest
Re: Direct Autocad/Intellicad to Blender exporter. LISP to Download
« Reply #3 on: October 26, 2012, 05:18:39 PM »
Well, ok.
It seems, that I'm not tough enough to manipulate with gathered DXF data.
For example, here is my alpha code, that splits the very simple-shaped polylines into 2 chunks by rebuilding gathered coordinates data, but building and gathering functions are still not able to read/write bulges and normals...

How can such solution look like?

Code: [Select]
(defun c:ww (/) (SETQ LST NIL)(c:split))

(defun c:split
   
  ( /
;|
   a1 a2 acblk acdoc acspc
   bb bd bn bo bs
   di
   en
   g1 gr
  g2
   ms
   of
   pt
   ss
|;
  )

;; {{Helper functions}

;;======================================================;;
;;  written by Fatty The Old Horse 10/13/05    ;;
;;      (framework)      ;;
;;======================================================;;
;; group list by number 1D_mod


(defun 1dpl:group-by-num (lst num / ls retf)
(if (= (rem (length lst) num ) 0)
 (progn (setq ls nil)
  (repeat (/ (length lst) num)
    (repeat num (setq ls (cons (car lst) ls) lst (cdr lst)))
  (setq retf (append retf (list (reverse ls))) ls nil)))) retf)

;;------------------------------------------------------------;;

;;; построение полилиний [[create polyline]]
(defun entmake-pline (lst)
  ;; lst - список координат точек в текущей системе координат
  ;; (entmake-pline '((0. 0.) (10. 20.) (30. 50.)))
  ;; (entmake-pline '((0. 0.) (10. 20.) (30. 50.) (100. 0.)))

  (entmakex (append (list '(0 . "LWPOLYLINE")
                          '(100 . "AcDbEntity")
   elayr
                          '(100 . "AcDbPolyline")
                          (cons 90 (length lst))
                          ) ;_ end of list
                    (mapcar '(lambda (x) (cons 10 x)) lst)
                    ) ;_ end of append
            ) ;_ end of entmakex

  ) ;_ end of defun


;;------------------------------------------------------------;;

(defun 1D_getinters (e1 e2 /
pts
) ;ent1 ent2
(vl-load-com)
 (setq ent1 (vlax-ename->vla-object e1)
 ent2 (vlax-ename->vla-object e2)
 pts (vl-catch-all-apply
 'vlax-safearray->list
 (list (vlax-variant-value
 (vla-intersectwith ent1 ent2 acextendboth)
 )
 )
 )
 )
 (if (vl-catch-all-error-p pts)
 (setq lst nil)
 (repeat (/ (length pts) 3)
 (setq lst
 (cons (list (nth 0 pts) (nth 1 pts) (nth 2 pts)) lst)
 pts (cdddr pts)
 )
 )
 )
 lst
 )

;}

;;;{{Main Func}

  (setq acdoc (vla-get-activedocument (vlax-get-acad-object))
        acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
        acblk (vla-get-blocks acdoc)
  )
  (or *oa|per (setq *oa|per (/ pi 2.)))
  (or *oa|off (setq *oa|off 0.))

  (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER))))))
    (princ "\n--> Current Layer Locked.")
    (if
        (setq en (car (entsel "\n LWpolyline")))  ;;
      (progn

(setq vs nil)
(setq vs (ssadd)) ;;empty selset memslot
(setq vss (ssadd)) ;;empty selset memslot


;; ========= Getting (dirty) Properties ===========
(setq enP nil)
(setq elayr (assoc 8 (entget en)))
(if (assoc 370  (entget en)) (setq enp (cons (assoc 370 (entget en)) enP))  )
(if (assoc 6 (entget en))  (setq enp (cons (assoc 6 (entget en)) enP)))
(if (assoc 62  (entget en)) (setq enp (cons (assoc 62 (entget en)) enP))  )

;; ========= Getting perpendicular intersections pointlist ===========
(PRINC "\n_point")
(SETQ G2 (GETPOINT))
(setq OSM (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq pt (vlax-curve-getClosestPointto en (setq g2 (trans g2 1 0))))
(setq g2 (trans g2 0 1))
(setq pt (trans pt 0 1))

(setq MTLIN (entlast))
(command "_LINE" g2 pt "")
(if (/= (entlast) MTLIN) (setq MTLIN (entlast)))
(1D_getinters MTLIN en)

;; ========= Comparing distances ===========
(setq ret (apply 'append ;(dist (point))
                             (mapcar '(lambda (el)
                              (list (cons (distance el g2) el))
                                      ) ;_  lambda
                                   LST ;taken pointlist
                             ) ;_  mapcar
                     ) ;_  apply
           ) ;_  setq

(setq ret (vl-sort ret (function (lambda (e1 e2)(> (car e2) (car e1))))));;; nearest from list

;; ========= Grdrawing Cutting line ===========
(setq A11 (trans (cdr (nth 0 ret)) 0 1))  ;; first nearest
(setq A22 (trans (cdr (nth 1 ret)) 0 1))  ;; second nearest
(grdraw a11 a22 5 1)
(entdel MTLIN)
(setq pt (getstring "Continue?: "))

(redraw)

;; ========= Getting _EN lwPolyline data and splitting it by _PTV point to _XX and _YY chunk lists  ===========
(defun 1d:PDIV (en ptv /)
(setq id_obj (vlax-ename->vla-object en))
(setq lvl (vla-get-Elevation id_obj))
(setq ret (vlax-get id_obj 'Coordinates))
(setq ret (1dpl:group-by-num ret 2)) ;;; splitting datalist to pairs
(setq ret (mapcar '(lambda (x) (append x (list lvl))) ret) );;;adding Zcoord to verts from elevation

(defun RemDup  (lst / z)
  (while (setq x (car lst))
    (setq
      z   (cons x z)
      lst (vl-remove x (cdr lst)))
    (mapcar
      '(lambda (y)
         (if (equal
               (list (nth 0 x) (nth 5 x))
               (list (nth 0 y) (nth 5 y)))
           (setq lst (vl-remove y lst))))
      lst))
  (setq nlst (reverse z))
  )

;; =========== Removing Duplicates #1 ==================================
(setq ret (RemDup ret))

;; =========== Packing list '(distance_from_begining (x y z))  =========
(setq DB nil i 0 DB11 nil DB22 nil)
(foreach n ret (setq DB (cons (list (vlax-curve-getdistatpoint id_obj n) n) DB))
(setq i (1+ i)) )

;; ==== Adding Vertex if closed  ========================================
(if (= (vlax-get id_obj 'Closed) -1) (setq DB (cons (list (vla-get-Length id_obj) (nth 0 ret)) DB) ))
(setq DB (reverse DB))

;; ==== Storing _PTV actual distance to _X1  =============================
(setq x1 (vlax-curve-getdistatpoint id_obj (trans ptv 1 0)))
(princ "\n ptdist =")
(princ x1)

;; ==== Splitting Polyline's data into before/after _X1 distance  =========
(setq i 0 xx nil yy nil)
(repeat (length DB)
(setq n (nth i DB))
(if (nth i ret) (if (< (car n) x1) (setq xx (cons (nth i ret) xx))  (setq yy (cons (nth i ret) yy)) )  )
(setq i (1+ i))
)
)

;; =========== First point datasplit =========
(1d:pdiv en (trans a11 0 0) )

;; =========== Building Dummy test Polyline =========
(setq DBX (append xx yy))
(entmake-pline DBX)
(command "_.chprop" en "" "_C" 50 "")
(entdel en)
(setq en (entlast))
(command "_PEDIT" en "_C" "")
(setq vs (ssadd en (ssadd)))
(command "_.chprop" en "" "_C" 220 "")

;; =========== Second point datasplit =========
(1d:pdiv en (trans a22 0 0))

(setq a11 (trans a11 1 0))
(setq a22 (trans a22 1 0))

;; =========== Removing Duplicates #2 =========
(if (member a11 xx)
(setq DB1 (append (cons a22 nil) xx ))
(setq DB1 (append (cons a22 nil) xx (cons a11 nil)))
)

(if (member a11 yy)
(setq DB2 (append yy (cons a22 nil)))
(setq DB2 (append (cons a11 nil) yy (cons a22 nil)))
)

(setq db11 db1)
(setq db22 db2)

;; =========== Building First Chunk =========
(entmake-pline DB1)
(setq DB1 (entlast))
(command "_PEDIT" DB1 "_C" "")
(if (assoc 62 enp) (command "_.chprop" DB1 "" "_C" (cdr (assoc 62 enp)) ""))
(if (assoc 6 enp) (command "_.chprop" DB1 "" "_LT" (cdr (assoc 6 enp)) ""))
(if (and (assoc 370 enp) (> (cdr (assoc 370 enp)) 0)) (command "_.chprop" DB1 "" "_LW" (/ (cdr (assoc 370 enp)) 100.0) ""))

;; =========== Building Second Chunk =========
(entmake-pline DB2)
(setq DB2 (entlast))
(command "_PEDIT" DB2 "_C" "")
(if (assoc 62 enp) (command "_.chprop" DB2 "" "_C" (cdr (assoc 62 enp)) ""))
(if (assoc 6 enp) (command "_.chprop" DB2 "" "_LT" (cdr (assoc 6 enp)) ""))
(if (and (assoc 370 enp) (> (cdr (assoc 370 enp)) 0)) (command "_.chprop" DB2 "" "_LW" (/ (cdr (assoc 370 enp)) 100.0) ""))

;; =========== Deleting Dummy test Polyline =========
(entdel en)

(setvar "OSMODE" OSM)

;;;;; end
      )
    )
  )
  (princ)
;}
)
« Last Edit: October 26, 2012, 06:21:48 PM by Inciner »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Direct Autocad/Intellicad to Blender exporter. LISP to Download
« Reply #4 on: October 26, 2012, 10:38:36 PM »
Maybe this thread will help you.
http://www.theswamp.org/index.php?topic=19865.0
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.

Inciner

  • Guest
Re: Direct Autocad/Intellicad to Blender exporter. LISP to Download
« Reply #5 on: October 28, 2012, 02:46:59 AM »
Wow, such powerful simplification algorhytms! Such a nice day =)
Thank you!

But then some more complex question - does anybody knows how to get face information from POLYFACE_MESH and POLYGON_MESH object types? Both of them are '(0 . "POLYLINE"), and I'm able just to get single polyline, that connects all vertices =\
Meanwhile, as a result it's looking rather funny, but whatever...
I know just that this could be done, as far as old Blender 2.49b has got DXF importer, that converts succesfully both of them, but I dont have any clue about how...

And I guess, that there is no use to ask about 3DSOLID and REGIONS. Their structures are opened in Bricscad, are available to be decoded in Autocad, has no acces into ZWCAD, and there is absolutely NO any converter available on LISP, because of complexity of ACIS SAT. That's So pity =\
« Last Edit: October 28, 2012, 04:11:31 AM by Inciner »