If LeaderOptYes.Value = True Then TextLength = GetTextLength(insBlock) If SequenceOption.Value = False Then below = below & "-" & SeqNum.Value End Ifįor I = LBound(attRef) To UBound(attRef) If attRef(I).TagString = "LINESIZE/MATERIAL" Then attRef(I).TextString = ListBox1.Object & "-" & ListBox2.Object ElseIf attRef(I).TagString = "PIPE-IDENTIFICATION-NO" Then attRef(I).TextString = below End If Next I 'since the constant acModelSpace is 1 you could shorten this to ' If ThisDrawing.ActiveSpace Then If ThisDrawing.ActiveSpace = acModelSpace Then Set insBlock = (insPnt, "Mech-38", 1, 1, 1, rotAng)Įlse Set insBlock = (insPnt, "Mech-38", 1, 1, 1, rotAng) End IfĪttRef = insBlock.GetAttributes 'it's unclear what this is doing for you below = ListBox3.Object 'I'm assuming you're parsing a string here below = Left(below, ((InStr(1, below, "-")) - 2)) If rotAng > (pi / 2) + 0.001 And rotAng < (pi * 1.5) + 0.001 Then rotAng = rotAng + pi End If 'it's clearer to write this as Atn(1) * 4 pi = 4 * (Atn(1)) rotAng = (startPnt, endPnt) lineLen = Distance(startPnt, endPnt) 'this makes no sense, why set insPnt to a value and then change each element insPnt = endPnt insPnt(0) = (startPnt(0) + endPnt(0)) / 2# insPnt(1) = (startPnt(1) + endPnt(1)) / 2# insPnt(2) = (startPnt(2) + endPnt(2)) / 2#
Private Sub Label_It(startPnt As Variant, endPnt As Variant) Dim insBlock As AcadBlockReference Dim attRef As Variant Dim rotAng As Double Dim insPnt As Variant Dim lineLen As Double Dim util As AcadUtility Dim pi As Double Dim I As Integer Dim below As String Dim TextLength As Double 'first, there are too many operations going on inside this routine 'break out some of the functional parts into separate routines
So, I've made some suggestions in the comments of your code below. I agree with Jason, comments are essential. If ThisDrawing.ActiveSpace = acModelSpace Then InsPoint = (EndPoint, rotAng, (TextLength NextPoint = (EndPoint, rotAng, TextLength) If (NextPoint, EndPoint) > (pi / 2) +Īnd (NextPoint, EndPoint) < (pi * NextPoint = oGetXX.GetPoint(x圎rr, StartPoint, " Next Leader Point:ĮndPoint = oGetXX.GetPoint(x圎rr, NextPoint, " Leader end point: ") If rotAng > (pi / 2) + 0.001 And rotAng lineLen Thenĭo Until x圎rr = GETXX_SUCCESS Or x圎rr = GETXX_ESCAPE Private Sub Label_It(startPnt As Variant, endPnt As Variant) I'm not so sure it uses the best coding practices and I'm looking for inputĪs to how I could improve what I've done, if anyone is willing to give me I have a VBA file that I created, one of my first, that works great.