CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 26, 2017, 06:30:35 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Extrude Solids  (Read 231 times)
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 4628



View Profile WWW
« on: August 26, 2017, 00:30:36 am »

Hello

I just finished a new little plugin that allow to extrude any 2D shape to do a solid 3D object (with cover at both ends)

For CamBam V1 only



http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/ExtrudeSolids.html

++
David
« Last Edit: August 26, 2017, 00:39:23 am by dh42 » Logged
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3066



View Profile
« Reply #1 on: August 26, 2017, 08:15:45 am »

Now that's a good one David !   Grin
We already had 'Extrude' but it did not close the top and bottom and only worked on some entities.
Logged
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 4628



View Profile WWW
« Reply #2 on: August 26, 2017, 22:03:00 pm »

Hello

Not a big job, Andy do all the difficult things ! , like an extrude function with caps at both ends, He just forgot to add it in the menu  Grin

I also play with the other extrude functions to try to do tapered extrusion, but the taper arg seems to have no effect  Huh

++
David


* Sans titre-1.png (140.52 KB, 1024x605 - viewed 23 times.)
Logged
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 4628



View Profile WWW
« Reply #3 on: August 26, 2017, 23:50:10 pm »

The code

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
« Last Edit: August 26, 2017, 23:57:29 pm by dh42 » Logged
philboone
CNC Ewok
*
Offline Offline

Posts: 1



View Profile
« Reply #4 on: September 24, 2017, 11:00:02 am »

Thanx for that code! It helped me too
Logged

I like to create different electronical devices because it helps me improve my skills and knowledges
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.148 seconds with 18 queries.

Copyright © 2008 HexRay Ltd. | Sitemap