georeference.org
Subscribe to this thread
Home - Scripting / All posts - DWG Tools Add-in (flattens dwg layers)
steveFitz

148 post(s)
#13-Jul-16 07:38

As promised, here, attached is an Add-in I've been working on for a while to flatten CAD layers to a single drawing component (or few, where text is included).

The Add-in extends the many and varied scripts that can be found on the forum and saves heaps of time if you convert CAD layers for using in field data collection programs such as Arcpad, etc. Most importantly it overcomes the copy/paste problem that can occur in some scripts.

The scripts involved include a few novelty items I wrote more for a matter of interest and learning C# rather than necessity. There is a config file for changing a few variables such as folder names and operation modes (e.g. 'quiet mode', default projection). It also harvests the colours from the imported layers and attempts to reproduce them in a theme.xml file which can be saved.

To make installation quick and easy (hopefully!) I made the project an 'installer' rather than upload a zip of files. I like the idea that you can peruse the code before installing and not have to trust what may be hidden in a zip file!

If anyone objects to using an installer then let me know and i'll post a zip too.

To install: run Manifold in Administrator mode, open the project and run '_Install Add-In Script'.

Use:

After installing and restarting Manifold you should have 3 numbered icons.

  1. Click 1 to import and project your dwg file. Define your area of interest by zooming and panning map to encompass all you want in the resulting flattened drawing. Turn visibility off for layers you don't want;
  2. Click 2 to define your area of interest (an additional AOI layer is added to the map);
  3. Click 3 to start the flattening process.

There are more instructions and details in the DWG Tools Readme comments in the project.

Thank-you to oisink for testing and commenting. Both oisink and tjhb contributed code and comments that inspired the Add-in.

Please feel free to reproduce any parts of the code or improve/extend the Add-in.

Steve

Attachments:
Add-In_DWGTools_095_b.map

pierredp
69 post(s)
#13-Jul-16 09:50

Many thanks for taking the time to develop and share this add-in. It came at just the right time since I have to convert heaps of CAD drawings for a project I've just started.

Will provide feedback as soon as I've used it


"Use time and words carefully because neither can be retrieved" - Jackson Brown

oisink
360 post(s)
#13-Jul-16 17:35

Its great - which is a welcome relief in the UK at present.

mikedufty

755 post(s)
#21-Jul-16 04:11

Thanks,

Seems to work nicely and less clunky than my old script.

Still need to find a way to import dwgs with block references.

mikedufty

755 post(s)
#25-Jul-16 09:14

Just checking, does this only work for dwg import or is there a way to select dxf?

steveFitz

148 post(s)
#25-Jul-16 10:10

mikedufty,

I haven't allowed for the import of dxf but I will check if I could make it an option for the next version.

At the moment you would need to import the dxf manually, project it manually, set the AOI area (all the step 1 processes), put the whole lot in a single folder then continue with step 2 and 3. That should work but... takes a lot of automation away.

With regard to the block references, is it possible to reconstruct one in Manifold 8?

I tried to import a single block and then reconstruct it from its parts but couldn't (no such thing as a multi-line?).

Steve

steveFitz

148 post(s)
#25-Jul-16 12:03

Well, that wasn't difficult at all really.

I added a few lines to import dxf format and it all seems to work (mind you I've only got 1 dxf file here to test).

As a matter of coincidence the only dxf I had had a name starting with lower case. This triggered a bug in my code that is now fixed. I had never thought to test with lower case file names!

Let me know how it goes.

Install will prompt to overwrite old files so keep a copy of your config file if you have customised it.

You will know the new version is installed when button 3 tool tip says "Flatten layers" rather than flatten dwg.

Steve

edit: you choose DXF File (*.dxf) from the file dialog file type drop down as default is dwg

Attachments:
Add-In_DWGTools_095_c.map

steveFitz

148 post(s)
#26-Jul-16 00:28

Whoops! It looks like I actually broke the file dialog filter for dwg!

That will teach me to send off without proper testing.

I'll fix it today and repost.

Apologies.

steve

steveFitz

148 post(s)
#26-Jul-16 10:15

Here is the latest version with file dialog filter fixed (an additional space caused it not to work).

Let me know if there are any issues.

Steve

Attachments:
Add-In_DWGTools_095_c.map

steveFitz

148 post(s)
#27-Jul-16 02:32

mikedufty,

Still need to find a way to import dwgs with block references.

Prompted by a line from another recent post by tjhb I tried

SELECT AllBranches([Geom (I)])

on an imported dwg block and see that indeed one can make a single object from lines.

So the next step would be to identify if there were anything linking the primitive parts of the imported block so it could be reconstructed. I can't see any. I have little experience with CAD so may have missed something.

Is there any way that the block parts can be identified for reconstruction?

Apologies if this has already been discussed.

Steve

Manifold User Community Use Agreement Copyright (C) 2007-2011 Manifold Software Limited. All rights reserved.