Loading DWG models
HOOPS Visualize is able to load DWG models using the RealDWG integration. You must be a RealDWG licensee in order to use the interface. DWG is only available on Windows platforms. See the release notes for platform-specific information. DXF files are also supported.
The Sprockets DWG module is used to read DWG and DXF files through the Autodesk's RealDWG API. Once the file has been imported, the integration creates a component tree with support for a model browser. The user is then able to query the model either through the component structure, the HPS scene graph, or directly through RealDWG. Data mapping is achieved through the HPS::DWG::Component class, which lets the user access the AcDbObjectId object associated with each component, which in turn can be used with the RealDWG API.
RealDWG is initialized after the HPS::World constructor has been called, at which point you can make function calls to RealDWG. RealDWG becomes uninitialized during the Visualize shutdown procedure. After the shutdown begins, you can no longer make calls to RealDWG.
The steps for loading DWG/DXF models are delineated below:
Step 1: Get RealDWG
In order to use the RealDWG functionality, you must install the native RealDWG libraries. If you have licensed RealDWG through Tech Soft 3D, you may download the package from our Developer Zone. The supported version of the RealDWG SDK is noted in the release notes. The RealDWG DLLs must be distributed with your application.
Step 2: Include RealDWG header
To utilize the RealDWG importer, you need to include sprk_dwg.h in your source.
Step 3: Add RealDWG to your PATH
In order to use DWG, it's necessary to add the RealDWG directory to your machine's PATH. If you're using RealDWG Object Enablers (optional), then also make sure that the directory containing the DBX files for the Object Enablers is located in your PATH prior to initializing HPS.
To import RealDWG files, HOOPS Visualize uses the same basic framework as it does for other file types. The main difference is the use of functions from the HPS::DWG container class.
The DWG import options can have a significant effect on the load time of certain models:
- SetMaxTessellationDeviation - This option specifies how finely to tessellate shells and meshes imported through DWG. Smaller numbers create more detailed and complex geometry.
- SetUnreferencedRecords - This option specifies whether to import parts of the drawings which are present, but not referenced in the model. Turning this off can result in a faster import.
If your model contains textures, and those textures are stored in an unusual location, you can specify the texture directory in the import options kit using SetTextureDirectories.
The Sprocket DWG module builds a component structure as it imports a DWG file. DWG components can be one of the following types:
- DWGModelFile - The top of the hierarchy. Represents an AcDbDatabase object in RealDWG.
- DWGBlockTable - The block table. This is always found directly under the DWGModelFile. Represents an AcDbBlockTable object in RealDWG.
- DWGLayerTable - The layer table. This is always found directly under the DWGModelFile. Represents an AcDbLayerTable object in RealDWG.
- DWGLayout - A DWG Layout. Found under the DWGBlockTable. Represents an AcDbLayout object in RealDWG.
- DWGBlockTableRecord - A record inside the Block Table. Found under the DWGBlockTable. Represents an AcDbBlockTableRecord object in RealDWG.
- DWGLayer - A layer. Found under the DWGLayerTable. Represents an AcDbLayer object in RealDWG.
- DWGEntity - A geometric entity. Found under a DWGLayout or a DWGBlockTableRecord, or under another DWGEntity. Represents an AcDbEntity object in RealDWG.
You can ask a component what type it is by calling the Component::GetComponentType function. All DWG components have the DWGComponentMask set on them. Therefore, you can tell if a component is a DWGComponent because Component::HasComponentType(ComponentType::DWGComponentMask) will return true.
Working with layers
As an example of how to use the component type to operate on an object, we'll look at a code sample that deals with layers. Once you have identified that a component you are interested in is of type DWGLayer, you can build a DWG::Layer object with it. With a layer object, you can enable and disable visibility, or return the visibility status. Below is an example of doing this:
- ActivateDefaultLayout - This function activates the default Layout. It is equivalent to calling ActivateDefaultCapture.
- GetDWGDatabase - Returns the DWGDatabase pointer. The user can request the database to use it in RealDWG calls. The user should NEVER delete a database pointer it gets from this function.
- GetAllLayouts - Returns a list of layouts associated with this CAD model.
Here is an example of how to activate the default layout:
Getting an array of all layouts from the CAD model may be done in the following way:
Here is an example of how to get a DWGObjectID from the layout object, and using it with RealDWG:
Acquiring a reference to the DWG database
This is an example of getting and using the DWG database from a CAD model object:
WARNING: You should never try to delete a RealDWG database pointer!
Metadata is additional non-geometric information that is associated with an HPS::DWG::Component. Each piece of metadata is a name-value pair, and the values are always returned as HPS::StringMetadata.
You can ask for the following metadata by calling GetMetadata from any HPS::DWG::Component:
- "Name" - Either returns the name of the component, or if the component has no name returns a string formatted as follows: <RealDWG Entity Type> <RealDWG Handle>. Example: AcDbPolyline 1AB45.
- "Handle" - Returns the hexadecimal handle of the entity associated with the component.
- "Layer" - Returns the name of the layer associated to this component, if any.
- "Units" - Returns the units used in the drawing. Only available from the DWG CAD Model.
When multiline text is encountered, RealDWG explodes it into fragments. These fragments are not guaranteed to match those produced by AutoCAD. (Example: in a two line multi-line text, the last word of the first line might actually appear as the first word of the second line).
Line patterns containing glyphs and shapes
Line patterns containing glyphs and SHX shapes are not supported.