CADImporterDLL in VB6.0

Discuss and ask questions about CAD DLL (CAD Image DLL, CAD Importer DLL).

Moderators: SDS, support, admin

Post Reply
fconfort
Posts: 9
Joined: 03 Dec 2006, 17:44

CADImporterDLL in VB6.0

Post by fconfort » 03 Dec 2006, 18:00

Enumerating via
hEntities=DXFGetSection(hDXF,CS_ENTITIES,dataEntity)
only returns minimal data when iterating with
DXFGetChild(hEntities, i , dataEntity)
(only Tag is returned)
even a subsequent call to DXFGetData does not fill out dataEntity

See code fragment below

Public Sub EnumEntities(hDXF As Long)
Dim hEntities As Long
Dim hEntity As Long
Dim lRet As Long
Dim sLayer As String
Dim lEntityCount As Long
Dim dataEntity As Data

If hDXF <> 0 Then
hEntities = DXFGetSection(hDXF, CS_ENTITIES, dataEntity)
lEntityCount = dataEntity.Count
For i = 0 To lEntityCount
hEntity = DXFGetChild(hEntities, i, dataEntity)
lRet = DXFGetData(hEntity, dataEntity)
Next i
End If
End Sub

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

Post by support » 05 Dec 2006, 19:18

Hello!

Thank you for the question.
Functions <b>DXFGetSection</b>, <b>DXFGetChild</b> and <b>DXFGetData</b> are left for compatibility with previous versions of <b>CADImporter.DLL</b>.
We recommend to use function <b>DXFEnum</b>.

Sergey.


please post questions to the forum or write to support@cadsofttools.com

fconfort
Posts: 9
Joined: 03 Dec 2006, 17:44

Post by fconfort » 06 Dec 2006, 01:31

Sergey,
I was investigating DXFGetSection, DXFGetChild and DXFGetData as a means to getting more detailed data from Light Weight Polylines.

I noticed that DXFEnum simply returns a list of short lines approximating the polyline.

Is there any way to retrieve node and bulge data or individual entity properties for entities making up polylines?

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

Post by support » 06 Dec 2006, 18:30

Hello!

Normally POLYLINE entity is returned as a row of lines. <b>CADImporter.DLL</b> gets lines (and arcs) that POLYLINE consists of, takes into account POLYLINE's line type and creates a row of DXFPOINT points. Pairs of these points form polyline.
There is no need to ****yze bulges etc. LPDXFPOINT DashDots contains already made polyline prepared for easy drawing.
Note: <b>CADImporter.DLL</b> never returns bulges.

<b>CADImporter.DLL</b> allows splitting lines and arcs from the POLYLINE to the separate entities:

The <b>DXFProhibitCurvesAsPoly</b> function defines conversion mode for polylines and for rotated ellipses and arcs.

int DXFProhibitCurvesAsPoly(
<font color="blue">HANDLE</font id="blue"> <b>hObject</b>,
<font color="blue">int</font id="blue"> <b>nCheckNumber</b>
);

Parameters
<i>hObject</i>
Identifies a CAD drawing object handle.
<i>nCheckNumber</i>
Specifies a mode of the conversion.

1. If <i>nCheckNumber</i> = 0 then incoming polyline is splitted to a row of lines and arcs. Starting the row entity contains DXF_BEGIN_POLYLINE tag in DXFDATA structure. Then entities go with DXF_ARC and DXF_LINE tags. Starting the row entity contains DXF_END_POLYLINE tag.

If <i>nCheckNumber</i> = 1 then polyline is returned as an entity with DXF_POLYLINE tag in DXFDATA structure and with a row of DXFPOINT points in DashDots. Pairs of these points form polyline.

2. If <i>nCheckNumber</i> = 0 then it is prohibited to convert DXF_ELLIPSE to DXF_POLYLINE and <b>Ratio</b> specifies ratio of minor axis to major axis, <b>Point1</b> specifies center point, <b>Point2</b> specifies endpoint of major axis, relative to the center. <b>Point3</b>, <b>Point4</b> specify start point and endpoint of elliptic arc. If <b>Point3</b> and <b>Point4</b> are equal then entity is ellipse else it is elliptic arc.

If <i>nCheckNumber</i> = 1 then DXF_ELLIPSE is converted to DXF_POLYLINE.

Return values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call <b>DXFGetLastError</b>.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

fconfort
Posts: 9
Joined: 03 Dec 2006, 17:44

Post by fconfort » 06 Dec 2006, 21:30

Hello Sergey,

I tried using DXFProhibitCurvesAsPoly(hObject,nCheckNumber)as you suggested, however I still get the same behavior regardless of the setting of nCheckNumber to 0 or 1.

I cannot see a DXF_BEGIN_POLYLINE tag for a Polyline entity only DXF_POLYLINE tag is received with an array of points.

Any suggestions?

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

Post by support » 07 Dec 2006, 18:45

It is necessary to dd the following lines to the <b>DemoVB</b> in the ..\cadimporterdll\DemoVB\.. folder of the <b>CADImporter.DLL</b> package (available at: http://www.cadsofttools.com/download/cadimporterdll.zip):
<b>Module1.bas</b>

Code: Select all

...
<font color="blue">Public Function DoPaint</font id="blue">(<font color="blue">ByRef</font id="blue"> EData <font color="blue">As </font id="blue">Data, Param <font color="blue">As Long</font id="blue">) <font color="blue">As Long</font id="blue">
...
    <font color="blue">Select Case</font id="blue"> EData.Tag
    <font color="blue">Case</font id="blue"> DXF_BEGIN_POLYLINE
      MsgBox "BeginPolyline"
    <font color="blue">Case</font id="blue"> DXF_END_POLYLINE
      MsgBox "EndPolyline"
...
<b>Form1.frm</b>
...

Code: Select all

<font color="blue">Private Declare Function</font id="blue"> DXFProhibitCurvesAsPoly <font color="blue">Lib</font id="blue"> "CADImporter.dll" (<font color="blue">ByVal</font id="blue"> HANDLE <font color="blue">As Long</font id="blue">, <font color="blue">ByVal</font id="blue"> Untis <font color="blue">As Long</font id="blue">) <font color="blue">As Long</font id="blue">
...
add new main menu items:
<b>Arcs As Curves</b>

Code: Select all

<font color="blue">Private Sub</font id="blue"> As_Curves_Click()
   <font color="blue">If</font id="blue"> dxf <> 0 <font color="blue">Then</font id="blue">
     DXFProhibitCurvesAsPoly dxf, 0
     Form_Paint
   <font color="blue">End If
End Sub</font id="blue">
<b>Arcs As Poly</b>

Code: Select all

<font color="blue">Private Sub</font id="blue"> As_Poly_Click()
   <font color="blue">If</font id="blue"> dxf <> 0 <font color="blue">Then</font id="blue">
     DXFProhibitCurvesAsPoly dxf, 1
     Form_Paint
   <font color="blue">End If
End Sub</font id="blue">
Sergey.

please post questions to the forum or write to support@cadsofttools.com

fconfort
Posts: 9
Joined: 03 Dec 2006, 17:44

Post by fconfort » 08 Dec 2006, 18:03

Sergey,
Thanks for your quick response.

What was causing me grief was the function prototype:

Private Declare Function DXFProhibitCurvesAsPoly Lib "CADImporter.dll" (ByVal HANDLE As Long, ByVal Untis As Long) As Long

I did not have the critical ByVal for parameter Untis.

After correcting this problem I encountered a problem with the ArcDraw function provided with the Demo.

It seems point parameter 2 which is passed to ArcDraw is actually a scaler value representing the Radius of the arc.
As such it should not be converted with the Vector Transformation function GetPoint.

The version of ArcDraw provided below and the support function
GetScaler seems to be working just fine.

Public Sub DrawArc(HDC As Long, dataEntity As Data)
Dim ptCenter As POINTAPI
Dim lRadius As Long
Dim ptEnd As POINTAPI
Dim ptStart As POINTAPI

ptCenter = GetPoint(dataEntity.Point1)
lRadius = GetScaler(dataEntity.Point2) 'X coordinate is Radius of Arc
ptStart = GetPoint(dataEntity.Point3)
ptEnd = GetPoint(dataEntity.Point4)
If ((dataEntity.Point3.X <> dataEntity.Point4.X Or dataEntity.Point3.Y <> dataEntity.Point4.Y) _
And (ptStart.X = ptEnd.X) And (ptStart.Y = ptEnd.Y)) Then
SetPixel HDC, ptStart.X, ptStart.Y, lColor
Exit Sub
End If
Arc HDC, lLeft:=ptCenter.X - lRadius, lTop:=ptCenter.Y - lRadius, _
lRight:=ptCenter.X + lRadius, lBottom:=ptCenter.Y + lRadius, _
lStartX:=ptStart.X, lStartY:=ptStart.Y, _
lEndX:=ptEnd.X, lEndY:=ptEnd.Y
End Sub

Function GetScaler(ptDXF As DXFPOINT) As Long
GetScaler = ptDXF.X * (Form1.GetScale / 100)
End Function

Thanks again for your help

fconfort

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

Post by support » 08 Dec 2006, 18:36

Hello,

Please try the following:
<b>Module1.bas</b>

Code: Select all

<font color="blue">Dim</font id="blue"> ArcsAsPoly <font color="blue">As Boolean</font id="blue">

...

<font color="blue">Public Sub</font id="blue"> DrawArc(HDC <font color="blue">As Long</font id="blue">, EData <font color="blue">As Data</font id="blue">)
<font color="blue">Dim</font id="blue"> Massiv(0 <font color="blue">To</font id="blue"> 3) As POINTAPI
<font color="blue">Dim</font id="blue"> Pt <font color="blue">As</font id="blue"> POINTAPI
<font color="blue">Dim</font id="blue"> Pt1 <font color="blue">As</font id="blue"> POINTAPI
<font color="blue">Dim</font id="blue"> CADPoint <font color="blue">As</font id="blue"> dxfPoint
<font color="blue">Dim</font id="blue">MajorLength <font color="blue">As</font id="blue"> Double
<font color="blue">Dim</font id="blue">Rect <font color="blue">As</font id="blue"> RECTAPI
<font color="blue">Dim</font id="blue">Ratio <font color="blue">As Double
    If Not</font id="blue"> ArcsAsPoly <font color="blue">Then
      If</font id="blue"> EData.Var1(16) = 1 <font color="blue">Then</font id="blue">
        Ratio = GetSingleFromBytes(EData.Var1(12), EData.Var1(13), EData.Var1(14), EData.Var1(15))
        Pt = GetPoint(EData.Point1)
        CADPoint.X = EData.Point1.X + EData.Point2.X
        CADPoint.Y = EData.Point1.Y + EData.Point2.Y
        CADPoint.Z = 0
        Pt1 = GetPoint(CADPoint)
        Massiv(2) = GetPoint(EData.Point3)
        Massiv(3) = GetPoint(EData.Point4)
        MajorLength = Sqr(((Pt1.X - Pt.X) ^ 2) + ((Pt1.Y - Pt.Y) ^ 2))
        Rect.TopLeft.X = Pt.X - MajorLength
        Rect.TopLeft.Y = Pt.Y - MajorLength * Ratio
        Rect.BottomRight.X = Pt.X + MajorLength
        Rect.BottomRight.Y = Pt.Y + MajorLength * Ratio

        Arc HDC, Rect.TopLeft.X, Rect.TopLeft.Y, Rect.BottomRight.X, Rect.BottomRight.Y, Massiv(2).X, Massiv(2).Y, Massiv(3).X, Massiv(3).Y
        <font color="blue">End If
      Else</font id="blue">
      Massiv(0) = GetPoint(EData.Point1)
      Massiv(1) = GetPoint(EData.Point2)
      Massiv(2) = GetPoint(EData.Point3)
      Massiv(3) = GetPoint(EData.Point4)
      <font color="blue">If</font id="blue"> (((EData.Point3.X <> EData.Point4.X) Or (EData.Point3.Y <> EData.Point4.Y)) And (Massiv(2).X = Massiv(3).X) And (Massiv(2).Y = Massiv(3).Y)) <font color="blue">Then</font id="blue">
        SetPixel HDC, Massiv(2).X, Massiv(2).Y, Color
        <font color="blue">Exit Sub
      End If
    End If</font id="blue">
    Arc HDC, Massiv(0).X, Massiv(1).Y, Massiv(1).X, Massiv(0).Y, Massiv(2).X, Massiv(2).Y, Massiv(3).X, Massiv(3).Y
<font color="blue">End Sub</font id="blue">
<b>Form1.frm</b>

Code: Select all

<font color="blue">Private Sub</font id="blue"> As_Curves_Click()
   <font color="blue">If</font id="blue"> dxf <> 0 <font color="blue">Then</font id="blue">
     Cls
     DXFProhibitCurvesAsPoly dxf, 0
     Form_Paint
     ArcsAsPoly = <font color="blue">False</font id="blue">
     As_Poly.Checked = <font color="blue">False</font id="blue">
     As_Curves.Checked = <font color="blue">True
   End If
End Sub

Private Sub</font id="blue"> As_Poly_Click()
   <font color="blue">If</font id="blue"> dxf <> 0 <font color="blue">Then</font id="blue">
     Cls
     DXFProhibitCurvesAsPoly dxf, 1
     Form_Paint
     ArcsAsPoly = <font color="blue">True</font id="blue">
     As_Curves.Checked = <font color="blue">False</font id="blue">
     As_Poly.Checked = <font color="blue">True
   End If
End Sub</font id="blue">
Sergey.

please post questions to the forum or write to support@cadsofttools.com

Post Reply