Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
draftsight / opt / dassault-systemes / DraftSight / APISDK / Create_PolygonMesh_Example_VBA.htm
Size: Mime:
<html>

<head>
<title>Create PolygonMesh Example (VBA)</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
<meta name=MS-HKWD content="VBA examples">
<meta name=MS-HKWD content="VBA examples,PolygonMeshes">
</head>


<body>
<h1>Create PolygonMesh Example (VBA)</h1>

<p>This example shows how to create a PolygonMesh.</p>
<pre>'--------------------------------------------------------------
' Preconditions:
' 1. Create a VBA macro in a software product in which VBA is
'    embedded.
' 2. Copy and paste this example into the Visual Basic IDE.
' 3. Add a reference to the DraftSight type library,
'    <i>install_dir</i>\<b>bin\dsAutomation.dll</b>.
' 4. Open the Immediate window.
' 5. Start DraftSight and open a drawing document.
' 6. Run the macro.
'
' Postconditions:
' 1. A PolygonMesh is created and zoomed to fit.
' 2. All PolygonMesh parameters are printed to the Immediate
'    window.
'------------------------------------------------------------</pre>
<pre>Option Explicit</pre>
<pre>    Sub Main()
    </pre>
<pre>        'Connect to DraftSight application
        Dim dsApp As DraftSight.Application
        Set dsApp = GetObject(, &quot;DraftSight.Application&quot;)
        'Abort any command currently running in DraftSight 
        'to avoid nested commands
        dsApp.<b>AbortRunningCommand</b></pre>
<pre>        'Get active document
        Dim dsDoc As DraftSight.Document
        Set dsDoc = dsApp.<b>GetActiveDocument</b>()
        If dsDoc Is Nothing Then
            MsgBox (&quot;There are no open documents in DraftSight.&quot;)
            End
        End If</pre>
<pre>        'Get model space
        Dim dsModel As DraftSight.Model
        Set dsModel = dsDoc.<b>GetModel</b>()</pre>
<pre>        'Get Sketch Manager
        Dim dsSketchMgr As DraftSight.SketchManager
        Set dsSketchMgr = dsModel.<b>GetSketchManager</b>()</pre>
<pre>        'PolygonMesh parameters
        Dim coordinatesArray() As Variant
        coordinatesArray = Array(0#, 0#, -4#, -1.53073372946036, 0#, -3.69551813004515, _
         -2.82842712474619, 0#, -2.82842712474619, -3.69551813004515, 0#, -1.53073372946036, _
         -4#, 0#, 0#, 0#, 0#, -4#, _
         -0.76536686473018, -1.32565429614237, -3.69551813004515, -1.4142135623731, -2.44948974278318, -2.82842712474619, _
         -1.84775906502257, -3.20041258076506, -1.53073372946036, -2#, -3.46410161513776, 0#, _
         0#, 0#, -4#, 0.765366864730179, -1.32565429614237, -3.69551813004515, _
         1.41421356237309, -2.44948974278318, -2.82842712474619, 1.84775906502257, -3.20041258076506, -1.53073372946036, _
         2#, -3.46410161513776, 0#, 0#, 0#, -4#, _
         1.53073372946036, 0#, -3.69551813004515, 2.82842712474619, 0#, -2.82842712474619, _
         3.69551813004515, 0#, -1.53073372946036, 4#, 0#, 0#, _
         0#, 0#, -4#, 0.76536686473018, 1.32565429614237, -3.69551813004515, _
         1.4142135623731, 2.44948974278318, -2.82842712474619, 1.84775906502257, 3.20041258076506, -1.53073372946036, _
         2#, 3.46410161513775, 0#, 0#, 0#, -4#, _
         -0.765366864730179, 1.32565429614237, -3.69551813004515, -1.41421356237309, 2.44948974278318, -2.82842712474619, _
         -1.84775906502257, 3.20041258076506, -1.53073372946036, -2#, 3.46410161513776, 0#)
                
        Dim mVertexCount As Long
        mVertexCount = 6</pre>
<pre>
        Dim nVertexCount As Long
        nVertexCount = 5
        </pre>
<pre>        Dim coordinatesDoubleArray() As Double
	Dim nbrArrayElements As Long
        nbrArrayElements = (mVertexCount * nVertexCount) * 3
        ReDim coordinatesDoubleArray(nbrArrayElements - 1)</pre>
<pre>        Dim i As Long
        For i = 0 To (nbrArrayElements - 1)
            coordinatesDoubleArray(i) = coordinatesArray(i)
        Next i</pre>
<pre>        'Add PolygonMesh
        Dim dsPolygonMesh As DraftSight.PolygonMesh
        Set dsPolygonMesh = dsSketchMgr.<b>InsertPolygonMesh</b>(mVertexCount, nVertexCount, coordinatesDoubleArray)</pre>
<pre>        'Make PolygonMesh continuous from the last row to the first row
        dsPolygonMesh.<b>MClosed</b> = True</pre>
<pre>        'Zoom to fit
        dsApp.<b>Zoom</b> dsZoomRange_e.dsZoomRange_Fit, Nothing, Nothing</pre>
<pre>        'Print PolygonMesh properties
        PrintParameters dsPolygonMesh
    End Sub</pre>
<pre>    Sub PrintParameters(ByVal dsPolygonMesh As DraftSight.PolygonMesh)
        Debug.Print (&quot;Polygon mesh parameters...&quot;)</pre>
<pre>        'Print common entity parameters
        Debug.Print (&quot;Handle = &quot; &amp; dsPolygonMesh.<b>Handle</b>)
        Debug.Print (&quot;Color = &quot; &amp; dsPolygonMesh.Color.<b>GetNamedColor</b>())
        Debug.Print (&quot;Erased = &quot; &amp; dsPolygonMesh.<b>Erased</b>)
        Debug.Print (&quot;Layer = &quot; &amp; dsPolygonMesh.<b>Layer</b>)
        Debug.Print (&quot;LineScale = &quot; &amp; dsPolygonMesh.<b>LineScale</b>)
        Debug.Print (&quot;LineStyle = &quot; &amp; dsPolygonMesh.<b>LineStyle</b>)
        Debug.Print (&quot;LineWeight = &quot; &amp; dsPolygonMesh.<b>LineWeight</b>)
        Debug.Print (&quot;Visible = &quot; &amp; dsPolygonMesh.<b>Visible</b>)</pre>
<pre>        Dim x1 As Double, y1 As Double, z1 As Double
        Dim x2 As Double, y2 As Double, z2 As Double
        dsPolygonMesh.<b>GetBoundingBox</b> x1, y1, z1, x2, y2, z2
        Debug.Print (&quot;BoundingBox: &quot; &amp; x1 &amp; &quot;, &quot; &amp; y1 &amp; &quot;, &quot; &amp; z1 &amp; &quot;, &quot; &amp; x2 &amp; &quot;, &quot; &amp; y2 &amp; &quot;, &quot; &amp; z2)</pre>
<pre>        'Print PolygonMesh parameters
        Debug.Print (&quot;FitSmooth = &quot; &amp; dsPolygonMesh.<b>FitSmooth</b>)
        Debug.Print (&quot;NDensity = &quot; &amp; dsPolygonMesh.<b>NDensity</b>)
        Debug.Print (&quot;MDensity = &quot; &amp; dsPolygonMesh.<b>MDensity</b>)
        Debug.Print (&quot;NClosed = &quot; &amp; dsPolygonMesh.<b>NClosed</b>)
        Debug.Print (&quot;MClosed = &quot; &amp; dsPolygonMesh.<b>MClosed</b>)
        Debug.Print (&quot;MVertexCount = &quot; &amp; dsPolygonMesh.<b>GetMVertexCount</b>())
        Debug.Print (&quot;NVertexCount = &quot; &amp; dsPolygonMesh.<b>GetNVertexCount</b>())</pre>
<pre>        'Print PolygonMesh coordinates
        Debug.Print (&quot;Coordinates of polygon mesh vertices:&quot;)
        Dim vertexIndex As Long
        For vertexIndex = 0 To dsPolygonMesh.<b>GetVerticesCount</b>() - 1
            Dim x As Double, y As Double, z As Double
            dsPolygonMesh.<b>GetVertexCoordinate</b> vertexIndex, x, y, z</pre>
<pre>            Debug.Print (&quot;Vertex &quot; &amp; vertexIndex &amp; &quot;: (1),(2),(3): &quot; &amp; x &amp; &quot;, &quot; &amp; y &amp; &quot;, &quot; &amp; z)
            Next
    End Sub
</pre>
<p>&nbsp;</p>

</body>

</html>