Author Topic: Extrude along path  (Read 1019 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Extrude along path
« on: April 20, 2023, 03:17:33 PM »

I am trying to use some code that I think Bryco helped me with years ago to extrude a circle along a spline path.  I cannot figure out why this doesn't work
Code: [Select]
Public Sub DrawCable()
      On Error GoTo err_control
'      Dim InsPt As Variant, dblRot As Double, strPrompt As String, intBusCenterLine As Integer
      Dim dblBusDia As Double
      Dim oLayer As AcadLayer, oLine As AcadSpline, objPath As Object
Dim newPT1(2) As Double
Dim newPT2(2) As Double
Dim P1, P2
Dim V(2) As Double, Unit As Double, Vn(2) As Double
Dim oCyl As Acad3DSolid, oCircle As AcadCircle
Dim regent(0) As AcadEntity
Dim oReg As Variant

Start:
      dblBusDia = 1.45
      Set oLayer = ThisDrawing.Layers.Add("3D-BUSS-CALC")
      oLayer.color = 234
      Dim objSelected As Object
      Dim objSelSet As AcadSelectionSet
      Set oLayer = ThisDrawing.Layers.Add("3D-BUSS")
      oLayer.color = 3
      Set objSelSet = ThisDrawing.SelectionSets.Add("Bus")
      objSelSet.SelectOnScreen
For Each objSelected In objSelSet
            If Not TypeOf objSelected Is AcadSpline Then
                  MsgBox "That was not a Layout Line"
                  Exit Sub
            End If
            Set oLine = objSelected
            Set objPath = objSelected
            newPT1(0) = oLine.FitPoints(0): newPT1(1) = oLine.FitPoints(1): newPT1(2) = oLine.FitPoints(2)
            newPT2(0) = oLine.FitPoints(3): newPT2(1) = oLine.FitPoints(4): newPT2(2) = oLine.FitPoints(5)
            P1 = newPT1
            P2 = newPT2
            V(0) = P2(0) - P1(0): V(1) = P2(1) - P1(1): V(2) = P2(2) - P1(2)
      'Normalise the vector(It's length=1)
            Unit = Sqr(V(0) * V(0) + V(1) * V(1) + V(2) * V(2))
            Vn(0) = V(0) / Unit: Vn(1) = V(1) / Unit: Vn(2) = V(2) / Unit
            Set oCircle = ThisDrawing.ModelSpace.AddCircle(P1, dblBusDia / 2)
            oCircle.Normal = Vn    ' Vn or V both work here.
            Set regent = oCircle
            oReg = ThisDrawing.ModelSpace.AddRegion(regent)
            Set oCyl = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(oReg(0), objPath)
           
            oCyl.Layer = "3D-BUSS"
            oCircle.Delete
            oReg(0).Delete
      Next
      ThisDrawing.SelectionSets.Item("Bus").Delete
      ThisDrawing.Application.Update
Exit_Here:
     
      ThisDrawing.SetVariable "INSUNITS", 1
      Unload frmBus
      Exit Sub
err_control:
      Select Case Err.Number


      Case "-2145320851"
            ThisDrawing.SelectionSets.Item("Bus").Delete
            Err.Clear
            Resume
      Case Else
            MsgBox Err.Description
                        oCircle.Delete
            oReg(0).Delete
            Resume Exit_Here
      End Select
End Sub
« Last Edit: April 20, 2023, 03:37:36 PM by David Hall »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #1 on: April 20, 2023, 03:21:12 PM »
It works all the way to this line
Code: [Select]
Set oCyl = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(oReg(0), objPath)
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #2 on: April 20, 2023, 03:25:46 PM »
And if I stop the code after the region is created, I can manually extrude the region along the spline, so I know it can be done.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #3 on: April 28, 2023, 03:10:51 PM »
Any takers?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Beavis

  • Retired
  • Needs a day job
  • Posts: 7904
  • AKA Daniel
Re: Extrude along path
« Reply #4 on: April 29, 2023, 06:10:47 PM »
you're wanting to extrude a region? did you try with just a circle?
ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(oReg(0), oCircle )
Retired

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #5 on: May 01, 2023, 08:37:31 AM »
I didn't try that, but I will.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #6 on: May 01, 2023, 08:41:51 AM »
didnt work
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #7 on: May 01, 2023, 08:43:40 AM »
works if I manually do it, but not through code
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4061
Re: Extrude along path
« Reply #8 on: May 01, 2023, 03:10:15 PM »
I verified I had what you put, and it still does not work.  I am beginning to think it wont work.  I have found the example from Adesk doesn't work either
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Beavis

  • Retired
  • Needs a day job
  • Posts: 7904
  • AKA Daniel
Re: Extrude along path
« Reply #9 on: May 02, 2023, 01:36:32 AM »
I was just guessing, I don't have VBA to test with
Retired