Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<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(, "DraftSight.Application")
'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 ("There are no open documents in DraftSight.")
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 ("Polygon mesh parameters...")</pre>
<pre> 'Print common entity parameters
Debug.Print ("Handle = " & dsPolygonMesh.<b>Handle</b>)
Debug.Print ("Color = " & dsPolygonMesh.Color.<b>GetNamedColor</b>())
Debug.Print ("Erased = " & dsPolygonMesh.<b>Erased</b>)
Debug.Print ("Layer = " & dsPolygonMesh.<b>Layer</b>)
Debug.Print ("LineScale = " & dsPolygonMesh.<b>LineScale</b>)
Debug.Print ("LineStyle = " & dsPolygonMesh.<b>LineStyle</b>)
Debug.Print ("LineWeight = " & dsPolygonMesh.<b>LineWeight</b>)
Debug.Print ("Visible = " & 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 ("BoundingBox: " & x1 & ", " & y1 & ", " & z1 & ", " & x2 & ", " & y2 & ", " & z2)</pre>
<pre> 'Print PolygonMesh parameters
Debug.Print ("FitSmooth = " & dsPolygonMesh.<b>FitSmooth</b>)
Debug.Print ("NDensity = " & dsPolygonMesh.<b>NDensity</b>)
Debug.Print ("MDensity = " & dsPolygonMesh.<b>MDensity</b>)
Debug.Print ("NClosed = " & dsPolygonMesh.<b>NClosed</b>)
Debug.Print ("MClosed = " & dsPolygonMesh.<b>MClosed</b>)
Debug.Print ("MVertexCount = " & dsPolygonMesh.<b>GetMVertexCount</b>())
Debug.Print ("NVertexCount = " & dsPolygonMesh.<b>GetNVertexCount</b>())</pre>
<pre> 'Print PolygonMesh coordinates
Debug.Print ("Coordinates of polygon mesh vertices:")
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 ("Vertex " & vertexIndex & ": (1),(2),(3): " & x & ", " & y & ", " & z)
Next
End Sub
</pre>
<p> </p>
</body>
</html>