'##################################################################### 'IsClosed.tcm macro for TurboCAD v7 'Tom Snape 10/19/01 'This macro can be used to determine if a graphic is closed. 'This can be helpful when making 2D profiles intended for creation 'of 3D solids. Often a 2D profile may appear to be closed, but if it is 'not, the resulting solid may not be what the user expected. 'This macro will not work on all objects; arcs, for example. ' '######################################################################### Option Explicit Dim tcApp As Application Dim Dr As Drawing Dim Grs As Graphics Dim Gr As Graphic Sub IsClosed() Set tcApp = IMSIGX.Application Set Dr = tcApp.ActiveDrawing Set Grs = Dr.Graphics If Dr.Selection.Count = 0 Then MsgBox "Nothing selected. Please select a graphic before running macro.", vbInformation Call CleanUp Exit Sub End If If Dr.Selection.Count > 1 Then MsgBox "More than one object selected. Please try again.", vbExclamation Call CleanUp Exit Sub End If Set Gr = Dr.Selection(0) If Gr.Closed = True Then MsgBox "The selected graphic is closed." Call CleanUp Else Dim GrEnd0 As Graphic Dim GrEnd1 As Graphic Dim LastV As Integer LastV = Gr.Vertices.Count - 1 Set GrEnd0 = Grs.AddCircleCenterAndPoint(Gr.Vertices(0).X, Gr.Vertices(0).Y, _ Gr.Vertices(0).Z, Gr.Vertices(0).X + (0.03 * GrSize(Gr)), Gr.Vertices(0).Y, _ Gr.Vertices(0).Z) GrEnd0.Properties("PenColor") = vbRed GrEnd0.Transform Gr.UCS Set GrEnd1 = Grs.AddCircleCenterAndPoint(Gr.Vertices(LastV).X, Gr.Vertices(LastV).Y, _ Gr.Vertices(LastV).Z, Gr.Vertices(LastV).X + (0.03 * GrSize(Gr)), Gr.Vertices(LastV).Y, _ Gr.Vertices(LastV).Z) GrEnd1.Properties("PenColor") = vbBlue GrEnd1.Transform Gr.UCS Dim Ans Ans = MsgBox("The selected graphic is not closed. Do you want me to close it?", vbYesNo) If Ans = vbYes Then Gr.Close ' GrEnd0.Delete ' GrEnd1.Delete Set GrEnd0 = Nothing Set GrEnd1 = Nothing Gr.Unselect Dr.ActiveView.Refresh End If Call CleanUp End Sub Private Sub CleanUp() Set Gr = Nothing Set Grs = Nothing Set Dr = Nothing Set tcApp = Nothing End Sub 'Use bounding box to get an idea of size of graphic 'This is used to scale size of circles placed on end vertices Function GrSize(Gra As Graphic) As Double GrSize = 0 Dim GrBB As BoundingBox Dim Size(2) As Double Set GrBB = Gra.CalcBoundingBox Size(0) = Abs(GrBB.Max.X - GrBB.Min.X) Size(1) = Abs(GrBB.Max.Y - GrBB.Min.Y) Size(2) = Abs(GrBB.Max.Z - GrBB.Min.Z) Dim i As Integer For i = 0 To 2 If Size(i) > GrSize Then GrSize = Size(i) Next i Set GrBB = Nothing End Function