Author Topic: Extrude along path  (Read 7583 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • 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 )

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • 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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Extrude along path
« Reply #10 on: October 15, 2023, 07:22:45 PM »
Using this to test my python wrappers

AddExtrudedSolidAlongPath seems to always fail if the spline has a fit point that’s non planar
However, I found it works for 3d polylines (I used PEDIT) on the spline


Code - Python: [Select]
  1. import PyRx as Rx
  2. import PyGe as Ge
  3. import PyGi as Gi
  4. import PyDb as Db
  5. import PyAp as Ap
  6. import PyEd as Ed
  7. import traceback
  8.  
  9. import AxApp24 as Ax
  10. import AxAppUtils24 as AxUt
  11.  
  12.  
  13. def PyRxCmd_doit():
  14.     try:
  15.        
  16.         dblBusDia = 1.45
  17.         axApp = Ax.getApp()
  18.         axDoc = axApp.ActiveDocument
  19.         entres = axDoc.Utility.GetEntity("\nSelect the spilne")
  20.         axSpline: Ax.IAcadSpline = entres[0]
  21.        
  22.         fp = axSpline.FitPoints
  23.        
  24.         #Ge math
  25.         pt1 = Ge.Point3d(fp[0],fp[1],fp[2])
  26.         pt2 = Ge.Point3d(fp[3],fp[4],fp[5])
  27.         v:Ge.Vector3d = pt2 - pt1
  28.         v.normalize()
  29.        
  30.         P1 = (fp[0],fp[1],fp[2])
  31.         oCircle = axDoc.ModelSpace.AddCircle(P1, dblBusDia / 2)
  32.         oCircle.Normal = (v[0],v[1],v[2])
  33.        
  34.         oReg = axDoc.ModelSpace.AddRegion([oCircle])
  35.         oCyl = axDoc.ModelSpace.AddExtrudedSolidAlongPath(oReg[0], axSpline)
  36.  
  37.     except Exception as err:
  38.         traceback.print_exception(err)
  39.        
  40. #polyline
  41. def PyRxCmd_doit2():
  42.     try:
  43.        
  44.         dblBusDia = 1.45
  45.         axApp = Ax.getApp()
  46.         axDoc = axApp.ActiveDocument
  47.         entres = axDoc.Utility.GetEntity("\nSelect the pline")
  48.         axPline: Ax.IAcad3DPolyline  = entres[0]
  49.        
  50.         fp = axPline.Coordinates
  51.        
  52.         #Ge math
  53.         pt1 = Ge.Point3d(fp[0],fp[1],fp[2])
  54.         pt2 = Ge.Point3d(fp[3],fp[4],fp[5])
  55.         v:Ge.Vector3d = pt2 - pt1
  56.         v.normalize()
  57.        
  58.         P1 = (fp[0],fp[1],fp[2])
  59.         oCircle = axDoc.ModelSpace.AddCircle(P1, dblBusDia / 2)
  60.         oCircle.Normal = (v[0],v[1],v[2])
  61.        
  62.         oReg = axDoc.ModelSpace.AddRegion([oCircle])
  63.         oCyl = axDoc.ModelSpace.AddExtrudedSolidAlongPath(oReg[0], axPline)
  64.  
  65.     except Exception as err:
  66.         traceback.print_exception(err)
  67.  
« Last Edit: October 15, 2023, 07:27:55 PM by It's Alive! »

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Extrude along path
« Reply #11 on: October 16, 2023, 01:03:12 PM »
that is awesome!  When you did the PEdit, what steps did you use?  Just curious how I can make this 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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Extrude along path
« Reply #12 on: October 16, 2023, 06:01:41 PM »
I just used the PEDIT command with the default options. Alternatively, SPLINEDIT, with the "convert to polyline" option will do the same. I don’t know how to do this in automatically in VBA.

For your code, you should only need to change AcadSpline to Acad3DPolyline and FitPoints to Coordinates


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Extrude along path
« Reply #13 on: October 16, 2023, 08:36:42 PM »
BTW,  .NET and ARX have a spline.toPolyline function, but I could not find this for VBA..

Here’s a test from python

Code - Python: [Select]
  1. import PyRx as Rx
  2. import PyGe as Ge
  3. import PyGi as Gi
  4. import PyDb as Db
  5. import PyAp as Ap
  6. import PyEd as Ed
  7. import traceback
  8.  
  9. import AxApp24 as Ax
  10. import AxAppUtils24 as AxUt
  11.  
  12. def PyRxCmd_doit():
  13.     try:
  14.         axApp = Ax.getApp()
  15.         axDoc = axApp.ActiveDocument
  16.        
  17.         plineIds = []
  18.         splineIds = []
  19.         dblBusDia = 1.45
  20.        
  21.         axSs = axDoc.SelectionSets.Add("Bus")
  22.         axSs.SelectOnScreen([0], ["SPLINE"])
  23.        
  24.         for axEnt in axSs:
  25.             splineIds.append(axEnt.ObjectID)
  26.            
  27.         for id in splineIds:
  28.             plineIds.append(convertToPlineEndErase(id))
  29.            
  30.         for id in plineIds:
  31.             obj = axDoc.ObjectIdToObject(id)
  32.             axPline = Ax.IAcad3DPolyline(obj)
  33.             fp = axPline.Coordinates
  34.        
  35.             #Ge math
  36.             pt1 = Ge.Point3d(fp[0],fp[1],fp[2])
  37.             pt2 = Ge.Point3d(fp[3],fp[4],fp[5])
  38.             v:Ge.Vector3d = pt2 - pt1
  39.             v.normalize()
  40.  
  41.             P1 = (fp[0],fp[1],fp[2])
  42.             oCircle = axDoc.ModelSpace.AddCircle(P1, dblBusDia / 2)
  43.             oCircle.Normal = (v[0],v[1],v[2])
  44.  
  45.             oReg = axDoc.ModelSpace.AddRegion([oCircle])
  46.             oCyl = axDoc.ModelSpace.AddExtrudedSolidAlongPath(oReg[0], axPline)
  47.             oCyl.Layer = "3D-BUSS"
  48.             oCircle.Delete()
  49.             axPline.Delete()
  50.            
  51.     except Exception as err:
  52.         traceback.print_exception(err)
  53.     finally:
  54.         axSs.Delete()
  55.        
  56. def convertToPlineEndErase(id):
  57.     splineId = Db.ObjectId()
  58.     splineId.setFromOldId(id)
  59.     spline = Db.Spline(splineId, Db.OpenMode.kForWrite)
  60.     pline = spline.toPolyline()
  61.     db = spline.database()
  62.     model = Db.BlockTableRecord(db.currentSpaceId(), Db.OpenMode.kForWrite)
  63.     plineid = model.appendAcDbEntity(pline)
  64.     spline.erase()
  65.     return plineid.asOldId()
  66.  

« Last Edit: October 16, 2023, 08:49:45 PM by It's Alive! »