ACAD units other than mm/inch

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
zrudic
Posts: 6
Joined: 09 Dec 2008, 14:21

ACAD units other than mm/inch

Post by zrudic » 13 Jan 2009, 15:01

We have CADImporter.dll embedded into our software for import of various vector graphics.
We need to automatically scale drawing according to units used in CAD files. As I couldn't find how to extract exact units from CADImporter.dll's functions/data structures (as I saw, it's only available to distinguish between mm and inch, probably based on "$MEASUREMENT 70 x" in DXF file), when reading DXF files I used peace of code:
Scale = 1;
f = fopen( AFileName, "r" );
if( f )
{
while( fgets( line, 80, f ) )
if( strstr( line, "$INSUNIT" ) )
break;
if( fscanf( f, "%d %d", & type, & code ) == 2 && type == 70 )
switch( code )
{
case 1: Scale *= 25.4; break; // inches
case 2: Scale *= 304.8; break; // feet
case 3: Scale *= 1609344; break; // miles
case 4: Scale *= 1; break; // millimeters
case 5: Scale *= 10; break; // centimeters
case 6: Scale *= 1E3; break; // meters
case 7: Scale *= 1E6; break; // kilometers
case 8: Scale *= 25.4E-6; break; // microinches
case 9: Scale *= 0.0254; break; // mils
case 10: Scale *= 914.4; break; // yards
case 11: Scale *= 1E-7; break; // angstroms
case 12: Scale *= 1E-6; break; // nanometers
case 13: Scale *= 0.001; break; // microns
case 14: Scale *= 100; break; // decimeters
case 15: Scale *= 1E4; break; // dekameters
case 16: Scale *= 1E5; break; // hektometers
case 17: Scale *= 1E12; break; // gigameters
case 18: Scale *= 1.49598E14; break; // astronomical units
case 19: Scale *= 9.4605284E18; break; // light years
case 20: Scale *= 3.08568025E19; break; // parsecs
}
fclose( f );
}
to find what units are used and what scale to use - default units (for unitless DXF file or any other file type that doesn't contain string "$INSUNIT") is mm. But what to do in case of DWG file that supports variety of units just like DXF, but is binary and doesn't contain string "$INSUNIT" ? Can you please send me format of DWG file (structure or offset to units tag or anything that I could use to find out what units are used). Or, even better, can you inform me if (and how) this can be extracted from CADImporter.DLL's functions/data structures for any CAD file type.

Best regards, Zoran Rudic

P.S.
In many sources on Internet they say that DWG format is unitless and speak about manual scaling when importing. Using AutoCAD 2008, I made test DWG file in mm units and saved it. Then opened it, changed units to cm and saved it with another name. Then I used EveryDWG.exe downloaded from http://www.opendwg.org/guestfiles and transfomed those DWG files to DXF files. First one contained lines:
...
$INSUNITS
70
4
...
while another contained
...
$INSUNITS
70
5
...
This (besides the fact that ACAD opens DWG files with correct settings for units) proves that DWG somehow contains information about used units. Question is: "How ?"

P.P.S.
From DwgFormatSpec13-2007.rtf downloaded also from http://www.opendwg.org/guestfiles, I found out that "INSUNITS" is BS (bitshort) found in "header variables section indicated by section-locator 0" that has the form:
Beginning sentinel
Size of the section (a 4 byte long)
Data (system variables and possibly other data at the beginning)
CRC (covers the stepper and the data)
Ending sentinel
Also the following 16 byte sentinel introduces this section:
0xCF,0x7B,0x1F,0x23,0xFD,0xDE,0x38,0xA9,0x5F,0x7C,0x68,0xB8,0x4E,0x6D,0x33,0x5F. After that introduction follows data, which are largely different for almost every ACAD version. Is there any "easier" way to extract this information (as I see, it should be separate C struct(s) and separate handling for every DWG version) ? Or could you please add this peace of information to all other informations you already extract from DWG header(s) in CADImporter.dll ? Thanks in advance.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: ACAD units other than mm/inch

Post by support » 13 Jan 2009, 17:16

Hello!

Unfortunately such functionality is unavailable in CADImporter.DLL v.6.1. For the moment it may be implemented as a special build for you. Please contact us via e-mail to info@cadsofttools.com accordingly to this question.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply