Jump to content

3D Tubes


Chris_Hebden

Recommended Posts

Greetings all,

 

I am new to this forum and am quite impressed by the knowledge of the members. I came across the topic of 3D tubes and I have a question/problem that I think fits here….

 

I wish to automate the creation of tubes, on the order of thousands, from a file of 3D polyline x-y-z coordinates.

 

I have the x-y-z coordinates of thousands of 3D polylines in Excel and text file. Each 3D polyline consists of only 3 points, like a triangle in 3D space with one side missing.

For each 3D polyline, I wish to convert it into a solid tube of fixed diameter. Currently to create the tubes, I am manually drawing a circle at the base of each polyline, and also manually extruding the circle to follow the path of the 3D polyline. One possible advantage is that the diameter of all tubes is the same.

 

If necessary, I can program in BASIC to create some brute force script (.scr) files. I would like to avoid LISP, for now.

 

Attached is an much scaled down example of the final output, consisting of 5 pipes, starting with 5 polylines.

 

Any thoughts, comments or suggestions would be greatly appreciated.

 

Back in the old Mechanical Desktop days, I could have helped you out with this. You could drive drawings from an excel spreadsheet back then in that product. However, that was 10 years ago, and I drifted over into architectural drawing and worked for companies who had their own ways of doing things, and I'm afraid I've lost touch with some of the newer features in autocad. I see in the help files that you can use parametric constraints in 2010, so if you could figure out how to access them from ms excel or access you could do these drawings from your spreadsheet. I am not the one to help you set it up though. I've forgotten just about everything about how to do that, and it probably doesn't work the same way now anyway.

Edited by Jack_O'neill
can't type tonight to save my life
Link to comment
Share on other sites

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

  • Jack_O'neill

    12

  • ReMark

    9

  • Chris_Hebden

    8

  • SEANT

    4

Top Posters In This Topic

Posted Images

Back in the old Mechanical Desktop days' date=' I could have helped you out with this. You could drive drawings from an excel spreadsheet back then in that product. However, that was 10 years ago, and I drifted over into architectural drawing and worked for companies who had their own ways of doing things, and I'm afraid I've lost touch with some of the newer features in autocad. I see in the help files that you can use parametric constraints in 2010, so if you could figure out how to access them from ms excel or access you could do these drawings from your spreadsheet. I am not the one to help you set it up though. I've forgotten just about everything about how to do that, and it probably doesn't work the same way now anyway.[/quote']

Thanks for your reply, Jack. Actually, I don't need to drive the drawing from Excel, it just happens that my data starts there. Probably should not have mentioned it in the OP, as it isn't critical to the process. In fact, I used a script (.scr) file to draw the 3D polylines.

 

I think what I'm looking for is the correct script commands that would do something like this: (1) draw each 3D polyline, (2) a circle and then (3) automatically extrude the circle to that particular polyline. As I mentioned, I can create a huge script file from the polyline data using BASIC, so I think I would only need to know script commands for one 3D polyline + circle + extrude along polyline path sequence. I hope that makes sense to somebody out there.

Link to comment
Share on other sites

I see you’re using AutoCAD 2006, so VBA is still an option. I had this routine hanging around, see if it will work for you. It creates and positions a circle, then extrudes along all the selected paths. The 3dPolys would already have to be in place, however.

See this link on how to run a vba program:

http://www.cadtutor.net/forum/showthread.php?30608-FAQ-How-do-I-run-a-VBA-routine

 

Option Explicit
Private Sub MakeExtrusions()
Dim intCode(0) As Integer
Dim varData(0) As Variant
Dim objProfile As AcadCircle
Dim ent3PLine As Acad3DPolyline
Dim objProfReg As AcadRegion
Dim objRod As Acad3DSolid
Dim dblDia As Double
Dim deltaX As Double, deltaY As Double, deltaZ As Double
Dim dblStartPoint() As Double
Dim dblNextPoint() As Double
Dim varEndPoint As Variant
Dim varCen As Variant
Dim arrOrigin(2) As Double
Dim curves(0 To 0) As AcadEntity
Dim varRegion As Variant
Dim dblVector() As Double
  varCen = arrOrigin
  On Error GoTo Abort
  dblDia = ThisDrawing.Utility.GetReal("Input a rod Diameter, <enter>, then select polylines:")
  Set objProfile = ThisDrawing.ModelSpace.AddCircle(varCen, dblDia / 2)
  objProfile.Visible = False
  intCode(0) = 0: varData(0) = "POLYLINE"
  If SoSSS(intCode, varData) > 0 Then
     For Each ent3PLine In ThisDrawing.SelectionSets.Item("TempSSet")
           dblStartPoint = ent3PLine.Coordinate(0)

           dblNextPoint = ent3PLine.Coordinate(1)
           dblVector = NormalizeST(VectorFrom2PtsST(dblStartPoint, dblNextPoint))
           objProfile.Center = dblStartPoint
           objProfile.Normal = dblVector
           Set curves(0) = objProfile
           varRegion = ThisDrawing.ModelSpace.AddRegion(curves)
           Set objProfReg = varRegion(0)
           Set objRod = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(objProfReg, ent3PLine)
           objProfReg.Delete
     Next
  End If
  objProfile.Delete
Exit Sub
Abort:
End Sub
Function VectorFrom2PtsST(dbl1stPt() As Double, dbl2ndPt() As Double) As Double()
Dim dblDummy(0 To 2) As Double
  dblDummy(0) = dbl2ndPt(0) - dbl1stPt(0)
  dblDummy(1) = dbl2ndPt(1) - dbl1stPt(1)
  dblDummy(2) = dbl2ndPt(2) - dbl1stPt(2)
  VectorFrom2PtsST = dblDummy
End Function
Function NormalizeST(dblVect() As Double) As Double()
Dim dblMag As Double
  If Not IsVectorZero(dblVect, 6) Then
     dblMag = (dblVect(0) ^ 2 + dblVect(1) ^ 2 + dblVect(2) ^ 2) ^ 0.5
     dblVect(0) = dblVect(0) / dblMag
     dblVect(1) = dblVect(1) / dblMag
     dblVect(2) = dblVect(2) / dblMag
  End If
  NormalizeST = dblVect
End Function
Function IsVectorZero(dblVector() As Double, Optional lngPrecision As Long = 6) As Boolean
  IsVectorZero = False
  If Round(dblVector(2), lngPrecision) <> 0# Then Exit Function
  If Round(dblVector(1), lngPrecision) <> 0# Then Exit Function
  If Round(dblVector(0), lngPrecision) <> 0# Then Exit Function
  IsVectorZero = True
End Function
Sub SSClear()
Dim SSS As AcadSelectionSets
  On Error Resume Next
  Set SSS = ThisDrawing.SelectionSets
     If SSS.count > 0 Then
        SSS.Item("TempSSet").Delete
        SSS.Item("RemoveSSet").Delete
        SSS.Item("EntireSS").Delete
     End If
End Sub
Function SoSSS(Optional grpCode As Variant, Optional dataVal As Variant) As Integer
  Dim TempObjSS As AcadSelectionSet
  SSClear
  Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
        'pick selection set
  If IsMissing(grpCode) Then
     TempObjSS.SelectOnScreen
  Else
     TempObjSS.SelectOnScreen grpCode, dataVal
  End If
  SoSSS = TempObjSS.count
End Function

Link to comment
Share on other sites

I see you’re using AutoCAD 2006, so VBA is still an option. I had this routine hanging around, see if it will work for you. It creates and positions a circle, then extrudes along all the selected paths. The 3dPolys would already have to be in place, however.

See this link on how to run a vba program:

http://www.cadtutor.net/forum/showthread.php?30608-FAQ-How-do-I-run-a-VBA-routine

 

Option Explicit
Private Sub MakeExtrusions()
Dim intCode(0) As Integer
Dim varData(0) As Variant
Dim objProfile As AcadCircle
Dim ent3PLine As Acad3DPolyline
Dim objProfReg As AcadRegion
Dim objRod As Acad3DSolid
Dim dblDia As Double
Dim deltaX As Double, deltaY As Double, deltaZ As Double
Dim dblStartPoint() As Double
Dim dblNextPoint() As Double
Dim varEndPoint As Variant
Dim varCen As Variant
Dim arrOrigin(2) As Double
Dim curves(0 To 0) As AcadEntity
Dim varRegion As Variant
Dim dblVector() As Double
varCen = arrOrigin
On Error GoTo Abort
dblDia = ThisDrawing.Utility.GetReal("Input a rod Diameter, <enter>, then select polylines:")
Set objProfile = ThisDrawing.ModelSpace.AddCircle(varCen, dblDia / 2)
objProfile.Visible = False
intCode(0) = 0: varData(0) = "POLYLINE"
If SoSSS(intCode, varData) > 0 Then
For Each ent3PLine In ThisDrawing.SelectionSets.Item("TempSSet")
dblStartPoint = ent3PLine.Coordinate(0)

dblNextPoint = ent3PLine.Coordinate(1)
dblVector = NormalizeST(VectorFrom2PtsST(dblStartPoint, dblNextPoint))
objProfile.Center = dblStartPoint
objProfile.Normal = dblVector
Set curves(0) = objProfile
varRegion = ThisDrawing.ModelSpace.AddRegion(curves)
Set objProfReg = varRegion(0)
Set objRod = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(objProfReg, ent3PLine)
objProfReg.Delete
Next
End If
objProfile.Delete
Exit Sub
Abort:
End Sub
Function VectorFrom2PtsST(dbl1stPt() As Double, dbl2ndPt() As Double) As Double()
Dim dblDummy(0 To 2) As Double
dblDummy(0) = dbl2ndPt(0) - dbl1stPt(0)
dblDummy(1) = dbl2ndPt(1) - dbl1stPt(1)
dblDummy(2) = dbl2ndPt(2) - dbl1stPt(2)
VectorFrom2PtsST = dblDummy
End Function
Function NormalizeST(dblVect() As Double) As Double()
Dim dblMag As Double
If Not IsVectorZero(dblVect, 6) Then
dblMag = (dblVect(0) ^ 2 + dblVect(1) ^ 2 + dblVect(2) ^ 2) ^ 0.5
dblVect(0) = dblVect(0) / dblMag
dblVect(1) = dblVect(1) / dblMag
dblVect(2) = dblVect(2) / dblMag
End If
NormalizeST = dblVect
End Function
Function IsVectorZero(dblVector() As Double, Optional lngPrecision As Long = 6) As Boolean
IsVectorZero = False
If Round(dblVector(2), lngPrecision) <> 0# Then Exit Function
If Round(dblVector(1), lngPrecision) <> 0# Then Exit Function
If Round(dblVector(0), lngPrecision) <> 0# Then Exit Function
IsVectorZero = True
End Function
Sub SSClear()
Dim SSS As AcadSelectionSets
On Error Resume Next
Set SSS = ThisDrawing.SelectionSets
If SSS.count > 0 Then
SSS.Item("TempSSet").Delete
SSS.Item("RemoveSSet").Delete
SSS.Item("EntireSS").Delete
End If
End Sub
Function SoSSS(Optional grpCode As Variant, Optional dataVal As Variant) As Integer
Dim TempObjSS As AcadSelectionSet
SSClear
Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
'pick selection set
If IsMissing(grpCode) Then
TempObjSS.SelectOnScreen
Else
TempObjSS.SelectOnScreen grpCode, dataVal
End If
SoSSS = TempObjSS.count
End Function

Sweet! Thanks, Sean!! Yes, the 3D polylines are in place, so this has a chance of working. I will need some time to get up to speed on VBA since I normally use an external BASIC compiler (JBASIC) to manipulate data and text files. I will most definitely give it a try and report back.

 

BTW - Is it possible to use this routine starting with 3D splines instead of 3D polylines? If so, how would I go about modifying it?

 

======

 

EDIT: Just did a quick and dirty test and IT WORKS!!! It also treats the 3D spline and polyline as the same type, which is great.

 

Sean: you are awesome.

Edited by rob8lyn
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...