CADViewer, with it’s flexible design and use of standard toolkits, can be integrated with any Database Management Application and be used with a multitude of custom data-driven applications.
This Tutorial - Retain AutoCAD Handles
This tutorial will illustrate how to extract, store and interact with entities in drawings based on their AutoCAD and MicroStation Drawings Handle ID. The steps outlined below can be tested online using our Online Test Sample developed specifically for this guide.
Extract Handles from a Drawing using AutoXchange 2024
An automated process in AutoXchange 2024 will retain all AutoCAD Handles in conversion from DWG to SVG, whereafter CADViewer can use it’s event handler API to make Handles interactive objects.
The process can be done directly using the AutoXchange command line interface, or it can be done interactively using CADViewer.
Creating hotspots server side with AutoXchange ahead of time instead of doing an on-the-fly conversion from CADViewer can save valuable time and computing resources, especially with very large files. For small and medium sizes drawings the execution time does not differ much using on-the-fly conversion compared to conversion ahead of time.
Since the conversion process retaining Handles in AutoXchange 2024, also creates a .csv file with a list of Handles in the processed file, we will make a stand-alone conversion to access this data.
The process to create an SVG file with handles ahead of time, can be done on both Windows and Linux.
It is illustrated with Windows below, but the process is similar on Linux.
Please Download CADViewer and AutoXchange 2024 and follow general install instructions.
1: Download the reference dwg file one_of_simple.dwg.
2: Navigate to the install folder of AutoXchange 2024:
3: In AutoXchange 2024 folder, check that the AutoXchange 2024 is running properly:
4: Build the command line, where the following AutoXchange 2024 commands that needs to be used are:
- -i= : input file name, this can also include path
- -o= : output file name, this can also include path
- -f=svg : output format, this must be specified to SVG
- -model : set the conversion to based on the Model Space, which contains all entities of the drawing
- -hlall : specify the converter to process all entities in the drawing, so handles are preserved
The reference drawing one_of_simple.dwg contains instances of the mostly used AutoCAD Entities.
5: Execute the command line.
\xampp\htdocs\cadviewer\converters\ax2020\windows>ax2020 -i="one_of_simple.dwg" -o="one_of_simple.svg" -f=svg -hlall
6: An SVG file with handles is now generated as part of the covnersion process. The CSV file one_of_simple.csv contains a table of all Entities, their Handles and if they have any Block associations.
Add .csv file with Handles to a Database
There are tools to automatically import .csv files into a database structure, and in a production environment tables will be set up for multiple files, but for the purpose of this demo, we are doing it manually through the PHPAdmin interface:
1: Navigate to http://localhost/phpmyadmin :
2: Create a new table cadviewer_handles_public_demo
3: Import .csv file one_of_simple.csv
4: Rename the import table table 1 to one_of_simple
5: Change structure in table so COL 1 is renamed to CV_ID Varchar 100, COL 2 is renamed to Handle Varchar 100, COL 3 is renamed to Entity Varchar 100 and COL 4 is renamed to Blocks Varchar 100.
6: Change structure in table and add CustomGroup1 as Varchar 100 after Blocks. Add an index column at the beginning of the table.
7: Group a few entities together by giving them the same group name GroupXX in the CustomGroup1 column.
Access the database content from PHP
1: In a text editor, open the file cadviewer_handles_public_demo.php
2: Do SQL calls to load the Handles, Entities and any CustomGroup1 values and pass over to CADViewer
Set up the Event Handers in CADViewer
In the CADViewer html file for this sample CADViewer_acadhandle_mysql_620.html, we enable all API event handlers to capture interaction with AutoCAD Handles. Note that we in cvjs_click() tells to update the SQL ScrollBar vqUpdateScrollbar(handle) with the handle ID.
Link Database calls with Highlight of Handle Objects
In the CADViewer code in this sample CADViewer_acadhandle_mysql_620.html, we use an AngularJS implementation of the left sidebar, but this can be done by any other technology. We pull the MySQL content from cadviewer_handles_public_demo.php, and do some specific group processing and display it.