Examples

  1. FAQ
  2. »
  3. Products Overview
  4. »
  5. Examples

How to copy objects in Databases?

To learn more about deep cloning , refer to the topics in this section use this linkHere you can find simple application .

 

 

How to get object property during importing a dwf file?

Sample Components/Dwfdb/Examples/OdDwfLoad does dumping of properties if you executes it with key -D .

How to add a hyperlink to an MTEXT entity?

OdWriteEx sample contains creating a circle with hyperlink. Search DbFiller.cpp for "hyperlink".

Here is sample code for creating MTEXT with hyperlink in field. Code:

OdDbMTextPtr pMText = OdDbMText::createObject();
  pMText->setDatabaseDefaults(pRecord->database());
  pRecord->appendOdDbEntity(pMText);

  /**********************************************************************/
  /* Set some properties                                                */
  /**********************************************************************/

  pMText->setLocation(point);
  pMText->setTextHeight(0.2);
  pMText->setAttachment(OdDbMText::kTopLeft);
  pMText->setContents(OD_T("Sample Hyperlink"));
  pMText->setWidth(w * 7.0 / 8.0);
  pMText->setTextStyle(styleId);
  
  OdDbFieldPtr pTextField3 = OdDbField::createObject();
  OdDbFieldPtr pField3_1 = OdDbField::createObject();

  OdDbObjectId textFldId3 = pMText->setField(OD_T("TEXT"), pTextField3);
  OdDbObjectId fldId3_1 = pTextField3->setField(OD_T(""), pField3_1);

  pField3_1->setEvaluationOption(OdDbField::kAutomatic);
  OdString fc6(OD_T("\\AcVar \\href \"http://forum.opendesign.com/showthread.php?14172-How-do-I-add-a-hyperlink-to-an-MTEXT-entity##Open Design Alliance Forum > Teigha, C++ version#0\""));
  pField3_1->setFieldCode(fc6);

  OdDbEntityHyperlinkPEPtr    hpe = pField3_1;
  OdDbHyperlinkCollectionPtr  urls = hpe->getHyperlinkCollection(pField3_1);
  
  urls->addTail(L"http://forum.opendesign.com/showthread.php?14172-How-do-I-add-a-hyperlink-to-an-MTEXT-entity##ForumLink#0\"", 
    L"Open Design Alliance Forum > Teigha, C++ version");
  
  hpe->setHyperlinkCollection(pField3_1, urls);

  pTextField3->setEvaluationOption(OdDbField::kAutomatic);
  OdString fc7(OD_T("HyperLink sample %<\\_FldIdx 0>%"));
  pTextField3->setFieldCode(fc7, OdDbField::FieldCodeFlag(OdDbField::kTextField | OdDbField::kPreserveFields));

  pField3_1->evaluate(OdDbField::kAutomatic);

How to debug ODA .NET application?

Currently we provide examples as release build config, if you need debug config you need create Debug Config manually. Please note, that in order to create Drawings.NET debug configuration you need Kernel and Drawings release archives (i.e. "amd64dll" for example).

  1. Create new configuration "Debug" from Release config. You need change build configuration and rebuild the solution:
     debug

     

  2. Project Properties -> Select Tab "Build" -> Unselect "Optimize code".
  3. Project Properties -> Select Tab "Build" -> Click button "Advanced" -> Change field "Debug Info" from "none" to "full".
  4. Project Properties -> Select Tab "Build" -> Field "Output path" -> Copy from release configuration (for e.x:....\exe\vc15_amd64dll)

     

    debug

Which filetypes are supported for DGN reference files?

At the moment we support reference attachments to DXF/DWG and to DGN files. And also we support raster attachments to image files and pdf files.

Do you have any sectioning samples ?

Sectioning samples are present in our sample applications. Also some additional info can be found in the documentation.

How to compute extents for model space?

See AbstractViewPE.h. This protocol extension can be applied to OdDbViewport, OdDbViewportTableRecord, OdDbViewTableRecord.

You can find sample code in Kernel/Examples/Exports/RasterExport. AbstractViewPE in its zoomExtents() and viewExtents() takes into account only visible geometry honoring layers state (if layer is off or frozen).

Do you have any library support to generate 2d .dwg floor plans from ifc files?

In Visualize library you can convert ifc to .vsf and then from .vsf to .dwg. An example of how you can do this is located in /Examples/Ifc2Visualize and /Extensions/Visualize2Dwg

Where I can find information about plot drawings?

For plotting options you can refer to the example in Drawings SDK archive in Drawing\Examples\Qt\OdaQtPlotSettingsValidator.

When using OdCopyEx.cpp to convert the CAD file version, the out of memory dialog box pops up, and the code throws an exception when readFile.

Dwg file format is highly compressed and drawing occupied much more memory than file size.
Memory limit for 32-bit application is 2G. 64-bit application has no such limitation.
In some scenarios partial loading and paging can reduce memory usage but saving drawing to file require that all data is loaded into memory.

How to ''embed'' images in the drawing?

You can embed image as OLE entity. See /Drawing/Examples/ExCommands/ExInsertRaster.cpp

How do I read in OBJ file data?

The main module project is placed in the Components/OBJToolkit folder. The header file with all needed methods declarations is OBJToolkit.h. To import the .obj file, create an OdObjImport object, call the method importFile and you'll have access to groups and geometrical objects of OdObjDb:

OdObjImportPtr pObjImporter = OBJToolkit::createObjImporter();
pObjImporter->importFile(filePath, &importOptions);
OdObjDbPtr pObjDb = pObjImporter->getObjDb();

The import sample is in the Obj2Visualize project of Components/Examples, and it can be tested in Components/Visualize/Examples/Visualize Viewer (File->Open->Obj).

An example of exporting .dwg to .obj is located in the Drawing/Examples/ExCustObjs project (in the function called _OBJExport_func). This is the OBJExport command of the OdaMfcApp sample application. Another example of exporting into OBJ from Visualize is in Visualize Viewer on the File->Export->Obj menu.

Can we get direct polylines like startPoint and EndPoint of dimension/leader/extension lines?

A dimension entity has the method OdDbObjectId dimBlockId(). A block contains all dimension geometry. If any dimension property is changed, this block is recomputed.

You can get simple entities such as lines, multiline text, etc. by iterating through the dimension block.

We need the text string in the form of polylines matching the exact font type used in a .dwg file. Is there a way to get such polylines?

See the implementation of the TxtExp command in Drawings/Examples/ExCommands/ExTxtExp.cpp. It converts text to polylines and arcs.

Is the source code for ODA File Converter available?

You can find this example source code in the Drawings archive: Drawings_XX\Drawing\Examples\Qt\OdaFileConverter.

Can you provide ODA sample code in C# (for how to create circles, arcs, etc.)?

See Drawings.NET\Swig\SwigODAExamples\Drawings\NetFramework\OdReadExSwigMgd\DbFiller.cs.

Are there command line examples that support Windows and Linux operating systems (.deb) for converting .dwg/.dxf files into .dwg/.dxf/.svg/.png files?

ODA SDKs support numerous formats. Drawings SDK provides native support for .dwg/.dxf file formats and a set of various exports and imports. The Drawings SDK archive includes a set of samples that work at the command line. Here are a few examples related to converting files:

  • OdCopyEx — Loads a .dwg/.dxf file of any version and saves it to a .dwg/.dxf file of any version.
  • OdDwfExport — Loads a .dwg/.dxf file and exports its content to a .dwf file.
  • OdColladaExport — The same, but the output is a Collada file.
  • OdPdfExport — Also the same, but the output is a .pdf file.
  • OdSvgExport — Also the same, but the output is an .svg file.
  • And more.

How do I regen in WPF?

The implementation is:

m_pDevice->invalidate();
if(m_pDevice->gsModel())
m_pDevice->gsModel()->invalidate(OdGsModel::kInvalidateAll);

where m_pDevice is a derivative of the OdGsDevice class.

How do I get geometry from an entity?

See the OdGetGeomEx sample project: \Drawing\Examples\OdGetGeomEx.

What are the differences between OdaMfcApp and ODA Viewer?

  • OdaMfcApp can use the various rendering devices (WinGDI, Silicon Graphics OpenGL®®, Microsoft® DirectX®, Bitmap, GLES2). ODA Viewer uses OpenGL.
  • OdaMfcApp can enable or disable the graphics cache (Tools->Options->Use GS model). ODA Viewer can't disable this option.