The code
Imports CamBam
Imports CamBam.CAD
Imports CamBam.UI
Imports CamBam.Util
Imports System.Windows.Forms
' extrude solids
'for cambam V1 only
' dh42 08/2017
Public Class MyPlugin
Public Shared Sub InitPlugin(ByRef ui As CamBamUI)
Dim mi As New ToolStripMenuItem() 'the new menu entry (item)
mi.Text = "Extrude Solids"
'-------------------- menu placement test for main menu----------
Dim mnuDraw As ToolStripMenuItem
'search for the index of the "surface" item in the "Draw"menu
For n As Integer = 0 To ui.Menus.mnuDraw.DropDownItems.Count - 1
Try
mnuDraw = ui.Menus.mnuDraw.DropDownItems.Item(n)
If mnuDraw.Name = "mnuDrawSurface" Then
mnuDraw = ui.Menus.mnuDraw.DropDownItems.Item(n) 'get a pointer to the 'surface' item in the draw menu
mnuDraw.DropDownItems.Add(mi) 'add the new entry at the last position in the sub menu.
AddHandler mi.Click, AddressOf plugin_clicked 'add a handler that call the sub 'plugin_clicked' if the main item his hit.
Exit For
End If
Catch ex As Exception
End Try
Next n
End Sub
Public Shared Sub plugin_clicked(ByVal sender As Object, ByVal e As EventArgs)
Extrude_Solids()
End Sub
Public Shared Sub Extrude_Solids()
Dim unit As Long
Dim tp As String 'entity type
Dim p As Polyline, r As CamBam.CAD.Region, c As Circle, a As Arc, tx As MText, sp As Spline, s As Surface
Dim reg_array() As CamBam.CAD.Region 'an array of regions that will contain MText explode
Dim res As Double = 0.02
Dim rep As String, tic As Double
Dim bottcap As Boolean = True 'used to know if a bottom cap is nedeed or not, if tickness = 0, no bottom cap to avoid double sided plane
'test units to define a suitable resolution
unit = CamBamUI.MainUI.ActiveView.CADFile.DrawingUnits
If unit = 1 Then 'inch
res = 0.02 / 25
Else
res = 0.02
End If
If CamBamUI.MainUI.ActiveView.SelectedEntities.Length <> 0 Then 'something is selected
rep = InputBox(TextTranslation.Translate("Thickness: "), TextTranslation.Translate("Extrude Solids"), "0")
If rep = "" Then Exit Sub 'cancel
tic = Val(rep)
If tic = 0 Then 'if no deep, the bottom cap is ommited
bottcap = False
Else
bottcap = True
End If
'undo
CamBamUI.MainUI.UndoBuffer.AddUndoPoint("Extrude Solids")
CamBamUI.MainUI.UndoBuffer.Add(CamBamUI.MainUI.ActiveView.CADFile.ActiveLayer.Entities)
CamBamUI.MainUI.ActiveView.CADFile.Modified = True
For Each ent As Entity In CamBamUI.MainUI.ActiveView.SelectedEntities
tp = ent.GetType.ToString
Select Case tp
Case "CamBam.CAD.PolyRectangle", "CamBam.CAD.Polyline"
p = CType(ent, Polyline)
If p.Closed = False Then
p.Closed = True
End If
s = CAD3DUtils.Extrude(p, res, tic, True, bottcap)
s.DisplayEdges = True
CamBamUI.MainUI.ActiveView.CADFile.Add(s.Clone)
Case "CamBam.CAD.Circle"
c = CType(ent, Circle)
p = c.ToPolyline()
s = CAD3DUtils.Extrude(p, res, tic, True, bottcap)
s.DisplayEdges = True
CamBamUI.MainUI.ActiveView.CADFile.Add(s.Clone)
Case "CamBam.CAD.Arc"
a = CType(ent, Arc)
p = a.ToPolyline()
If p.Closed = False Then
p.Closed = True
End If
s = CAD3DUtils.Extrude(p, res, tic, True, bottcap)
s.DisplayEdges = True
CamBamUI.MainUI.ActiveView.CADFile.Add(s.Clone)
Case "CamBam.CAD.MText"
tx = CType(ent, MText)
reg_array = tx.ToRegions 'explode MText to regions
' make surface with each region stored in the array
Try
For n As Long = 0 To UBound(reg_array)
s = CAD3DUtils.Extrude(reg_array(n), res, tic, True, bottcap)
s.DisplayEdges = True
CamBamUI.MainUI.ActiveView.CADFile.Add(s.Clone)
Next n
Catch ex As Exception
' just in case the array is empty
End Try
Case "CamBam.CAD.Spline"
sp = CType(ent, Spline)
p = sp.ToPolyline(res)
If p.Closed = False Then
p.Closed = True
End If
s = CAD3DUtils.Extrude(p, res, tic, True, bottcap)
s.DisplayEdges = True
CamBamUI.MainUI.ActiveView.CADFile.Add(s.Clone)
Case "CamBam.CAD.Region"
r = CType(ent, CamBam.CAD.Region)
s = CAD3DUtils.Extrude(r, res, tic, True, bottcap)
s.DisplayEdges = True
CamBamUI.MainUI.ActiveView.CADFile.Add(s.Clone)
Case Else
' .....
End Select
CamBamUI.MainUI.ActiveView.RefreshView()
Next ent
Else
MsgBox(TextTranslation.Translate("Please select at least one drawing objects"))
End If
End Sub
End Class
++
David