Saturday, September 26, 2009

Extracting 3D DWF Model Properties Using Autodesk Design Review API and AutoCAD VBA

A while ago I came across a situation where I had to extract line lists, valve lists, equipment lists and fittings lists from a DWF file. The DWF file was converted from a PDS model review file (DRI) using NavisWorks. After a few hours research on Autodesk Design Review API, I could extract all the required lists with a few lines of code. Ofcourse, with the help of fast dying AutoCAD VBA.

As the code makes use of CExpressViewerContol, you need to place it inside a form before running the code. You may use any COM compliant development environment in place of AutoCAD VBA. But I would like to stick to AutoCAD VBA till its last breath due to ease of use.

Sub ExtractDwfProps()
'### Extracts properties from model components of a 3D DWF file
'### By zoomharis@gmail.com
'### Date: 09/09/09

'### Based on Autodesk Design Review 2010 API

'### DWF specific references
' -----------------------
'### AdCommon 1.0 Type Library
'### ECompositeViewer 1.0 Type Library
'### ExpressViewerDll 1.0 Type Library

'### DWF specific controls
' ---------------------
'### CExpressViewerContol

On Error Resume Next
Dim oECV As ECompositeViewer.IAdECompositeViewer
Dim oSec As ECompositeViewer.IAdSection
Dim oEnt As AdCommon.IAdObject
Dim oProp As AdCommon.IAdProperty
Dim oCol As AdCommon.CAdCollection
Dim oCont As ECompositeViewer.IAdContent
Dim strDwfLoc As String
Dim strPropName As String
Dim strPropValue As String
'## Let me use a sample 3D dwf file
strDwfLoc = "C:\Dwf\3DModel.dwf"
strPropName = ""
strPropValue = ""
'## Open the dwf file in the viewer
CExpressViewerContol1.SourcePath = strDwfLoc
Set oECV = CExpressViewerContol1.ECompositeViewer
'## Iterate through the dwf model
For Each oSec In oECV.Sections
Set oCont = oSec.Content
Set oCol = oCont.Objects(0)
For Each oEnt In oCol
For Each oProp In oEnt.Properties
strPropName = oProp.Name
strPropValue = oProp.value
Next
'## Write code here to apply conditions to filter the list
'## and send the extracted info into a text or excel file.
'## Then clear the property name and property value strings
strPropName = ""
strPropValue = ""
Next
Next
Set oProp = Nothing
Set oEnt = Nothing
Set oCol = Nothing
Set oCont = Nothing
Set oSec = Nothing
Set oECV = Nothing
End Sub

I have stripped down some of the code portion as it was specific my purpose. This is mostly in a general form and you may need to add/modify wherever necessary in order to run it in your system.

Saturday, September 12, 2009

Creating Complex Selection Sets Using FILTER Command

It always make me wonder why the FILTER command is often overlooked by most of the AutoCAD users of current era, especially the newbies. It may be partially due to the fact that this command can get highly complicated at times depending upon the requirement. Ofcourse, it can be. But the power is always accompanied by complexity. Some of the advantages of this most powerful selection tool are;
  • Creating selection sets based upon multiple criteria
  • Creating logical groups without physically grouping it
  • Flexibility to use transparently in between the commands

To make it simple (sorry, if you find it otherwise ;-), let us go by a sample. I have a Piping & Instrumentation diagram in which I need to create a selection set of major and minor process lines along with the line numbers. The newbie designer has drawn some of the lines as LINE entity and rest of them as POLYLINE entity. All the major lines are placed inside 'MAJOR' layer and the minor ones in 'MINOR' layer. The line number is placed inside an attributed block reference named 'LINENO' which resides in 'LINE_NUM' layer. The image below illustrates the filter criteria for creating the above selection set.



This is a nested filter criteria that makes it little difficult to understand. Nothing to worry. Let us split it into smaller portions so that we can analyse it easily.Following is the description of each portion in the order as shown in the image.




  1. Object= 'LINE' OR 'POLYLINE'
  2. Layer = 'MAJOR' OR 'MINOR'
  3. Block_Name = 'LINENO' AND Layer = 'LINE_NUM'
  4. Result of Step-1 AND Step-2
  5. Result of Step-3 AND Step-4.

If you represent the whole thing as a logical expression, it would look like the following statement;

((( Object= 'LINE' OR 'POLYLINE') AND (Layer = 'MAJOR' OR 'MINOR')) OR (Block_Name ='LINENO' AND Layer = 'LINE_NUM'))

If you have a closer look at the filter, you will find that the innermost criteria gets resolved first and passes its result to the outer ones in nested filters. In the above case, the criteria to be executed at the final stage is the outermost one (Step-5).

This way, you can save very complex filters in your drawing for quick access at any stage of drawing development or review.

Friday, August 28, 2009

Quick Tip - Start an MText List with a Number or Alphabet of Your Choice

Last week I came across one of our designers using this nice trick and thought I would share it with you people. If you want to start a list inside MText window with a number or alphabet of your choice, try the following steps.
  1. Type the number or alphabet followed by a period (dot) symbol.
  2. Press the tab button after the period symbol
  3. Type the content of the first line (optional) and press enter key.

That's it. Now you will find the list starting with the number or alphabet you typed over there. Shown below is a sample list created using the above steps.

In addition to that, a little research on the subject helped me to prefix the list numbers with a custom text, as shown in the image below.


Wednesday, August 12, 2009

Quick Tip - Generating a Drawing List from Different Folders Using Windows Command Prompt

Most you might already know that typing DIR *.dwg /B > ListFileName in the windows command prompt will provide you with a quick list of drawings in the specific location. What if you want to create a list with drawings from multiple folders? It's a really simple task. See the following sample to get to know the syntax.

DIR D:\Proj_Dir\Disc-1\*.dwg D:\Proj_Dir\Disc-2\*.dwg D:\Proj_Dir\Disc-3\*.dwg /B > D:\Proj_Dir\Dwg_List.txt

As you can see, the paths are seperated by a space. Remember that the /B switch is still required to get the bare format file names. The above command will list all the drawing file names in the folders Disc-1, Disc-2 and Disc-3 to the Dwg_List.txt file. To access windows command prompt, either type CMD in the run prompt or locate it via Start--> All Programs --> Accessories --> Command Prompt.

Tuesday, July 14, 2009

How to Use DWG TrueView to Optimize Your Drawing Files

Yet another reason to add DWG TrueView to your arsenal. DWG TrueView can be used as an excellent tool to optimize drawing files in batch. With facilities like purging, auditing, xref binding etc. TrueView has become truly irresistible for the CAD managers/administrators/users . Following are the steps involved in the process.

1. Start DWG TrueView and open 'DWG Convert' from the menu. It will launch the 'DWG Convert' dialog box.



2. Click on the 'Conversion Setups' button to open 'Conversion Setups' dialog box. Our idea is to create an exclusive setup for our optimization process.


3. Click on 'New' button to launch 'New Conversion Setup' dialog box and provide a meaningful name over there.


4. Clicking on 'Continue' button will pop up the 'Modify Conversion Setup' dialog box. Here I am going to use the basic settings. You may choose the options as per your requirement. Since our aim is to optimize the drawings (drawing format conversion is not our primary objective), I prefer to use 'In-place (overwrite files)' as my conversion package type. Choose the drawing file format based upon your company/client CAD standards (We normally use AutoCAD 2007 format as we are still on AutoCAD 2008). In the actions area, select 'Check and fix errors' and 'Purge drawings' check boxes as a minimum. Don't forget to provide a conversion setup description at the bottom in order to easily make out the setup objective later on.


5. Click 'Ok' to finalise the setup. You can see the new setup name listed in the 'Conversion Setups' list box.


6. Close the dialog box to go back to the 'DWG Convert' dialog box. Add the drawing files to be optimized using the 'Add file' button in the bottom side. Once the drawings have been added, make sure that the recently created conversion setup is selected in the list. That's it. Just click on convert button and the TrueView application will do the rest for you.


Once the setup is made, you can use the same setup every time you need to optimize the drawings. Really cool, isn't it? The entire process consumes only a little time and resources. In case you haven't installed AutoCAD 2010 yet, TrueView is a must for you as it can bring 2010 format files down to your AutoCAD version compatible format. What else you need to get it installed on your system? DWG TrueView and Autodesk Design Review are FREE and can be downloaded from the Autodesk site.

Tuesday, July 7, 2009

DATAEXTRACTION Means A Lot More Than Simple Attribute Extraction

How often do you use DATAEXTRACTION wizard for extracting some information other than block attribute data? I have often seen people leaving it behind for tasks like extracting specific text information mentioning that this tool is not powerful enough to get an accurate output. That's not true. Here I am going to show you how to extract a line list from a bunch of Piping & Instrumentation Diagrams (P&ID). The P&IDs contains a lot of other text objects. But with the help of some filtering options, you can extract only the required text information from the drawing.

1. Start DATAEXTRACTION wizard

2. Select the required P&ID drawings (Here I am using sample ones).

3. In the third page select only 'Text' as object type.(Tip: You can uncheck all entries simultaneously by using right click).

4. In the fourth page, select 'Drawing' and 'Text' in the category filter. Also select 'File Name' and 'Value' in the properties area.

5. In the refine data page, you will get a screen similar to the one shown below. This is the area where we are going to play our game. You will notice that the value field contains various text object values from different drawings. We need to confine the list to line numbers.

6. Now right click on the value column and select 'Filter Options' from the right click menu.

7. You will be provided with a filter dialog box as shown in the image below. For our purpose, select the 'Contains' list item from the first list box and type in a wildcard criteria *"-* in the second list box as shown in the picture.

8. Click 'Ok' to apply the filter. Now you can see the value column filtered to show only line numbers based upon the given criteria.

9. Click on 'Next' button and save the output as an excel file or table.


You can easily create various lists from your drawings irrespective of the data containers. Whether it be attribute or text, DATAEXTRACTION is powerful enough to pull the required data based upon different conditions. As the wildcard criteria plays a critical role in extracting the specific data, you need to be very careful to choose the right criteria in order to get proper results.

On a side note, I feel like the command name is a bit too long. It would be a lot better if it were something like DATAXTRACT or even shorter. Anyway, that's not a matter of a concern as we don't use this command very frequently.

Thursday, May 21, 2009

Some Interesting Single Key Shortcuts in Autodesk Design Review

For the keyboard fans, who don't like working with menus and ribbons, there are several easy to use keyboard shortcuts inside ADR to make your life a lot easier. Some of those deserve a special mention for the fact that they are single key shortcuts. Using these shortcuts, the navigation options seem to be as easy as in AutoCAD, or even better. Here goes some of the single key shortcuts those caught my eyes at first sight.

R - Zoom Rectangle
F - Fit to Window
Q - Dynamic Zoom
H - Pan
PgUp - Next Page
PgDn - Previous Page
G - Length (Dimension)
N - Full Screen (Toggle)

I personally found the 'R' and 'F' shortcuts combination so terrific that it could easily beat the speed of Z+W and Z+E combination in AutoCAD. For a full list of ADR shortcuts, please refer to the help section inside the application. Unfortunately, I could not find any equivalent shortcut keys for DWG TrueView. If it's not available in TrueView, Autodesk should seriously consider incorporating it, atleast for the navigation options. For sure, these applications are going to be more and more popular in the future.