Author Topic: Macro to export an OBJ file -- Updated!  (Read 3394 times)

DrollTroll

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4091
Macro to export an OBJ file -- Updated!
« on: December 05, 2006, 12:43:04 PM »
Some time ago I created a macro to export DesignCAD surfaces (planes and grids) to an OBJ file that can be read by most other modeling programs. This can help you in the case where a particular program (Lightwave is an example) doesn't like DesignCAD's DXF output for surfaces.

Usage:
Download the macro ExportObj to your DesignCAD folder. Follow these steps to export a drawing to obj format:
1) Load the DesignCAD drawing that you want to export.
2) Tools/Macro Execute -> "ExportObj.d3m"
3) Load the obj file into the modeler of your choice.

Limitations:
1) DesignCAD pays no attention to normals, so you may have to reverse the normals on some of the faces of the exported objects before they look correct in your alternate application. Most modeling programs that care about normal orientation provide a means to reverse the direction of one or more faces of an object.

2) The macro makes no attempt to tesselate complex polygons into triangles. Some programs won't even acknowledge a facet that has more than 4 vertices. (Poser is an example that comes to mind.) For cases like this, you may have to do some intermediate adjustments in another program.

3) Different programs have different expectations of OBJ files. This exporter is about as no-frills as it gets. That means no colors, no materials. Faces are grouped first by group ID, if any, then by Solid ID, if any. All non-grouped, non-solid entities go into the same face group.

Enough with the caveats! Here's the file. This macro should work in DesignCAD 3D Max 14 and above.

NOTE: As of DesignCAD 3D Max 25, DesignCAD can now directly export obj files, and there's an option to tesselate all facets into triangles.

Update 11/17/2016 -- Updated the macro to use the existing filename and path, if the drawing has been saved.
« Last Edit: November 17, 2016, 08:29:43 AM by DrollTroll »
2016 marks my 24th year in DesignCAD-Land!

Ignoblius

  • Newbie
  • *
  • Posts: 9
Re: Macro to export an OBJ file
« Reply #1 on: May 13, 2008, 04:16:29 PM »
You can flip normals on the mesh object in DCAD by selecting the object, calling up the info box (ctrl-I) and hitting the "Reverse the order of the points" button. It's 3rd on the top right, with a graphic of opposing red and blue arrows.

Ignoblius

  • Newbie
  • *
  • Posts: 9
Re: Macro to export an OBJ file
« Reply #2 on: May 13, 2008, 04:32:04 PM »
One problem I had with this macro is that I don't get to pick the destination of the OBJ file created-it is created in the same directory that the macro is in. I get around this problem by having a "DCAD generated OBJ" folder where I want it and placing the macro file in that folder.

Another problem is that I can only use it once in a drawing session-if I try to use it again the macro ignores any changes made to the drawing since the first time. I have to save, close and reopen the drawing. Fortunately, if I do this without exiting DCAD the "Macro Execute" menu line defaults back to my folder of choice.

DrollTroll

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4091
Re: Macro to export an OBJ file
« Reply #3 on: May 19, 2008, 10:36:38 AM »
You can flip normals on the mesh object in DCAD by selecting the object, calling up the info box (ctrl-I) and hitting the "Reverse the order of the points" button. It's 3rd on the top right, with a graphic of opposing red and blue arrows.

Indeed you can. However, you can't really tell which way the normal is facing in DesignCAD. I suppose you could export to obj, load the obj in another program, note which normals are backwards, then pick the faces in DesignCAD and reverse them and export again. I find it much more efficient to just do the face-flipping directly in the destination program (unless it's Poser -- the grouping tools in Poser are awful).
2016 marks my 24th year in DesignCAD-Land!

DrollTroll

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4091
Re: Macro to export an OBJ file
« Reply #4 on: May 19, 2008, 10:53:03 AM »
Another problem is that I can only use it once in a drawing session-if I try to use it again the macro ignores any changes made to the drawing since the first time. I have to save, close and reopen the drawing.

That's quite strange -- I've not seen any problem like that. Is it possible you're overwriting an obj file that you've got open in a different application? That might cause the file to be locked and thus not get overwritten -- but I don't see in that case why closing the drawing in DesignCAD would have any effect...
2016 marks my 24th year in DesignCAD-Land!

Ignoblius

  • Newbie
  • *
  • Posts: 9
Re: Macro to export an OBJ file
« Reply #5 on: May 21, 2008, 05:05:52 PM »
That's possible. Usually when I use the macro, I have DCAD and Poser open at the same time so I hunt for wrong-way normals in Poser and flip them in DCAD.