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
'### 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
'## 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 = ""
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.

Wednesday, April 15, 2009

How To Use Autodesk Design Review As Your Default Raster Image Viewer

Have you had a lot of headache in the past for viewing raster files those are not supported by windows built in image viewer applications? Don't worry, the solution is right under your nose. Apart from serving as an excellent review application, Autodesk Design Review can also be used as a raster image viewer. That means, you don't have to attach the raster images inside AutoCAD to view the contents. Instead, you can directly double click it on the explorer so that it opens directly in the Design Review application. Please make sure that you have done the following steps.

1. Goto Control Panel and double click on 'Folder Options'.
2. Goto the 'File Types' tab.
3. Locate the raster file extension inside the 'registered file types' list
4. If the extension does not exist, then click on 'New' to create a new one.

5. Select the extension from the list and click on 'Change' button shown in the details section.

6. From the next popup window, choose 'Select the program from a list' option.

7. Choose Autodesk DWF Application as the preferred application to open files with this extension. Also remember to check the 'Always use the selected program to open this kind of file' check box shown right under the list.

8. If everything is done properly, it will look as shown in the image below.

That's it. Repeat the same steps for other types of raster files. Once done, you don't have worry about it any more. Now you can goto explorer and double click those files to open it directly inside the Design Review application. I have configured mine to view file types like CAL, CALS, GP4, CG4, MIL, RST, PCT, PICT, TGA, RLS etc. (testing pending for some types). The best part of the story is that you can easily save this image as a DWF(x) file in order to send it to somebody for review purpose.

Autodesk Design Review is a wonderful review application with exciting features like '2D content comparison', 'PDF Support' etc. It's free and can be downloaded from the Autdesk Design Review site.

Sunday, January 25, 2009

Assigning Multiple Double Click Actions to Single Entity Type in AutoCAD

In the Unleash the Double Click Power post, you saw how to customize the double click action of an entity type to implement custom double click actions. Now we are going to see how we can implement different double click actions simultaneously on single entity type. Normally, we accomplish this by using Reactors or Events in the respective languages. But, we are not going to use any of these in our method. Rather, we will follow a tricky way to achieve the same result.

As an example, I will show you how to change the double click action of an 'Attribute Block'. Normally double clicking an attribute block shows the Enhanced Attribute Editor Dialog. We are going to change this to show either Enhanced Attribute Editor(_eattedit) or Edit Attributes dialog (_attedit) depending on certain condition. Let's say, when we double click on a title block named TITLE_BLOCK, it should display the Enhanced Attribute Editor dialog and for all other blocks in the drawing, it should display Edit Attributes dialog. The step by step configuration is given below.

  1. Open CUI and create a custom command with the following code inside the macro section of the command. If you don't know how to create a custom command, then refer to the 'Unleash the Double Click Power' post mentioned above. Replace the 'TITLE_BLOCK' inside the following code with your actual title block name.
    ^C^C(if (= (cdr (assoc 2 (entget (ssname (ssget "P") 0)))) "TITLE_BLOCK") (command "_eattedit")(command "_ddatte" ))

  2. Drag and drop the custom command under the 'Attribute Block' section inside the Double Click Actions.

  3. Click on 'Apply' and close the CUI dialog.

That's it. Now if you double click on the title block, it will open the Enhanced Attribute Editor dialog and for all other attributed blocks, it will open Edit Attributes dialog. By the way, don't forget to take a backup of the default CUI files before you start experimenting with them.

Sunday, January 18, 2009

Quick Tip - A Shortcut for Closing Active Drawing

You already know that ALT+F4 can effectively be used to quit a running application in windows operating system. For those who don't know, pressing CTRL+F4 inside AutoCAD will close the active drawing without touching the application or other drawings already open over there. Though it's a more straight forward shortcut than the ALT+F+C, I would like to stick to the latter as it looks easier to me (May be because I am used to that). CTRL+F4 shortcut is not limited to AutoCAD, but it works well with almost all windows multi document interface (MDI) applications.

Sunday, January 4, 2009

My New Year Wish - An Intermediate AutoCAD Product for 2D Designing & Draughting

Why? Let's have a look at the existing product line. ie, Vanilla AutoCAD and AutoCAD LT. You might be able to find an answer from there.

AutoCAD LT: The lack of strong application programming interfaces makes AutoCAD LT really handicapped in the perspective of a Power User or CAD Administrator. You can not use any of your custom commands developed using AutoLISP/VBA/Dotnet/ObjectARX inside LT. The remaining option called DIESEL is only good enough to make small macros. Not only that; the number of commands are limited as compared to the full version.

Vanilla AutoCAD: Very powerful platform for 2D as well as 3D designing and modeling. The disadvantage is that it's loaded with comprehensive 3D modeling and rendering engines which are not at all used by the 2D user. Believe me; I have never used any of the 3D modeling or rendering features for the past 4 or 5 years for official purpose. That means the 2D users are carrying a burden over their shoulders and have been quite unnecessarily paying for the unwanted features. They could work much faster, if all those unwanted features were not loaded over there. The recent versions of AutoCAD show that it is more inclined towards 3D development than the 2D ones.

The need of the moment is an intermediate AutoCAD Product, which offers the power of Vanilla AutoCAD customization and 2D features minus all the 3D/rendering features with an attractive price tag. In that case, managers don't have to think twice at the time of purchase/upgrade of the product as they normally would do. As of now, we are forced to use Vanilla AutoCAD as we have in-house discipline specific menus and associated programs.

I am sorry to have started the New Year in a rebellion mood. But we really wish to see such a product available in the industry. Please note that the above views and opinions are my personal ones and those don't reflect the views or policies of the company I am working for. I take this opportunity to wish you a happy and prosperous new year. May the New Year make our dreams (including the CAD related ones ;-) come true...!! Many thanks to all you people for visiting my blog.