Reply
Solved! Go to solution

ElseIf and If programming question.

Here's a section of my program that inserts a callout with information on a draft created from a flat pattern. I had a problem when creating the callout for a circle,  cause the code searched for a line, so I made it detect the center of a circle. So I want it to use cirecle center when there's no line and a line edge when there is. But can't si to make it work. Each section works induvidually but not together, I know I'm not far from the answer.

 oDocD = oDocs.Add("SolidEdge.DraftDocument", TemplateDoc:="I:\SOLIDEDGE\template\Quicksheet\GAB.dft")
        oSheet = oDocD.ActiveSheet
        oMlink = oDocD.ModelLinks.Add(sParFile)
        oView = oSheet.DrawingViews.AddSheetMetalView(oMlink, SolidEdgeDraft.DrawingViewTypeConstants.igPrincipleView, 1, 0, 0, SolidEdgeDraft.SheetMetalDrawingViewTypeConstants.seSheetMetalFlatView)
        Try
            Dim objDoc As SolidEdgeDraft.DraftDocument = oApp.ActiveDocument
            Dim objSheet As SolidEdgeDraft.Sheet = objDoc.ActiveSheet
            Dim objView As SolidEdgeDraft.DrawingView = objSheet.DrawingViews.Item(1)
            Dim objdvline As SolidEdgeDraft.DVLine2d = objView.DVLines2d.Item(1)
            Dim objdvarc As SolidEdgeDraft.DVCircle2d = objView.DVCircles2d.Item(1)
            Dim objBalloons As SolidEdgeFrameworkSupport.Balloons = objSheet.Balloons
            Dim objBall As SolidEdgeFrameworkSupport.Balloon = Nothing
            Dim x, y, z As Double
            Dim objTerminator As Object = Nothing
            Dim keyPoint As Boolean
            Dim kpt As SolidEdgeFramework.KeyPointType
            Dim hnd As Integer
            oApp.ScreenUpdating = False
            
'GET THE CENTER OF A CIRCLE
            If objdvarc.Diameter > 0 Then
                ' Get the coordinates of the  CIRCLE CENTER POINT)
                objdvarc.GetCenterPoint(x, y)
                objView.ViewToSheet(x, y, x, y)
                ' Create the callout
                objBall = objBalloons.AddByTerminator(objdvarc.Reference, x, y, z, True)
                objBall.GetTerminator(objTerminator, x, y, z, keyPoint)
                objBall.AddVertex(x + 0.08, y + 0.2, z)
                objBall.TextScale = 6.0
                objBall.BalloonText = "GABARIT: %{File Name (no extension)|GP}" & vbCrLf & vbCrLf & "PLAQUE: %{Gage|GP}" & vbCrLf & vbCrLf & "MATERIEL: %{Material|GP}" & vbCrLf & vbCrLf &
                  "DIMENSIONS: %{Flat_Pattern_Model_CutSizeY/CP|G} X %{Flat_Pattern_Model_CutSizeX/CP|G}" & vbCrLf & vbCrLf & "PAR: %{Author}" & vbCrLf & vbCrLf &
                    "FICHIER .PSM REF: %{File Name (full path)|GP}"
                objBall.Leader = False
                objBall.BreakLine = False
'IF NO CIRCLE ,GET LINE
            ElseIf objdvline.EdgeType > 0 Then
                ' Get the coordinates of the  edge line's midpoint (0=start, 1=end, 2=middle)
                objdvline.GetKeyPoint(2, x, y, z, kpt, hnd)
                objView.ViewToSheet(x, y, x, y)
                'Create the callout
                objBall = objBalloons.AddByTerminator(objdvline.Reference, x, y, z, True)
                objBall.GetTerminator(objTerminator, x, y, z, keyPoint)
                objBall.AddVertex(x + 0.08, y + 0.2, z)
                objBall.TextScale = 6.0
                objBall.BalloonText = "GABARIT: %{File Name (no extension)|GP}" & vbCrLf & vbCrLf & "PLAQUE: %{Gage|GP}" & vbCrLf & vbCrLf & "MATERIEL: %{Material|GP}" & vbCrLf & vbCrLf &
                  "DIMENSIONS: %{Flat_Pattern_Model_CutSizeY/CP|G} X %{Flat_Pattern_Model_CutSizeX/CP|G}" & vbCrLf & vbCrLf & "PAR: %{Author}" & vbCrLf & vbCrLf &
                    "FICHIER .PSM REF: %{File Name (full path)|GP}"
                objBall.Leader = False
                objBall.BreakLine = False
            End If
            oApp.ScreenUpdating = True
            Dim objWin As SheetWindow = oApp.ActiveWindow
            objWin.Update()
        Catch ex As Exception
        End Try
        oDocD.SaveAs("H:\GABARIT DXF A TRANSFERER\" & (IO.Path.GetFileNameWithoutExtension(oDocP.FullName)) & ".DXF")
        oDocP.Save()
        oDocP.Close()
        'oDocP.Close(False)
    End Sub

I will post corrected formula if I find it..

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.
2 REPLIES
Solution
Solution
Accepted by topic author Pedneault75
‎05-18-2017 02:09 PM

Re: ElseIf and If programming question.

According to the code, you want the IF case when there is a circle and ELSE IF case when there is no circle.

 

I'd add this to my IF:

If (objdvarc IsNot Nothing) AndAlso objdvarc.Diameter > 0 Then

That way you don't throw an exception if there is no circle. I'm not sure if that's causing your issue, but that's the first thing I noticed.

 

(AndAlso instead of And to short-circuit the evaluation.)

Siemens PLM Software, Inc.
Project Test Engineer (Automation)

Re: ElseIf and If programming question.

Works!!! Very grateful!
ST9
Conveyor and industrial equipment designer.
Giving SE a chance.