Web CAD API Updates

The latest DWG FastView WebCADAPI update introduces several key features to enhance CAD drawing management. Users can now extract block information and text elements from CAD files into TXT format, making it easier to handle and analyze data. The new text extraction function provides details like coordinates and layers, while users can control its activation through conversion parameters.

Additionally, the API supports writing annotations back to CAD drawings, allowing for updates using saved text files. A new conversion feature also enables DWF files to be transformed into DWG or OCF formats, with options for version control and format selection. These updates significantly improve functionality for CAD users, streamlining data extraction and integration processes.

Block Information Extraction

The new version has added the block extraction function, which can extract block information from CAD drawings to txt files, including block name, layer, attribute information, etc. Only need to provide the CAD drawing file stream or URL download address, you can extract block information.

The returned result is the download address of the txt file.

The data format in the txt file is as follows:

{
"entcounts":{
"AcDbBlockReference":2
},
"blockcounts":{
" Round Air Outlet":1,  //Block name and total number of block
"Air outlet":1  // Block name and total number of block
},
"xrefs":{
},
"layers":{  //Layer information
"10":{  //Layer handle
"name":"0",  //Layer name
"status":0,  //Layer status
"color":7, //Layer colour
"handle":"10", //Layer handle
"count":2
},
"2B0":{
"name":"C-HAVC-Outlet",
"status":0,
"color":16,
"handle":"2B0",
"count":2
},
"2B1":{
"name":"C-HAVC-HVAC equipment",
"status":0,
"color":16,
"handle":"2B1",
"count":1
}
},
"spaces":[{
"name":"*Model_Space",   // Layout dictionary name
"layout":"Model",  //Layout name
"handle":"1F",  //Layout handle
"entities":[],
"blocks":[{
"handle":"36BB",  //The handle of the block
"layer":"2B0",  //The layout handle of the block
"name":"Air outlet",  //Block name
"parent":"1F",  / The layout handle of the block
"position":[731121.705682, 1059970.188720, 0],  //Block base coordinates
"extMin":[730788.738739, 1059637.221777, 0],  //Block bounding box coordinate left
"extMax":[731454.672625, 1060303.155663, 0], //Top and bottom right coordinates
"scale":[-1, 1, 1],   //Scaling ratio of tile x、y、z
"angle":3.141593,  //Block rotation angle, the unit is radian
"atts":[], //Block attribute information
"dyn":true  //Dynamic block or not
}, {
"handle":"377F",
"layer":"10",
"name":"the round air outlet",
"parent":"1F",
"position":[732113.914672, 1059939.081392, 0],
"extMin":[731659.073369, 1059484.240089, 0],
"extMax":[732568.755975, 1060393.922695, 0],
"scale":[1, 1, 1],
"angle":1.047198,
"atts":[],
"dyn":false
}]
}, {
"name":"*Paper_Space",
"layout":"Layout 1",
"handle":"D2",
"entities":[],
"blocks":[]
}, {
"name":"*Paper_Space0",
"layout":"Layout 2",
"handle":"D6",
"entities":[],
"blocks":[]
}]
}

Text information extraction

The new text extraction function has been added, which can output all the text information in the drawings to txt files. The text files record the coordinates, layers, types and other information of each character. Users can process the text files by themselves to achieve functions such as text search, location, and statistics.

The installation and usage methods of the new version are the same as before. Only in the function of converting ocf, a txt parameter has been added. When it is False, the text extraction function is not activated, and it is the same as before. When it is True, the text information is extracted, and the download address of the txt file is included in the returned result.

The parameters introduction in the text file:

"space": {
"name": "*Model_Space", // The layout model name where the text is located
"handle": 31, //Layout handle
"entities": [
{
"handle": 72965, //Text handle
"layer": 16, // The handle of the layer where the text is located, corresponds to the handle in the layer information at the beginning of the txt file.
"texts": [
{
"content": "Document Number:XYD", //The content of the text
"box": [ // The coordinates of the bounding box where the text is located. The first two are the x and y coordinates of the top left corner of the rectangular bounding box, and the last two are the x and y coordinates of the lower right corner.
776.935514,
202.314079,
800.633838,
206.005699
],
"mask": 1 //The type of the text,
}
]
},

The enumeration of mask text types:
1,Single line text
2,Multi-line text
3,Annotation text
4,Table text
5,Text inside blocks
6,Text inside external references
7,Text inside Leader annotation
8,Attribute definition text
9,Text inside architectural AEC custom entities
10,Entities associated with hyperlinks

The front-end can use the coordinate values inside the box. The first two coordinates are the minimum values, and the last two coordinates are the maximum values. Call the bounding box positioning function to move the viewport to the location corresponding to the font.

const box = {
min: {
x: 776.935514,
y: 202.314079
},
max: {
x: 800.633838,
y: 206.005699
}
}
gstarSDK.focusToBox(box,true) //The front-end is positioned at the viewport location corresponding to the bounding box coordinates.

Write annotations back to the drawing

The new version has added an interface to write annotations back to the CAD drawing. The annotated graphics can be written back to the dwg format drawing, so that they can be viewed in the PC CAD software.

annotationStream、annotationUrl:The annotation stream file or annotation file download address requires storing the annotation strings in a text file. There is no limit on the file format, generally txt is sufficient.

dwgVersion:The recommended version format of the generated CAD drawings is version 3.

dwgVersion、fileUrl:The CAD drawing stream file or the drawing download URL address will be used to write annotations on the drawing.

According to the task id, you can the query returned results, where dwgUrl is the download address of the new drawing after the annotation is written.

DWF Drawing conversion

The new version adds a DWF drawing conversion and display function, which can convert DWF to DWG or directly to OCF format files.

dwg controls whether to generate dwg format drawings. The default is to generate dwgVersion is to control the generated dwg drawing version.

OCF is to control whether convert and generate to ocf file or not, the default is Not.

FileStream、fileUrl:dwf drawing download address and file stream

According to the task id, you can query the returned results, and the DWF converted results can be obtained.

Items is a list, because the dwf drawing may have multiple pages, then one page will be converted into a dwg or ocf, so there may be multiple.

allZip is a compressed package file, which will contain all the files in items, packaged into a compressed package, which can be downloaded directly and then decompressed, so there is no need to download them one by one in items.

The latest update to DWG FastView WebCADAPI enhances CAD drawing management by introducing new features such as block and text information extraction into TXT files, enabling easier data handling. Users can write annotations back to CAD drawings and convert DWF files into DWG or OCF formats, with options for version control. These improvements streamline the processes of data extraction, annotation, and file conversion, significantly benefiting CAD users.