-2

I am trying to retrieve entities only from particular view of a DXF file.

The VIEWPORT class doesn't help to separate views.

Help me to solve this out.

Thanks in advance

Lee Mac
  • 15,615
  • 6
  • 32
  • 80

2 Answers2

2

In general, for arbitrary viewports & target objects, this is a relatively difficult problem.

The solution can be reduced to calculating the boundary of the viewport relative to WCS, and then determining which entities reside either entirely within or partially within the calculated boundary.

The boundary can be calculated by obtaining the boundary vertices of the viewport (with respect to Paperspace), and then transforming such vertices using a transformation matrix constructed using the scale (or view height), rotation (or twist angle), and normal vector, and viewport center.

  • The scale can be calculated by dividing DXF group 45 (height w.r.t. Modelspace) by DXF group 41 (height w.r.t Paperspace).

  • The rotation can be obtained from DXF group 51 (view twist angle).

  • The normal vector can be obtained from DXF group 16 (WCS view direction vector).

  • The center can be obtained from DXF group 10 (WCS center point)

Upon calculating the boundary coordinates, you'll then need to calculate the extents of all Modelspace geometry (or just the rectangular bounding box, depending on the accuracy you require), and determine whether any portion of the geometrical extents falls within the calculated viewport boundary.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • Is it possible to identify the layer in which the drawing is present? because, while retrieving entities table lines, margin lines and projection circles were also got retrieved. Is it possible to eliminate those. – karthik Dec 27 '19 at 05:10
  • Not directly - you could count the number of objects in Modelspace residing on each layer and take an educated guess, but this is a risky approach and not something that I would recommend. – Lee Mac Dec 27 '19 at 11:54
0

I also needed to find the model space entities for a given paper space viewport, here is what I have found so far:

  • DXF Groups 10,20: Paper space center point in WCS
  • DXF Groups 12,22: View center point in DCS
  • DXF Groups 17,27: View target center point in WCS

The model space viewport center point appears to be just a vector sum of groups (12,22) and groups (17,27).

Once I found the model space view center point, I can find all the model space entities using the viewport width and height groups (40,41) and scale groups (41/45).

Have tried this method on many dxf files and it worked very well.

atsu
  • 81
  • 7