Jump to content

Need to export each solid as separate dwg, dxf or 3ds file format


ADSK2007

Recommended Posts

Hello everyone

I need to export every solid object inside a cad file into a dwg, dxf or a 3ds file format. The export process can use any name, (ex. Solid-001, Solid-002, etc.).
one important thing to mention is that the solid needs to be saved based on 0,0,0 location.

 

1- Is there a procedure Inside AutoCAD I can take to do this? File save as or Export?

2- Could this be done using a script?

3- Are there any lisp that can accomplish such task?

4- Can this be done with a 3rd party plug-in or application other than AutoCAD?

 

Any suggestion would be very helpful and greatly appreciated

The file has too many objects to export individually so I am looking for an alternative solution to do this automatically.

 

Thank you

 

Link to comment
Share on other sites

Maybe this LISP snippet will give you a start, a Selection Set selecting solids or 3D solids only:

 

The If is there so that if there are no solids it will skip past your clever stuff

 

(if (setq MySS  (ssget '((0 . "*SOLID"))))
  (progn

;Do all your stuff to solids here

  ) ; end progn
  (progn

;Do your stuff if no solids selected

  ) ; end progn
) ; end if

 

and then look into -wblock to save each item in the selection set to a block

 

I can't remember how your LISP skills are, but is this enough to give you a good start?

Link to comment
Share on other sites

Hi Steven

 

Thank you for the quick reply. Sorry but I don't have enough experience with lisp programming. I thought maybe someone could suggest a way.
How do I run this lisp? Just so you understand where is this going, I need to import each object (Solid) into another application to calculate and visualize lights (Dialux Evo software). Each object needs to be imported separately into the scene. We design the scene in AutoCad and export it into Dialux software for precise lighting calculations.


 

20 minutes ago, Steven P said:

Maybe this LISP snippet will give you a start, a Selection Set selecting solids or 3D solids only:

 

The If is there so that if there are no solids it will skip past your clever stuff

 

(if (setq MySS  (ssget '((0 . "*SOLID"))))
  (progn

;Do all your stuff to solids here

  ) ; end progn
  (progn

;Do your stuff if no solids selected

  ) ; end progn
) ; end if

 

and then look into -wblock to save each item in the selection set to a block

 

I can't remember how your LISP skills are, but is this enough to give you a good start?

 

Edited by ADSK2007
Link to comment
Share on other sites

That's OK, some people know a lot and just need an idea what to do, some not a lot and want a full solution - both are OK

 

I'll see if I have time to think up something tomorrow or someone else no doubt will have something too

  • Like 1
Link to comment
Share on other sites

Hi Steven

I am not really looking for an easy solution. I have been searching for 2 days now. Yesterday I spent many hours using different applications and file formats to see which application will export a better mesh object with less mesh faces. Problem is that I get one block of many solids coming into Dialux evo as one object and I cannot separate them.
The only solution I found so far is to export each solid as a 3ds file separately and then import it into Dialux evo. That way I can have all objects separated and able to assign material and lighting properties. Doing it that way seem to work but each time exported objects from AutoCAD are imported in a different location even tho I set and export each object from 0,0,0 point. It is crazy "I Know" but for now I have no choice. So you see my friend, I have been scratching my head for two days trying
Anyway, I just posted this question here maybe someone knows something that can help either with a lisp, script, plug-in or even using another program that can do this easily.

 

btw, each solid is in its own layer. Maybe it can be exported by layer selection since they are all in a different layer?
In any case I do appreciate any suggestion / help you can give me.

 

Thank you

Link to comment
Share on other sites

All I can suggest you is to use DWG or DXF... 3DS file will tessellate roundness of 3D SOLID entities and you'll get them with huge size due to many vertices therefore processed...

Link to comment
Share on other sites

Have you tried Rhino (Rhinoceros) by McNeil... Maybe it can handle huge DWG files more reliably... I know that non uniformly scaled 3DSOLID entities stored in block can be imported to Rhino, there EXPLODED and finally import them to CAD as ACIS without any tessellations...

Link to comment
Share on other sites

hi ,  

 

if you can modify it, this will do the trick

 

 

(

(vl-load-com)
(defun c:WBP ( / c_doc o_arr ss o_lst cnt fname)
    (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
          o_arr (vlax-make-safearray vlax-vbobject '(0 . 0))
          ss (ssget "_X" '((0 . "POLYLINE") (-4 . "&=") (70 . 8)))
    );end_setq

    (repeat (setq cnt (sslength ss))
      (setq o_lst (cons (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))) o_lst))
    );end_repeat
    
    (setq cnt 0)
    
    (foreach obj o_lst
      (setq sso (vla-add (vla-get-selectionsets c_doc) "PLO")
            fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      );end_setq
      (vlax-safearray-put-element o_arr 0 obj)
      (vla-additems sso o_arr)
      (vla-wblock c_doc fname sso)
      (vla-delete sso)
      (setq cnt (1+ cnt))
    );end_foreach  
);end_defun

 

Link to comment
Share on other sites

hi 

 

Is that what you want ?

 

 

 

(vl-load-com)
(defun c:WBP ( / c_doc o_arr ss o_lst cnt fname)
    (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
          o_arr (vlax-make-safearray vlax-vbobject '(0 . 0))
          ss (ssget "_X" '((0 . "*SOLID") ))
    );end_setq

    (repeat (setq cnt (sslength ss))
      (setq o_lst (cons (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))) o_lst))
    );end_repeat
    
    (setq cnt 0)
    
    (foreach obj o_lst
      (setq sso (vla-add (vla-get-selectionsets c_doc) "PLO")
            fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      );end_setq
      (vlax-safearray-put-element o_arr 0 obj)
      (vla-additems sso o_arr)
      (vla-wblock c_doc fname sso)
      (vla-delete sso)
      (setq cnt (1+ cnt))
    );end_foreach  
);end_defun

 

Link to comment
Share on other sites

thecocuk07,
Unfortunately I don't have Lisp knowledge and don't know how to modify the code for solid objects instead of 3D polylines as described in the other thread.
Thank you for helping

Link to comment
Share on other sites

6 minutes ago, ADSK2007 said:

thecocuk07,
Ne yazık ki Lisp bilgim yok ve diğer başlıkta açıklandığı gibi 3D çoklu çizgiler yerine katı nesneler için kodu nasıl değiştireceğimi bilmiyorum.
yardım ettiğiniz için teşekkür ederim

(vl-load-com)
(defun c:WBP ( / c_doc o_arr ss o_lst cnt fname)
    (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
          o_arr (vlax-make-safearray vlax-vbobject '(0 . 0))
          ss (ssget "_X" '((0 . "*SOLID") ))
    );end_setq

    (repeat (setq cnt (sslength ss))
      (setq o_lst (cons (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))) o_lst))
    );end_repeat
    
    (setq cnt 0)
    
    (foreach obj o_lst
      (setq sso (vla-add (vla-get-selectionsets c_doc) "PLO")
            fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      );end_setq
      (vlax-safearray-put-element o_arr 0 obj)
      (vla-additems sso o_arr)
      (vla-wblock c_doc fname sso)
      (vla-delete sso)
      (setq cnt (1+ cnt))
    );end_foreach  
);end_defun

 

Edited by thecocuk07
Did you try ?
Link to comment
Share on other sites

marko_ribar

 

Yes, I know Rhino 3D very well and work with version 7 . My issue is not the quality of surface that gets imported into Dialux evo application. No matter what you import will tessellate regardless of what you do or what format you use (DWG, DXF or 3ds).

My problem as described above is to export all objects inside the CAD file into separate files. For example, if i have a store design with 100 solid models inside that cad file, I would like to end up with 100 files each containing one single solid or mesh (depending on file format and extension). As I also mentioned before I have a routine which will place each solid into a layer. So it should be possible to save each exported file as the layer name.

Edited by ADSK2007
Link to comment
Share on other sites

(vl-load-com)
(defun c:WBP ( / c_doc o_arr ss o_lst cnt fname)
    (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
          o_arr (vlax-make-safearray vlax-vbobject '(0 . 0))
          ss (ssget "_X" '((0 . "*POLYLINE") (-4 . "&=") (70 . 8)))
    );end_setq

    (repeat (setq cnt (sslength ss))
      (setq o_lst (cons (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))) o_lst))
    );end_repeat
    
    (setq cnt 0)
    
    (foreach obj o_lst
      (setq sso (vla-add (vla-get-selectionsets c_doc) "PLO")
            fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")
      );end_setq
      (vlax-safearray-put-element o_arr 0 obj)
      (vla-additems sso o_arr)
      (vla-wblock c_doc fname sso)
      (vla-delete sso)
      (setq cnt (1+ cnt))
    );end_foreach  
);end_defun

  • Like 1
Link to comment
Share on other sites

thecocuk07

 

No I didn't try it. I thought that code was made for 3d polylines and not for Solid objects. I will give it a try and see what i get.

Thanks

Link to comment
Share on other sites

I thank both of you, dlanorh for writing the code and you for helping me and make it work.

 

One last question, Is there a way that we could also save the file name to Layer name? As I mentioned before, each solid is put into a layer and layer name. This way When I end up with 300 dwg files, I know which file correspond to which layer. see snapshot attached

Screenshot 2023-01-23 110419.jpg

Link to comment
Share on other sites

Change this :

fname (strcat (getvar 'dwgprefix) (itoa cnt) ".dwg")

To :

fname (strcat (getvar 'dwgprefix) (cdr (assoc 8 (entget (vlax-vla-object->ename obj)))) ".dwg")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...