TenSecond408 发表于 2022-7-6 08:10:50

管斜接脚本

我有一个管斜接脚本,我正在尝试运行。Iv尝试加载。bas文件并运行它,但我在第2行一直遇到语法错误。。。。。。。我不知道为什么脚本不会运行,四检查了线,它似乎是正确的。如果有人能看一下。bas文件对我来说太棒了!
 
见附件。
 
谢谢你抽出时间。
 
PS:它不允许我上传。bas文件,所以我将其转换为。txt文件。
 
-AJ公司
块茎螨。txt文件

TenSecond408 发表于 2022-7-6 08:16:13



'----------------------------------------------------------------------
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 发表于 2022-7-6 08:17:35

本模块中没有几个支持元素。没有这些元素,就没有简单的方法来测试和提供建议。
 
此例程的目的是创建未包装的斜接,如本线程中所述:
 
http://www.cadtutor.net/forum/showthread.php?t=29251

TenSecond408 发表于 2022-7-6 08:22:28

 
是的,关于展开模板,您是正确的,但在该线程中讨论的是直线切割。我想最好的名字应该是Tube Cope?如果您查看该线程并从PAULMCZ下载名为“pipe fitting lsp.dwg”的dwg。你会看到一个标签为“TJ计划”,这更像是我想要做的。我不想要在管子上直接切割,我想要一个顶盖,这样一个相交的管子会平稳地铺在另一个管子上,以便进行良好的焊接。
 
http://farm4.static.flickr.com/3507/3239922597_21cdc2582a.jpg
http://farm4.static.flickr.com/3334/3240757744_8cfbc4205f.jpg
示例。。。。
 
谢谢你的回复。
 
-AJ公司

SEANT 发表于 2022-7-6 08:24:32

我看这会有什么帮助。但是,正如我所说,您发布的模块(.bas)不完整。有些函数dcCreateLine和dcCreateSpline不存在。如果你有权访问它们,请将其张贴出来,以便提供更明智的建议。没有它们,这将是一个相当激烈的逆向工程项目。
 
这个主题很有趣,我不介意在空闲的时候研究它(可能是作为一个C项目)。
 
在平均时间后#13http://www.cadtutor.net/forum/showthread.php?t=29251包含一个链接,指向一个可能符合要求的独立程序。

TenSecond408 发表于 2022-7-6 08:27:11

 
是的,我已经有一些程序可以为我做,但它们都只是直接打印。我想在CAD中做点什么,这样我就可以使用线条添加额外的尺寸。BAS文件是为“DeltaCAD”制作的,它在那里工作,只是在AutoCAD中不工作。。。
 
我不擅长数学,但它就像你用excel文件处理斜接坐标一样,可以用同样的方法处理。我确实知道完成手术需要什么公式。你想让我帮你贴出完整的等式。这是一个链接到完整的方程式。我想它会将该方程求解180次(每2度)以完成展开模板。
 
http://metalgeek.com/static/dan/derivation.html
 
-AJ公司

SEANT 发表于 2022-7-6 08:32:25

是否可以安全地假设打印的曲线将作为管外径的参考,但关键几何形状是内径?我还假设初始切割将通过跳汰锯进行,锯片保持与管表面垂直的方向。
 
在你上一篇文章中链接的照片显示了切割地面背面的外部部分(以允许良好的焊缝),只有用于索引适当角度的内部边缘。
 
编辑:实际上,经过进一步思考,我可以看到用带锯切割管子会如何改变参数。

David Bethel 发表于 2022-7-6 08:35:42

我过去在钻床上使用的是一种金属切割孔锯(与要相交的管子直径相同),通过夹具将管子固定在适当的角度。钻一个导向孔,然后去钻。
 
为了进行生产工作,他们制作了一种工具和模具,该工具和模具可以一次装入冲床和切口的一侧。还有激光切割-大卫

TenSecond408 发表于 2022-7-6 08:39:01

 
是的,你所说的一切都是正确的。我通常会磨掉外缘,这样就不必在很薄的金属上焊接了。焊接时它给了我更多的肉,这产生了一个漂亮的焊缝。我给你们发的那些管子的图片,是用一个像有人从下面开始锯的孔,用一个磨机实际切割的地方。
 
我会在所有的切口上使用孔锯,但在做不同角度的切割时,很难把东西排好。直尺在铣床上很容易,但我只是没有夹具的设备来固定它在不同的角度。
 
-AJ公司

TenSecond408 发表于 2022-7-6 08:42:27

 
这也是我在做管子斜接时通常使用的过程,但正如我在上面对肖特说的那样,我没有合适的虎钳来固定夹具,以使管子保持复合角度。您还提到了一个冲床的管槽口。我们的商店里也有这个,它是为钢铁工人设计的凹口,但它只有90度(直管)的凹口,就像我拍的那些。
 
这些展开模板是最快速、最简单的操作。我可以用手带做一个基本的90度缺口,比我去磨坊用孔锯切割要快。展开后会给我基本的线条和切割位置,使我达到大致的形状,然后我使用研磨机进行平滑处理,以获得合适的精加工配件
 
-AJ。
页: [1] 2
查看完整版本: 管斜接脚本