Jump to content

how to make region if the 3D points are non coplanar using vba


Recommended Posts

Posted

Hi All

 

I am working on auto cad back end vba how to make a region if the 3D points are non coplanar can any one help it is urgent

 

Thanka in Advance

Posted

The Region is a planar entity, though that plane can have any orientation.

 

Can you post an example file showing what you have to work with and what you would like to have as a result?

Posted
The Region is a planar entity, though that plane can have any orientation.

 

Can you post an example file showing what you have to work with and what you would like to have as a result?

 

 

for example

 

the points are

 

' Define the four coordinates of the face

point1(0) = 0#: point1(1) = 0#: point1(2) = 0#

point2(0) = 5#: point2(1) = 0#: point2(2) = 0#

point3(0) = 5#: point3(1) = 5#: point3(2) = 20#

point4(0) = 0#: point4(1) = 5#: point4(2) = 20#

 

then by using this points how to make a region using vba

Posted

This would be the format for those specific points. Conceivably, you will have to modify the process a bit to accommodate arbitrary points. You may also want to delete the temporary lines.

 

Sub RegionFromPts()

   
   Dim curves(0 To 3) As AcadEntity
   Dim point1(0 To 2) As Double
   Dim point2(0 To 2) As Double
   Dim point3(0 To 2) As Double
   Dim point4(0 To 2) As Double
   
     point1(0) = 0#: point1(1) = 0#: point1(2) = 0#
     point2(0) = 5#: point2(1) = 0#: point2(2) = 0#
     point3(0) = 5#: point3(1) = 5#: point3(2) = 20#
     point4(0) = 0#: point4(1) = 5#: point4(2) = 20#



   Set curves(0) = ThisDrawing.ModelSpace.AddLine(point1, point2)
   Set curves(1) = ThisDrawing.ModelSpace.AddLine(point2, point3)
   Set curves(2) = ThisDrawing.ModelSpace.AddLine(point3, point4)
   Set curves(3) = ThisDrawing.ModelSpace.AddLine(point4, point1)
   ' Create the region
   Dim regionObj As Variant
   regionObj = ThisDrawing.ModelSpace.AddRegion(curves)
   ZoomAll
   
End Sub

Posted
This would be the format for those specific points. Conceivably, you will have to modify the process a bit to accommodate arbitrary points. You may also want to delete the temporary lines.

 

Sub RegionFromPts()


   Dim curves(0 To 3) As AcadEntity
   Dim point1(0 To 2) As Double
   Dim point2(0 To 2) As Double
   Dim point3(0 To 2) As Double
   Dim point4(0 To 2) As Double

     point1(0) = 0#: point1(1) = 0#: point1(2) = 0#
     point2(0) = 5#: point2(1) = 0#: point2(2) = 10#
     point3(0) = 5#: point3(1) = 5#: point3(2) = 20#
     point4(0) = 0#: point4(1) = 5#: point4(2) = 30#



   Set curves(0) = ThisDrawing.ModelSpace.AddLine(point1, point2)
   Set curves(1) = ThisDrawing.ModelSpace.AddLine(point2, point3)
   Set curves(2) = ThisDrawing.ModelSpace.AddLine(point3, point4)
   Set curves(3) = ThisDrawing.ModelSpace.AddLine(point4, point1)
   ' Create the region
   Dim regionObj As Variant
   regionObj = ThisDrawing.ModelSpace.AddRegion(curves)
   ZoomAll

End Sub

 

 

ya it works fine

 

but if i give z values like above 0 ,10, 20, 30 then it is not working

Posted

All four points have to be on the same plane. I’m not sure what tolerance AutoCAD uses for the AddRegion method, but I imagine it is pretty tight (1.0000E-06 perhaps).

 

In lieu of a separate test for planarity, the fact that a region can not be made may be a good indication that the points are not planar.

 

Accommodating non planar points may require the use of 3D Polylines, or broken down to two triangular Regions.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...