+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 25
  1. #1
    Junior Member
    Using
    AutoCAD 2009
    Join Date
    Jan 2009
    Posts
    14

    Default Tube Miter Script

    Registered forum members do not see this ad.

    I have a tube miter script that i'm trying to run. Iv tried loading the .bas file and running it, but i keep getting a syntax error on line 2....... Im not sure why the script wont run, iv checked over the lines and it seems to be right. If someone could look over the .bas file for me that would be great!

    See Attached File.

    Thanks for your time.

    PS: It wont let me upload the .bas file, so i converted it to a .txt file.

    -AJ
    Attached Files

  2. #2
    Junior Member
    Using
    AutoCAD 2009
    Join Date
    Jan 2009
    Posts
    14

    Default

    Code:
       '----------------------------------------------------------------------
      Sub Main()
        Begin Dialog TUBEMITERDIALOG 50,47, 160, 96, "Tube Miter"
          Text         4  ,12,120,12, "Diameter of intersecting tube (mm)"
          TextBox      120,12,25 ,12, .IDD_D1
          Text         4  ,24,120,12, "Diameter of mitered tube (mm)"
          TextBox      120,24,25 ,12, .IDD_D2
          Text         4  ,36,120,12, "included angle"
          TextBox      120,36,25 ,12, .IDD_PHI
          Text         4  ,48,120,12, "Offset (mm)"
          TextBox      120,48,25 ,12, .IDD_OFFSET
          OKButton     4,80,37,12
          CancelButton 45,80,37,12
        End Dialog
        Dim dlg As TUBEMITERDIALOG 
        Dim ot As Long
      
        If(dcSelectAll) Then dcEraseSelObjs
      
        dcSetDrawingScale 25.4
        dcSetLineParms dcBLACK, dcSOLID, dcTHIN
        dcSetSplineParms dcBLACK, dcSOLID, dcTHIN
      
      
        dlg.IDD_D1 = "25.4"
        dlg.IDD_D2 = "25.4"
        dlg.IDD_PHI = "90"
        dlg.IDD_OFFSET= "0.0"
      
        Button = Dialog(dlg)
      
        If Button = -1 Then
          Make_TubeMiter dlg.IDD_d1/2,dlg.IDD_D2/2,rad(90 - dlg.IDD_PHI),dlg.IDD_OFFSET/2
          dcViewAll
        End If
      End Sub
      
      '----------------------------------------------------------------------
      ' Square a value
      '----------------------------------------------------------------------
      Function square(ByVal x As Double)
        square = x * x 
      End Function
      
      '----------------------------------------------------------------------
      ' Convert from degrees into radians
      '----------------------------------------------------------------------
      Function rad(ByVal deg As Double)
        rad = (2*3.1415926535/360)*deg
      End Function
      
      '----------------------------------------------------------------------
      ' Plot the tube miter
      '   R1     = radius of intersecting tube
      '   R2     = radius of intersected (cut) tube
      '   Phi    = included angle between tubes (in radians)
      '   Offset = offset along the z axis between the tubes
      '
      '
      ' The generalized equation for a cylinder of radius r about the x axis is 1 = (y/r)^2 + (z/r)^2
      ' apply the transformation y = y'cos(phi) + x'sin(phi) to rotate the cylinder about the z axis by angle phi
      ' this gives the equation 1 = ((y cos(phi) + x sin(phi))/r)^2 + (z/r)^2
      ' now solve for x to get: x = (+- r*sqrt(1-(z/r)^2) - y cos(phi))/sin(phi)
      
      ' we can now iterate over values of y and z to find the discreet x points that make up our curve and fit them with 
      ' a spline
      
      ' so we'll find our y and z values by rotating around the mitered cylinder which is along the x axis.  So we get:
      ' y = R sin(alpha)
      ' z = R cos(alpha)  for alpha = 0 to 360 
      ' actually let's not forget the offset, which applies only to the Z axis, so z = R cos(alpha) + Offset
      ' we can then substitute these back into the above equation for x.
      
      ' This X dimension is exactly what we want to plot, but the y parmeter for plotting needs to be the circumfrence 
      ' of the mitered cylinder.  so Yplot= R * alpha (if alpha is in radians) 
      
      ' we also need to account for the fact that we support having a mitered cylinder larger than the intersecting cylinder
      ' so there is some logic there to figure out when a value is valid and not.  
      
      '---------------------------------------------------------------------- 
      Sub Make_TubeMiter(ByVal R1 As Double,ByVal R2 As Double,ByVal Phi As Double,ByVal Offset As Double)
        Dim X As Double ' X(a)
        Dim s(361) As Double 'Array for the spline
        Dim i As Double 'i for for loop
        Dim start As Double 'start of a spline
        Dim sign As Double 'either 1 or -1 to determine the sign in the equation below
        Dim loopCount As Integer 'loop once if the intersecting tube is larger, twice if smaller
        Dim j As Integer
        Dim ya As Double
        Dim za As Double 
        Dim alpha As Double
        Dim max As Double
      
        sign = -1
        loopCount = 1
        max = 0
      
        ' If the intersecting tube is smaller, we need to draw both sides
        ' of the intersection since it is making a hole though the tube, Thus we want to run through
        ' the loop twice. 
      
        If (R2 + Offset > R1) Then 
            loopCount = 2
        End If
      
        For j = 1 to loopCount 
          start = -1
          For i=0 To 360 Step 2 'iterate 0 - 360 by 2 degree increments
            alpha = rad(i) 'we need everything in radians
            ya = R2*Sin(alpha)
            za = R2*Cos(alpha)+Offset
      
            'if there is something to cut here
            If square(za/R1) <= 1 Then
              X= (R1 * sign * Sqr(1 - square(za/R1)) - ya * Sin(Phi))/Cos(Phi) ' from the equation derived int he comments above
      
              ' If this is the first good sample in this spline, then record that
              If start = -1 Then 
                start = i
              End If
            Else ' we are cutting a hole, and this is outside that hole
              X = 0.0
              ' this is the first sample that is outside the hole, draw the spline
              If start > -1 Then
                dcCreateSpline s(start), (i-start)/2, False
                start = -1
              End If
            End If
      
            ' spline point = (x,R*alpha)
            s(i) = X
            s(i+1) = R2 * alpha 
      
            ' record the largest extent for the purpose of drawing reference lines
            If (Abs(X) > max) Then max = Abs(X)
      
          Next i
      
          ' If we stopped the loop while we still had valid values, display the spline
          If start > -1 Then
            dcCreateSpline s(start), (362 - start)/2, False
          End If
      
          ' swap the sign just in case we need to run through the loop again
          sign = 1
      
        Next j
      
        ' Draw reference lines
        dcCreateLine  (-2*max), (R2 * rad(0)  ), (2*max), (R2 * rad(0)  )
        dcCreateLine  (-2*max), (R2 * rad(90) ), (2*max), (R2 * rad(90) )
        dcCreateLine  (-2*max), (R2 * rad(180)), (2*max), (R2 * rad(180))
        dcCreateLine  (-2*max), (R2 * rad(270)), (2*max), (R2 * rad(270))
        dcCreateLine  (-2*max), (R2 * rad(360)), (2*max), (R2 * rad(360))
      
      End Sub

  3. #3
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    There are several supporting elements not present with this module. Without these elements there is no easy way to test and offer suggestions.

    Is the purpose of this routine to create a unwrapped miter as discussed in this thread:

    http://www.cadtutor.net/forum/showthread.php?t=29251

  4. #4
    Junior Member
    Using
    AutoCAD 2009
    Join Date
    Jan 2009
    Posts
    14

    Default

    Quote Originally Posted by SEANT View Post
    There are several supporting elements not present with this module. Without these elements there is no easy way to test and offer suggestions.

    Is the purpose of this routine to create a unwrapped miter as discussed in this thread:

    http://www.cadtutor.net/forum/showthread.php?t=29251
    Yes you are correct about the unwrap templates, but the ones discusses in that thread are for straight cuts. I guess a better name for it would be Tube Cope? If you look in that thread and download the dwg called "pipe fitting lsp.dwg" from PAULMCZ. You will see the one labeled "TJ Program" thats more like what im looking to do. I dont want just a straight cut on the tube, i want a cope so the one pipe that is intersecting will lay onto the other tube nice and flat for a good weld.



    Examples....

    Thanks for the reply.

    -AJ

  5. #5
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    I can see how that would be helpful. But, as I said, the module (.bas) you posted is incomplete. Some functions, dcCreateLine, dcCreateSpline, are not present. If you have access to them post them to allow more informed advice. Without them it would be a fairly intense reverse engineering project.

    The subject is interesting and I wouldn’t mind looking into it (perhaps as a C# project) when some time frees up.

    In the mean time post #13 of http://www.cadtutor.net/forum/showthread.php?t=29251 contains a link to a standalone program that may fit the bill.
    Last edited by SEANT; 6th Jun 2009 at 02:53 pm. Reason: Spelling

  6. #6
    Junior Member
    Using
    AutoCAD 2009
    Join Date
    Jan 2009
    Posts
    14

    Default

    Quote Originally Posted by SEANT View Post
    I can see how that would be helpful. But, as I said, the module (.bas) you posted is incomplete. Some functions, dcCreateLine, dcCreateSpline, are not present. If you have access to them post them to allow more informed advice. Without them it would be a fairly intense reverse engineering project.

    The subject is interesting and I wouldn’t mind looking into it (perhaps as a C# project) when some time frees up.

    In the mean time post #13 of http://www.cadtutor.net/forum/showthread.php?t=29251 contains a link to a standalone program that may fit the bill.
    Yeah i already have a few programs that will do it for me, but they all just print directly. I wanted something i can do in CAD so i can use the line work to add additional dimensions. That BAS file was made for "DeltaCAD" and it works in there, just not in AutoCAD...

    Im not good with math, but it seams like the same way you did the excel file for the miter coordinates, could be done the same for this. I do know the formula that it would take to complete the operation. You want me to post up the full equation for you. Here is the a link to the complete equation worked out. I guess it solves that equation 180 times ( every 2 degree) to complete the unwrap template.

    http://metalgeek.com/static/dan/derivation.html

    -AJ
    Last edited by TenSecond408; 6th Jun 2009 at 03:55 pm.

  7. #7
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    Is it safe to assume that the printed curve will be a reference for the outside diameter of the tube, but the critical geometry is for the inside diameter? I’m also assuming the initial cutting will be by jig saw with the blade maintaining a perpendicular orientation to the tube surface.

    The photo linked in your last post shows the outside portion of the cut ground back (to allow a good welded seam) and only the inside edge used to index the appropriate angle.

    Edit: Actually, after further thought, I can see how cutting the tube with a band saw would change the parameters a bit.
    Last edited by SEANT; 8th Jun 2009 at 09:43 am. Reason: Modified statement

  8. #8
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    What I've used in the past is a metal cutting hole saw ( same diameter as the tube to be intersected ) in a drill press, jigged to hold the tube at proper angle. Drill a pilot hole and then go for it.

    For production work they make a tool and die that fits into a punch press and notches 1 side at a time. And then there is always laser cutting. -David
    Attached Images
    R12 (Dos) - A2K

  9. #9
    Junior Member
    Using
    AutoCAD 2009
    Join Date
    Jan 2009
    Posts
    14

    Default

    Quote Originally Posted by SEANT View Post
    Is it safe to assume that the printed curve will be a reference for the outside diameter of the tube, but the critical geometry is for the inside diameter? I’m also assuming the initial cutting will be by jig saw with the blade maintaining a perpendicular orientation to the tube surface.

    The photo linked in your last post shows the outside portion of the cut ground back (to allow a good welded seam) and only the inside edge used to index the appropriate angle.

    Edit: Actually, after further thought, I can see how cutting the tube with a band saw would change the parameters a bit.
    Yes you are correct on everything stated. I do usually grind back the outside edges as to not have to weld on really thin metal. It gives me more meat when welding which produces a nice weld. Those tubes i sent you pictures of where actually cut with a mill, using a hole saw like someone started below.

    I would use a hole saw on all cuts but its very difficult to get stuff lined up when doing all the different angles of the cope. Straight copes are very easy on the mill, but i just dont have the equpiments to jig fixture to hold it at different angles.

    -AJ

  10. #10
    Junior Member
    Using
    AutoCAD 2009
    Join Date
    Jan 2009
    Posts
    14

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by David Bethel View Post
    What I've used in the past is a metal cutting hole saw ( same diameter as the tube to be intersected ) in a drill press, jigged to hold the tube at proper angle. Drill a pilot hole and then go for it.

    For production work they make a tool and die that fits into a punch press and notches 1 side at a time. And then there is always laser cutting. -David
    This is also the process i usually use when doing tube miters, but as i said to SEANT above i dont have the proper vises to jig fixtures to hold the tube at compound angles and stuff. You also mentioned a tube notcher for a punch. We also have this in a our shop, its a notcher for the Iron Worker, but it only notches for a 90degree (straight cope) like the ones i took pictures of.

    These unwrap templates are about the quickest and easy thing to do. I can do a basic 90* notch by hand with a portaband faster that i can go to the mill and use a hole saw to cut. The unwraps will give me the basic lines and locations of cuts to get me to the ballpark shape then i use a grinder to smooth and to get the finish fittments just right

    -AJ.

Similar Threads

  1. Compound Miter in 3D
    By Bill Tillman in forum AutoCAD 3D Modelling & Rendering
    Replies: 2
    Last Post: 2nd Mar 2009, 09:56 pm
  2. joining a tube
    By bikoy in forum AutoCAD 3D Modelling & Rendering
    Replies: 16
    Last Post: 8th Dec 2008, 01:29 am
  3. angle around a tube?
    By F_Bond in forum AutoCAD 3D Modelling & Rendering
    Replies: 7
    Last Post: 24th Feb 2008, 08:46 pm
  4. How to draw a tube
    By Jussdale in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 14th Oct 2007, 10:02 pm
  5. Sub script and Super script Text
    By edwin in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 1st Aug 2007, 08:07 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts