Jump to content

Tube Miter Script


TenSecond408

Recommended Posts

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

TUBEMITER.txt

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • TenSecond408

    12

  • SEANT

    10

  • David Bethel

    1

  • Tromto

    1

Top Posters In This Topic

Posted Images


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

Link to comment
Share on other sites

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.

 

3239922597_21cdc2582a.jpg

3240757744_8cfbc4205f.jpg

Examples....

 

Thanks for the reply.

 

-AJ

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

PIPE.JPG

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

I’m still working on this project when free time is available. The coding is progressing nicely, and here is a peek at the UI.

Cope.jpg

Link to comment
Share on other sites

I’m still working on this project when free time is available. The coding is progressing nicely, and here is a peek at the UI.

 

Wow, thats pretty awesome so far. Im glad someone else had an interest in this, there is no way i could ever figure this out. Thanks for all your hard work.

 

-AJ

Link to comment
Share on other sites

Actually, here is an early build with almost no testing. . . .if anyone is feeling adventurous.

 

None of the details regarding Tube Wall Thickness have been implemented.

 

NETLOAD the DLL then enter COPE at AutoCAD’s command line.

 

Edit: See updated routine in lower post.

Link to comment
Share on other sites

Actually, here is an early build with almost no testing. . . .if anyone is feeling adventurous.

 

None of the details regarding Tube Wall Thickness have been implemented.

 

NETLOAD the DLL then enter COPE at AutoCAD’s command line.

 

You are amazing sir... I know your not done with the code, but i figured i would do some testing on it and let you know what i found.

 

It appears that when you do the multiple uncut tube option, than when it generates the two splines that the lower spline for the bottom cut need to be mirrored from the top one. As of now, its generates the same spline as the top, this means it copes to a tube that is vertical and the other would be clocked 90* of that. If that makes sense.

 

Other than that it all looks good. Thanks so much. Cant wait for the final version.

Link to comment
Share on other sites

I said before that when using the dual tube option that it create the spline wrong. It's actually doing was it's suppose to when you add angle into the equation. The only thing is when the angle is set to 0* (straight cope) off perpendicular is when it gets messed up. I know its easy enough to just move it around in AutoCAD to correct the error, but i figured since your doing the coding it can be done in the code pretty easily also.

 

-AJ

Link to comment
Share on other sites

Definitely something in need of work. I should get some time for refinement this weekend.

 

Take your time man, the beta alone helps me out tremendously. Thanks for the help.

 

Ill have to post up some pictures of the current project I'm working on that this is aiding me on.

 

-AJ

Link to comment
Share on other sites

Take your time man, the beta alone helps me out tremendously. Thanks for the help.

 

Ill have to post up some pictures of the current project I'm working on that this is aiding me on.

 

-AJ

 

I’ve addressed a couple of the issues with the first routine. If you get a chance, give it a test drive and let me know about any problems.

 

The wall thickness situation is next to get attention. As a general question; is this type of pipe cutting usually done by band saw (specifically, cutting straight through)? The alternate would be via a jigsaw with a blade smaller than the diameter of the pipe. The two methods would require a different curve projection to achieve the correct contour for the inner radius.

 

For that matter, is the wall thickness of the pipe thin enough (with respect to the diameter) that compensating for it would not really amount to much?

Release_1.zip

Link to comment
Share on other sites

Incidentally, later this weekend I’ll post the source code (C#) in case there are any interested would-be collaborators. :unsure:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...