Reputation: 620
I am working on drawing dxf files in Java. So far I am able to draw, LINES
, POLYLINES
, TEXT
, CIRCLE
, ARC
, LWPOLYLINES
.
But I am having problems on drawing INSERT
entities. I know this is mapped to block entities but when I draw them nothing get displayed. I understand you have to do some transformation on INSERT
entities but I have no idea how to do that. I Googled a lot about this but no luck. So I hope you can give some direction how to process the INSERT
entities. I also looked at some frameworks like ycad and dxf-code but that code is difficult to trace.
What is the algortihm for translation INSERT
to entities like LINE
and ARC
Thanks
Johan
Upvotes: 0
Views: 2448
Reputation: 16015
The BLOCK
entity (otherwise known as a Block Definition) is essentially the 'blueprints' for an INSERT
(otherwise known as a Block Reference).
Rather than duplicating all of the geometric information constituting the block for every block reference in a drawing, the block definition (BLOCK
entity) is a 'template' for each block reference, meaning that only the position, rotation & scale of each block reference need be stored.
The Block Definition resides within the Block Symbol Table and is comprised of a BLOCK
header entity (defining the block name and origin (usually 0,0) among other properties), followed by all geometry forming the block definition, and finally a terminating ENDBLK
entity.
All geometry contained within the Block Definition is defined relative to the origin of the Block Definition; then, when a Block Reference (INSERT
) is created, the Block Definition geometry is transformed relative to the insertion point of the Block Reference.
Upvotes: 0
Reputation: 19107
It is hard to provide you a definitive answer because we see no code. But the way INSERT
features are managed is described on the AutoDesk website. Here is the information for blocks in DXF files.
It also provides information about two important entries BLOCK
and ENDBLCK
.
Here is an example of a block that has a LINE
and an ARC
in it. The block will look like this:
The block is called SAMPLE:
0
BLOCK
8
0
2
SAMPLE
70
0
10
0.0
20
0.0
30
0.0
3
SAMPLE
1
0
ARC
5
263
8
0
10
0.0
20
22.4468613708478415
30
0.0
40
242.9028467109147016
50
354.6976825438280798
51
185.3023174561718918
0
LINE
5
264
8
0
10
-241.8634560136443099
20
0.0000000000001137
30
0.0
11
241.8634560136443099
21
-0.0000000000002274
31
0.0
0
ENDBLK
5
262
8
0
Basically, you have an entry which defines the block entities. It will have an origin and all the values are relative to the origin for the elements.
If you design it first then you will know what to do.
Once you have the BLOCK
defined you will be able to use it as an INSERT
.
The BLOCK
itself. The key is the origin. Most are defined with a coordinate of 0,0,0. Then the ENTITIES
are drawn relative to this origin for a scale of 1:1.
Imagine a rectangle that is 1 unit square for the scale factor of one. Then the coordinates would be:
-0.5, 0.5
0.5, 0.5
0.5, -0.5
-0.5, -0.5
I hope this information helps you.
Upvotes: 3