Howdy folks!
I'm trying to find pipe segment sizes (diameters) and length in AutoCAD Mecanical 2018 files. In all cases, the pipe segments will be Solid3D types, with hollow centers. I quickly sketched in some code to do this, and it seems to work, but I'm not very bright so it will only work if the pipe is oriented along the Z axis. Easy-peasy. I could get it to work in other orthagonal views with a bunch of If/Thens, but that won't work for all cases.
My problem is that I need it to work with the pipe segment in any orientation.
These pipes will be mixed in with many other non-pipe solids, so the object has to be identified as a pipe, then it's diameter must be determined.
Note that I cannot rely on the pipe ends being squared, so I don't think I can iterate through brep.faces looking for circular faces of a certain diameter or do things like that.
I've attached a dwg file that has 2 pipe segments in it. A simple one that is oriented along the Z axis, and a worst-case example, where I've rotated the pipe segment slightly in all 3 axiis, and then I've cut the ends.
Here is the initial code that I tested with (it works with a Z-aligned pipe segment):
Dim sf = New SelectionFilter(New TypedValue() {New TypedValue(CInt(DxfCode.Start), "3DSOLID")})
Dim selResult As PromptSelectionResult = acEd.SelectAll(sf)
Dim PipeODs As New Dictionary(Of String, Double) ' (OD, Nom)
PipeODs.Add(CDbl(0.84).ToString, 0.5)
PipeODs.Add(CDbl(1).ToString, 0.75)
PipeODs.Add(CDbl(1.3125).ToString, 1)
PipeODs.Add(CDbl(1.875).ToString, 1.5)
PipeODs.Add(CDbl(2.375).ToString, 2)
PipeODs.Add(CDbl(3.5).ToString, 3)
PipeODs.Add(CDbl(4.5).ToString, 4)
PipeODs.Add(CDbl(6.625).ToString, 6)
PipeODs.Add(CDbl(8.625).ToString, 8)
PipeODs.Add(CDbl(10.75).ToString, 10)
Using acDoc.LockDocument()
Using acTr As Transaction = acDoc.TransactionManager.StartTransaction
Dim acBlkTbl As BlockTable = acTr.GetObject(acDB.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec As BlockTableRecord = acTr.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
For Each Obj As SelectedObject In selResult.Value ' loop thru each 3dsolid
Dim eee As Entity = acTr.GetObject(Obj.ObjectId, OpenMode.ForRead)
Dim objWork As Solid3d = acTr.GetObject(Obj.ObjectId, OpenMode.ForWrite) '.Clone
If objWork.MassProperties.Volume = 0 Then
Continue For
End If
Dim brep As New BoundaryRepresentation.Brep(objWork)
Dim EXT As BoundBlock3d = brep.BoundBlock
If EXT.Direction1.Length = EXT.Direction2.Length Then
If PipeODs.ContainsKey(EXT.Direction1.Length.ToString) Then
Dim pipeod As Double = EXT.Direction1.Length
Dim pipelength As Double = EXT.Direction3.Length
'pa.Pipes.Add(New Pipe(pipeod, pipelength, Obj.ObjectId))
objWork.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.White)
End If
End If
Next
End Using
End Using
The "Dim EXT As BoundBlock3d = brep.BoundBlock" and the following If/Then are where (I assume) the magic needs to happen. I just do not understand rotation matrices and coordinate system matrices so it is beyond me.
I hope this is enough info. If anyone can help me out, it would really be appreciated.
Thanks!!