Message 1 of 25
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Sir,
Please see the attached error massage used autocad 2020 64bit & help me.
Option Explicit
Dim BNSize(1 To 100) As String
Dim BNQty(1 To 100) As Integer
Dim SS As AcadSelectionSet
'Count BN from layers BN1,BN2,BN4
Sub BNCount()
Dim BoltSize As String
Dim BoltQty As Integer
Dim LayerQty As Integer
Dim Boltstr As Variant 'as Variant because split function return array
SelectBN
If SS.Count = 0 Then
MsgBox "No Valid Bolt Nut Block selected"
Exit Sub
End If
Call FillArray(BNSize, "") 'LIB sub
Call FillArray(BNQty, 0) 'LIB sub
Dim BNBLOCK As Variant
Dim BNAtt As Variant
Dim Count As Integer
Dim Donut As AcadLWPolyline
Dim VarDIMSCALE
Dim Errfound As Boolean
VarDIMSCALE = ThisDrawing.GetVariable("DIMSCALE")
Errfound = False
If findlayer("TEMP") = False Then
ThisDrawing.Layers.Add "TEMP"
End If
For Each BNBLOCK In SS
LayerQty = Val(Right(BNBLOCK.Layer, 1))
If BNBLOCK.HasAttributes Then
BNAtt = BNBLOCK.GetAttributes
For Count = LBound(BNAtt) To UBound(BNAtt)
If InStr(BNAtt(Count).TextString, "-") > 0 Then ' if - found in att then
Boltstr = Split(BNAtt(Count).TextString, "-")
BoltQty = Val(Boltstr(0))
If BoltQty = 0 Then ' if qty = 0 or any non numeric string then
Set Donut = AddDonut(ThisDrawing.ModelSpace, VarDIMSCALE * 5#, VarDIMSCALE * 10#, BNBLOCK.InsertionPoint)
Donut.Color = acMagenta
Donut.Layer = "TEMP"
Errfound = True
Else
BoltSize = Boltstr(1)
AddTOBNSum BoltSize, BoltQty * LayerQty
End If
Else
Set Donut = AddDonut(ThisDrawing.ModelSpace, VarDIMSCALE * 5#, VarDIMSCALE * 10#, BNBLOCK.InsertionPoint)
Donut.Color = acMagenta
Donut.Layer = "TEMP"
Errfound = True
End If
Next Count
End If
Next BNBLOCK
If Errfound Then
MsgBox "Error found , Atrribute without - or Qty not valid number "
Else
Call WriteBNSum
End If
SS.Clear
Set SS = Nothing
End Sub
Private Sub SelectBN()
Dim FType
Dim FData
BuildFilter FType, FData, 2, "B1,B2,B3,B4,B5,B6,B7,B8,B9,B10", 8, "BN1,BN2,BN3,BN4"
On Error Resume Next
Set SS = ThisDrawing.SelectionSets("SS")
If Err Then Set SS = ThisDrawing.SelectionSets.Add("SS")
SS.Clear
SS.SelectOnScreen FType, FData
End Sub
Private Sub AddTOBNSum(BoltSize, BoltQty)
Dim I As Integer
For I = 1 To 100
If BNSize(I) = BoltSize Then
BNQty(I) = BNQty(I) + BoltQty
Exit Sub
End If
Next
For I = 1 To 100
If BNSize(I) = "" Then
BNSize(I) = BoltSize
BNQty(I) = BoltQty
Exit Sub
End If
Next
End Sub
Private Sub WriteBNSum()
Dim pnt As Variant
Dim ExtraPer As Double
Dim AddNo As Integer
Dim Textheight As Integer
Dim Vspacing As Integer
Dim Hspacing As Integer
Dim VarDIMSCALE
pnt = ThisDrawing.Utility.GetPoint(, vbCr & "Select Insertion point : ")
VarDIMSCALE = ThisDrawing.GetVariable("DIMSCALE")
ExtraPer = GetRel("Extra % of Bolt Nut", 0, 4) 'LIB Function (4 not allow -Ve)
AddNo = GetInt("Additional No of Bolt nut", 0, 4) 'LIB Function
Textheight = VarDIMSCALE * GetInt("Text Height", 3, 6) 'LIB Function
Vspacing = Textheight + VarDIMSCALE * GetInt("Vertical spacing", 3, 6) 'LIB Function (6 not allow 0 & -Ve)
Hspacing = VarDIMSCALE * GetInt("Horigontal spacing", 40, 6) 'LIB Function
If findlayer("TEXT") = False Then
MsgBox "Text layer not found , Creating text layer"
ThisDrawing.Layers.Add "TEXT"
End If
Call WriteStringArray(BNSize, pnt, Textheight, Vspacing, "TEXT") 'LIB SUB
'Inc BN qty based on extra % or add no
Dim BNper As Integer
Dim BNadd As Integer
Dim I As Integer
For I = 1 To 100
If BNQty(I) = 0 Then Exit For
BNper = Int(round((BNQty(I) * (100# + ExtraPer) / 100#), 0))
BNadd = BNQty(I) + AddNo
If BNper > BNadd Then
BNQty(I) = BNper
Else
BNQty(I) = BNadd
End If
Next
Dim X As Double
Dim Y As Double
Dim Z As Double
X = pnt(0) + Hspacing
Y = pnt(1)
Z = pnt(2)
pnt = point3d(X, Y, Z) 'LIB FUNCTION
Call WriteNumberArray(BNQty, pnt, Textheight, Vspacing, "TEXT") 'LIB SUB
End Sub
*Moderator edit* Please post code to a code window.
Solved! Go to Solution.