PDA

View Full Version : Tube Miter Script



TenSecond408
5th Jun 2009, 06:47 pm
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

TenSecond408
5th Jun 2009, 07:19 pm
'----------------------------------------------------------------------
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

SEANT
5th Jun 2009, 09:37 pm
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

TenSecond408
6th Jun 2009, 04:28 am
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.

http://farm4.static.flickr.com/3507/3239922597_21cdc2582a.jpg
http://farm4.static.flickr.com/3334/3240757744_8cfbc4205f.jpg
Examples....

Thanks for the reply.

-AJ

SEANT
6th Jun 2009, 02:21 pm
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.

TenSecond408
6th Jun 2009, 03:49 pm
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

SEANT
8th Jun 2009, 09:22 am
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.

David Bethel
8th Jun 2009, 12:31 pm
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

TenSecond408
8th Jun 2009, 03:17 pm
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

TenSecond408
8th Jun 2009, 03:24 pm
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.

SEANT
9th Jun 2009, 11:58 am
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.

TenSecond408
9th Jun 2009, 01:28 pm
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

SEANT
11th Jun 2009, 12:01 pm
I'll be afield from the office today but should be able to post a test routine later tonight.

SEANT
11th Jun 2009, 12:18 pm
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.

TenSecond408
11th Jun 2009, 03:08 pm
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.

TenSecond408
11th Jun 2009, 05:01 pm
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

SEANT
11th Jun 2009, 08:38 pm
Definitely something in need of work. I should get some time for refinement this weekend.

TenSecond408
11th Jun 2009, 08:45 pm
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

SEANT
12th Jun 2009, 11:11 am
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?

SEANT
12th Jun 2009, 11:17 am
Incidentally, later this weekend I’ll post the source code (C#) in case there are any interested would-be collaborators. :unsure:

TenSecond408
14th Jun 2009, 04:53 pm
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?

When cutting the pipe from one of these templates I usually use a band saw and get the basic cuts done. I then use a hand held grinder to grind clearance on the inside diameter so the miter sits real nice on the uncut tube. Usually the wall thickness is about .065" so its not that critical, but these last pipes i was doing was 1.125 dia. x .155" wall so i had to clearance and radius inside a lot to get it to fit nicely. The program seems to work very good now, i havnt been able to find any other issue yet. Thanks again.

-AJ

SEANT
15th Jun 2009, 12:00 pm
When cutting the pipe from one of these templates I usually use a band saw and get the basic cuts done. I then use a hand held grinder to grind clearance on the inside diameter so the miter sits real nice on the uncut tube. Usually the wall thickness is about .065" so its not that critical, but these last pipes i was doing was 1.125 dia. x .155" wall so i had to clearance and radius inside a lot to get it to fit nicely. The program seems to work very good now, i havnt been able to find any other issue yet. Thanks again.

-AJ

I plan to have the routine determine “rail to rail” spacing by the inside edge of the “Cut Tube”. Consequently, any subsequent grinding would be applied to the outside edge. I thought that would generally be an easier grinding task – let me know if that’s true or not.

I’ve got a good game plan to map this critical inside geometry to the appropriate outside geometry for a through cut (i.e., band saw). I’ll post that as soon as I commit it to code.

TenSecond408
17th Jun 2009, 01:49 pm
I plan to have the routine determine “rail to rail” spacing by the inside edge of the “Cut Tube”. Consequently, any subsequent grinding would be applied to the outside edge. I thought that would generally be an easier grinding task – let me know if that’s true or not.

I’ve got a good game plan to map this critical inside geometry to the appropriate outside geometry for a through cut (i.e., band saw). I’ll post that as soon as I commit it to code.

Just trying to understand this, so your wanting to make it so instead of measuring centers of the two uncut tubes, you measure the distance between the two uncuts? Either way would be fine, but you are correct it is easier to grind that outside edge.

-AJ

Tromto
20th Oct 2009, 12:50 pm
Your script is written for DeltaCAD not AutoCAD. I have tested it with the DeltaCAD Demo and it works just fine. Just rename it to tubemiter.bas and run it from the Options > Macro > Run menu of DeltaCAD software.

jamami
9th Mar 2012, 11:07 am
I have been struggling with this issue for weeks using Acad2012, Win 7.
To draw the cope end I subtract one tube from the other, this creates a taper from wall thickness t at the intersection of the inner tube face to zero at the intersection of the outer wall face. This loss of wall thickness is not ideal. To get rid of this less than full thickness material I create a slicing plane through intersection of non-cut tube 1 and the inner wall of the tube to be cut, I establish this point by drawing a 2D cross section.
I realise this a bit of a hack and it never works out spot on as the slicing plan never seems to match exactly the intersection point of the 3D tube inner wall.
I have tried to get a work around. ie:
- drawing a tube inner radius only subtracting from that then shelling-this only re creates the taper.
-offsetting the intersection edge of the inner wall and trying to project onto outer at 90deg-this does not offset correctly due to the complex geometry.
33557

I was hoping the COPE file from SEANT may answer my problems but this will not load generating the error shown at the bottom of this post.
If anyone can provide me some help with the following I would be really grateful:

1. How to create a mitre maintaining full wall thickness. 90 degree intersections.
2. How to create a mitre maintaining full wall thickness. Non 90 degree intersections.
3. How to create a mitre maintaining full wall thickness. Tubes angled in 2 planes ie: for triangular space truss.
4. How to create a mitre maintaining full wall thickness. Tubes angled in 2 planes centres lines not coincident ie internal members offset to enable 2/3 to meet at same node.
5. How to deal with the above when using non round tubes.
6. How to fix the netload error for the cope routine.

Command: NETLOAD
Cannot load assembly. Error details: System.IO.FileLoadException: Could not
load file or assembly 'file:///C:\Users\tony
jenkins.EAS\Documents\EA\Release_1\TubeCope.dll' or one of its dependencies.
Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\tony
jenkins.EAS\Documents\EA\Release_1\TubeCope.dll' --->
System.NotSupportedException: An attempt was made to load an assembly from a
network location which would have caused the assembly to be sandboxed in
previous versions of the .NET Framework. This release of the .NET Framework
does not enable CAS policy by default, so this load may be dangerous. If this
load is not intended to sandbox the assembly, please enable the
loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 (http://go.microsoft.com/fwlink/?LinkId=155569)
for more information.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyN ame fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAsse mblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom (String assemblyFile,
Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm
hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks,
StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(Stri ng fileName)
at loadmgd()